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

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

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

View File

@ -286,55 +286,80 @@ Function LocalEvent::GetOnTrigger() const noexcept
return m_OnTrigger;
}
void LocalEvent::SetOnTrigger(const Function & func) noexcept
void LocalEvent::SetOnTrigger(Function & func) noexcept
{
m_OnTrigger = func;
}
void LocalEvent::SetOnTrigger_Env(SqObj & env, Function & func) noexcept
{
m_OnTrigger = Function(env.GetVM(), env, func.GetFunc());
}
// ------------------------------------------------------------------------------------------------
Function LocalEvent::GetOnInclude() const noexcept
{
return m_OnInclude;
}
void LocalEvent::SetOnInclude(const Function & func) noexcept
void LocalEvent::SetOnInclude(Function & func) noexcept
{
m_OnInclude = func;
}
void LocalEvent::SetOnInclude_Env(SqObj & env, Function & func) noexcept
{
m_OnInclude = Function(env.GetVM(), env, func.GetFunc());
}
// ------------------------------------------------------------------------------------------------
Function LocalEvent::GetOnExclude() const noexcept
{
return m_OnExclude;
}
void LocalEvent::SetOnExclude(const Function & func) noexcept
void LocalEvent::SetOnExclude(Function & func) noexcept
{
m_OnExclude = func;
}
void LocalEvent::SetOnExclude_Env(SqObj & env, Function & func) noexcept
{
m_OnExclude = Function(env.GetVM(), env, func.GetFunc());
}
// ------------------------------------------------------------------------------------------------
Function LocalEvent::GetOnCleared() const noexcept
{
return m_OnCleared;
}
void LocalEvent::SetOnCleared(const Function & func) noexcept
void LocalEvent::SetOnCleared(Function & func) noexcept
{
m_OnCleared = func;
}
void LocalEvent::SetOnCleared_Env(SqObj & env, Function & func) noexcept
{
m_OnCleared = Function(env.GetVM(), env, func.GetFunc());
}
// ------------------------------------------------------------------------------------------------
Function LocalEvent::GetOnRelease() const noexcept
{
return m_OnRelease;
}
void LocalEvent::SetOnRelease(const Function & func) noexcept
void LocalEvent::SetOnRelease(Function & func) noexcept
{
m_OnRelease = func;
}
void LocalEvent::SetOnRelease_Env(SqObj & env, Function & func) noexcept
{
m_OnRelease = Function(env.GetVM(), env, func.GetFunc());
}
// ------------------------------------------------------------------------------------------------
bool LocalEvent::Compatible(SQInt32 type) const noexcept
{
@ -2230,19 +2255,20 @@ template < class T > static bool Register_LocalFilter(HSQUIRRELVM vm, const SQCh
typedef NoConstructor< Filter > Allocator;
// Attempt to register the specified filter type
Sqrat::RootTable(vm).Bind(cname, Sqrat::Class< Filter, Allocator >(vm, cname)
/* Metamethods */
.Func(_SC("_cmp"), &Filter::Cmp)
.Func(_SC("_tostring"), &Filter::ToString)
/* Properties */
.Prop(_SC("count"), &Filter::Count)
.Prop(_SC("any"), &Filter::Any)
.Prop(_SC("none"), &Filter::None)
.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 &, 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 &, SQInt32) >(_SC("exclude"), &Filter::Exclude)
/* Functions */
.Func(_SC("enabled"), &Filter::Enabled)
.Func(_SC("clear"), &Filter::Clear)
.Func(_SC("flip"), &Filter::Flip)
@ -2276,13 +2302,14 @@ bool Register_LocalEvent(HSQUIRRELVM vm)
typedef NoCopy< LocalEvent > Allocator;
// Attempt to register the specified type
Sqrat::RootTable(vm).Bind(_SC("LocalEvent"), Sqrat::Class< LocalEvent, Allocator >(vm, _SC("LocalEvent"))
/* Constructors */
.Ctor()
.Ctor<SQInt32>()
.Ctor<SQInt32, bool>()
/* Metamethods */
.Func(_SC("_cmp"), &LocalEvent::Cmp)
.Func(_SC("_tostring"), &LocalEvent::GetName)
/* Properties */
.Prop(_SC("ltag"), &LocalEvent::GetTag, &LocalEvent::SetTag)
.Prop(_SC("ldata"), &LocalEvent::GetData, &LocalEvent::SetData)
.Prop(_SC("type"), &LocalEvent::GetType, &LocalEvent::SetType)
@ -2296,13 +2323,11 @@ bool Register_LocalEvent(HSQUIRRELVM vm)
.Prop(_SC("suspended"), &LocalEvent::GetSuspended, &LocalEvent::SetSuspended)
.Prop(_SC("compatible"), &LocalEvent::Compatible)
.Prop(_SC("name"), &LocalEvent::GetName)
.Prop(_SC("on_trigger"), &LocalEvent::GetOnTrigger, &LocalEvent::SetOnTrigger)
.Prop(_SC("on_include"), &LocalEvent::GetOnInclude, &LocalEvent::SetOnInclude)
.Prop(_SC("on_exclude"), &LocalEvent::GetOnExclude, &LocalEvent::SetOnExclude)
.Prop(_SC("on_cleared"), &LocalEvent::GetOnCleared, &LocalEvent::SetOnCleared)
.Prop(_SC("on_release"), &LocalEvent::GetOnRelease, &LocalEvent::SetOnRelease)
.Prop(_SC("blips"), &LocalEvent::GetBlipFilter)
.Prop(_SC("checkpoints"), &LocalEvent::GetCheckpointFilter)
.Prop(_SC("keybinds"), &LocalEvent::GetKeybindFilter)
@ -2313,6 +2338,12 @@ bool Register_LocalEvent(HSQUIRRELVM vm)
.Prop(_SC("sprites"), &LocalEvent::GetSpriteFilter)
.Prop(_SC("textdraws"), &LocalEvent::GetTextdrawFilter)
.Prop(_SC("vehicles"), &LocalEvent::GetVehicleFilter)
/* Functions */
.Func(_SC("set_on_trigger"), &LocalEvent::SetOnTrigger_Env)
.Func(_SC("set_on_include"), &LocalEvent::SetOnInclude_Env)
.Func(_SC("set_on_exclude"), &LocalEvent::SetOnExclude_Env)
.Func(_SC("set_on_cleared"), &LocalEvent::SetOnCleared_Env)
.Func(_SC("set_on_release"), &LocalEvent::SetOnRelease_Env)
);
// Output debugging information
LogDbg("Registration of <LocalEvent> 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;
/* --------------------------------------------------------------------------------------------
* ...