1
0
mirror of https://github.com/VCMP-SqMod/SqMod.git synced 2024-11-08 00:37:15 +01:00

Extended callback binding on global event type to allow custom environments.

This commit is contained in:
Sandu Liviu Catalin 2015-11-01 02:14:55 +02:00
parent 0796185225
commit 21b9e71d83
2 changed files with 73 additions and 17 deletions

View File

@ -275,55 +275,80 @@ Function GlobalEvent::GetOnTrigger() const noexcept
return m_OnTrigger; return m_OnTrigger;
} }
void GlobalEvent::SetOnTrigger(const Function & func) noexcept void GlobalEvent::SetOnTrigger(Function & func) noexcept
{ {
m_OnTrigger = func; m_OnTrigger = func;
} }
void GlobalEvent::SetOnTrigger_Env(SqObj & env, Function & func) noexcept
{
m_OnTrigger = Function(env.GetVM(), env, func.GetFunc());
}
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
Function GlobalEvent::GetOnInclude() const noexcept Function GlobalEvent::GetOnInclude() const noexcept
{ {
return m_OnInclude; return m_OnInclude;
} }
void GlobalEvent::SetOnInclude(const Function & func) noexcept void GlobalEvent::SetOnInclude(Function & func) noexcept
{ {
m_OnInclude = func; m_OnInclude = func;
} }
void GlobalEvent::SetOnInclude_Env(SqObj & env, Function & func) noexcept
{
m_OnInclude = Function(env.GetVM(), env, func.GetFunc());
}
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
Function GlobalEvent::GetOnExclude() const noexcept Function GlobalEvent::GetOnExclude() const noexcept
{ {
return m_OnExclude; return m_OnExclude;
} }
void GlobalEvent::SetOnExclude(const Function & func) noexcept void GlobalEvent::SetOnExclude(Function & func) noexcept
{ {
m_OnExclude = func; m_OnExclude = func;
} }
void GlobalEvent::SetOnExclude_Env(SqObj & env, Function & func) noexcept
{
m_OnExclude = Function(env.GetVM(), env, func.GetFunc());
}
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
Function GlobalEvent::GetOnCleared() const noexcept Function GlobalEvent::GetOnCleared() const noexcept
{ {
return m_OnCleared; return m_OnCleared;
} }
void GlobalEvent::SetOnCleared(const Function & func) noexcept void GlobalEvent::SetOnCleared(Function & func) noexcept
{ {
m_OnCleared = func; m_OnCleared = func;
} }
void GlobalEvent::SetOnCleared_Env(SqObj & env, Function & func) noexcept
{
m_OnCleared = Function(env.GetVM(), env, func.GetFunc());
}
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
Function GlobalEvent::GetOnRelease() const noexcept Function GlobalEvent::GetOnRelease() const noexcept
{ {
return m_OnRelease; return m_OnRelease;
} }
void GlobalEvent::SetOnRelease(const Function & func) noexcept void GlobalEvent::SetOnRelease(Function & func) noexcept
{ {
m_OnRelease = func; m_OnRelease = func;
} }
void GlobalEvent::SetOnRelease_Env(SqObj & env, Function & func) noexcept
{
m_OnRelease = Function(env.GetVM(), env, func.GetFunc());
}
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
bool GlobalEvent::Compatible(SQInt32 type) const noexcept bool GlobalEvent::Compatible(SQInt32 type) const noexcept
{ {
@ -2087,19 +2112,20 @@ template < class T > static bool Register_GlobalFilter(HSQUIRRELVM vm, const SQC
typedef NoConstructor< Filter > Allocator; typedef NoConstructor< Filter > Allocator;
// Attempt to register the specified filtertype // Attempt to register the specified filtertype
Sqrat::RootTable(vm).Bind(cname, Sqrat::Class< Filter, Allocator >(vm, cname) Sqrat::RootTable(vm).Bind(cname, Sqrat::Class< Filter, Allocator >(vm, cname)
/* Metamethods */
.Func(_SC("_cmp"), &Filter::Cmp) .Func(_SC("_cmp"), &Filter::Cmp)
.Func(_SC("_tostring"), &Filter::ToString) .Func(_SC("_tostring"), &Filter::ToString)
/* Properties */
.Prop(_SC("count"), &Filter::Count) .Prop(_SC("count"), &Filter::Count)
.Prop(_SC("any"), &Filter::Any) .Prop(_SC("any"), &Filter::Any)
.Prop(_SC("none"), &Filter::None) .Prop(_SC("none"), &Filter::None)
.Prop(_SC("all"), &Filter::All) .Prop(_SC("all"), &Filter::All)
/* Overloads */
.template Overload< bool (Filter::*)(const typename Filter::RefType &) >(_SC("include"), &Filter::Include) .template Overload< bool (Filter::*)(const typename Filter::RefType &) >(_SC("include"), &Filter::Include)
.template Overload< bool (Filter::*)(const typename Filter::RefType &, SQInt32) >(_SC("include"), &Filter::Include) .template Overload< bool (Filter::*)(const typename Filter::RefType &, SQInt32) >(_SC("include"), &Filter::Include)
.template Overload< bool (Filter::*)(const typename Filter::RefType &) >(_SC("exclude"), &Filter::Exclude) .template Overload< bool (Filter::*)(const typename Filter::RefType &) >(_SC("exclude"), &Filter::Exclude)
.template Overload< bool (Filter::*)(const typename Filter::RefType &, SQInt32) >(_SC("exclude"), &Filter::Exclude) .template Overload< bool (Filter::*)(const typename Filter::RefType &, SQInt32) >(_SC("exclude"), &Filter::Exclude)
//.Func(_SC("exclude"), &Filter::Exclude) /* Functions */
.Func(_SC("enabled"), &Filter::Enabled) .Func(_SC("enabled"), &Filter::Enabled)
.Func(_SC("clear"), &Filter::Clear) .Func(_SC("clear"), &Filter::Clear)
.Func(_SC("flip"), &Filter::Flip) .Func(_SC("flip"), &Filter::Flip)
@ -2133,13 +2159,14 @@ bool Register_GlobalEvent(HSQUIRRELVM vm)
typedef NoCopy< GlobalEvent > Allocator; typedef NoCopy< GlobalEvent > Allocator;
// Attempt to register the specified type // Attempt to register the specified type
Sqrat::RootTable(vm).Bind(_SC("GlobalEvent"), Sqrat::Class< GlobalEvent, Allocator >(vm, _SC("GlobalEvent")) Sqrat::RootTable(vm).Bind(_SC("GlobalEvent"), Sqrat::Class< GlobalEvent, Allocator >(vm, _SC("GlobalEvent"))
/* Constructors */
.Ctor() .Ctor()
.Ctor<SQInt32>() .Ctor<SQInt32>()
.Ctor<SQInt32, bool>() .Ctor<SQInt32, bool>()
/* Metamethods */
.Func(_SC("_cmp"), &GlobalEvent::Cmp) .Func(_SC("_cmp"), &GlobalEvent::Cmp)
.Func(_SC("_tostring"), &GlobalEvent::GetName) .Func(_SC("_tostring"), &GlobalEvent::GetName)
/* Properties */
.Prop(_SC("ltag"), &GlobalEvent::GetTag, &GlobalEvent::SetTag) .Prop(_SC("ltag"), &GlobalEvent::GetTag, &GlobalEvent::SetTag)
.Prop(_SC("ldata"), &GlobalEvent::GetData, &GlobalEvent::SetData) .Prop(_SC("ldata"), &GlobalEvent::GetData, &GlobalEvent::SetData)
.Prop(_SC("type"), &GlobalEvent::GetType, &GlobalEvent::SetType) .Prop(_SC("type"), &GlobalEvent::GetType, &GlobalEvent::SetType)
@ -2153,13 +2180,11 @@ bool Register_GlobalEvent(HSQUIRRELVM vm)
.Prop(_SC("suspended"), &GlobalEvent::GetSuspended, &GlobalEvent::SetSuspended) .Prop(_SC("suspended"), &GlobalEvent::GetSuspended, &GlobalEvent::SetSuspended)
.Prop(_SC("compatible"), &GlobalEvent::Compatible) .Prop(_SC("compatible"), &GlobalEvent::Compatible)
.Prop(_SC("name"), &GlobalEvent::GetName) .Prop(_SC("name"), &GlobalEvent::GetName)
.Prop(_SC("on_trigger"), &GlobalEvent::GetOnTrigger, &GlobalEvent::SetOnTrigger) .Prop(_SC("on_trigger"), &GlobalEvent::GetOnTrigger, &GlobalEvent::SetOnTrigger)
.Prop(_SC("on_include"), &GlobalEvent::GetOnInclude, &GlobalEvent::SetOnInclude) .Prop(_SC("on_include"), &GlobalEvent::GetOnInclude, &GlobalEvent::SetOnInclude)
.Prop(_SC("on_exclude"), &GlobalEvent::GetOnExclude, &GlobalEvent::SetOnExclude) .Prop(_SC("on_exclude"), &GlobalEvent::GetOnExclude, &GlobalEvent::SetOnExclude)
.Prop(_SC("on_cleared"), &GlobalEvent::GetOnCleared, &GlobalEvent::SetOnCleared) .Prop(_SC("on_cleared"), &GlobalEvent::GetOnCleared, &GlobalEvent::SetOnCleared)
.Prop(_SC("on_release"), &GlobalEvent::GetOnRelease, &GlobalEvent::SetOnRelease) .Prop(_SC("on_release"), &GlobalEvent::GetOnRelease, &GlobalEvent::SetOnRelease)
.Prop(_SC("blips"), &GlobalEvent::GetBlipFilter) .Prop(_SC("blips"), &GlobalEvent::GetBlipFilter)
.Prop(_SC("checkpoints"), &GlobalEvent::GetCheckpointFilter) .Prop(_SC("checkpoints"), &GlobalEvent::GetCheckpointFilter)
.Prop(_SC("keybinds"), &GlobalEvent::GetKeybindFilter) .Prop(_SC("keybinds"), &GlobalEvent::GetKeybindFilter)
@ -2170,6 +2195,12 @@ bool Register_GlobalEvent(HSQUIRRELVM vm)
.Prop(_SC("sprites"), &GlobalEvent::GetSpriteFilter) .Prop(_SC("sprites"), &GlobalEvent::GetSpriteFilter)
.Prop(_SC("textdraws"), &GlobalEvent::GetTextdrawFilter) .Prop(_SC("textdraws"), &GlobalEvent::GetTextdrawFilter)
.Prop(_SC("vehicles"), &GlobalEvent::GetVehicleFilter) .Prop(_SC("vehicles"), &GlobalEvent::GetVehicleFilter)
/* Functions */
.Func(_SC("set_on_trigger"), &GlobalEvent::SetOnTrigger_Env)
.Func(_SC("set_on_include"), &GlobalEvent::SetOnInclude_Env)
.Func(_SC("set_on_exclude"), &GlobalEvent::SetOnExclude_Env)
.Func(_SC("set_on_cleared"), &GlobalEvent::SetOnCleared_Env)
.Func(_SC("set_on_release"), &GlobalEvent::SetOnRelease_Env)
); );
// Output debugging information // Output debugging information
LogDbg("Registration of <GlobalEvent> type was successful"); LogDbg("Registration of <GlobalEvent> type was successful");

View File

@ -493,7 +493,12 @@ public:
/* -------------------------------------------------------------------------------------------- /* --------------------------------------------------------------------------------------------
* ... * ...
*/ */
void SetOnTrigger(const Function & func) noexcept; void SetOnTrigger(Function & func) noexcept;
/* --------------------------------------------------------------------------------------------
* ...
*/
void SetOnTrigger_Env(SqObj & env, Function & func) noexcept;
/* -------------------------------------------------------------------------------------------- /* --------------------------------------------------------------------------------------------
* ... * ...
@ -503,7 +508,12 @@ public:
/* -------------------------------------------------------------------------------------------- /* --------------------------------------------------------------------------------------------
* ... * ...
*/ */
void SetOnInclude(const Function & func) noexcept; void SetOnInclude(Function & func) noexcept;
/* --------------------------------------------------------------------------------------------
* ...
*/
void SetOnInclude_Env(SqObj & env, Function & func) noexcept;
/* -------------------------------------------------------------------------------------------- /* --------------------------------------------------------------------------------------------
* ... * ...
@ -513,7 +523,12 @@ public:
/* -------------------------------------------------------------------------------------------- /* --------------------------------------------------------------------------------------------
* ... * ...
*/ */
void SetOnExclude(const Function & func) noexcept; void SetOnExclude(Function & func) noexcept;
/* --------------------------------------------------------------------------------------------
* ...
*/
void SetOnExclude_Env(SqObj & env, Function & func) noexcept;
/* -------------------------------------------------------------------------------------------- /* --------------------------------------------------------------------------------------------
* ... * ...
@ -523,7 +538,12 @@ public:
/* -------------------------------------------------------------------------------------------- /* --------------------------------------------------------------------------------------------
* ... * ...
*/ */
void SetOnCleared(const Function & func) noexcept; void SetOnCleared(Function & func) noexcept;
/* --------------------------------------------------------------------------------------------
* ...
*/
void SetOnCleared_Env(SqObj & env, Function & func) noexcept;
/* -------------------------------------------------------------------------------------------- /* --------------------------------------------------------------------------------------------
* ... * ...
@ -533,7 +553,12 @@ public:
/* -------------------------------------------------------------------------------------------- /* --------------------------------------------------------------------------------------------
* ... * ...
*/ */
void SetOnRelease(const Function & func) noexcept; void SetOnRelease(Function & func) noexcept;
/* --------------------------------------------------------------------------------------------
* ...
*/
void SetOnRelease_Env(SqObj & env, Function & func) noexcept;
/* -------------------------------------------------------------------------------------------- /* --------------------------------------------------------------------------------------------
* ... * ...