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

Implement option to retrieve the manager associated with a command and the number of commands managed by a manager.

This commit is contained in:
Sandu Liviu Catalin 2016-07-03 03:44:44 +03:00
parent dde8890941
commit 1963c8e636
2 changed files with 28 additions and 0 deletions

View File

@ -1024,6 +1024,7 @@ void Register(HSQUIRRELVM vm)
.SquirrelFunc(_SC("_typename"), &Manager::Typename)
.Func(_SC("_tostring"), &Manager::ToString)
// Member Properties
.Prop(_SC("Count"), &Manager::GetCount)
.Prop(_SC("IsContext"), &Manager::IsContext)
.Prop(_SC("OnFail"), &Manager::GetOnFail)
.Prop(_SC("OnFail"), &Manager::GetOnFail)
@ -1067,6 +1068,7 @@ void Register(HSQUIRRELVM vm)
.Func(_SC("_tostring"), &Listener::ToString)
// Member Properties
.Prop(_SC("Attached"), &Listener::Attached)
.Prop(_SC("Manager"), &Listener::GetManager)
.Prop(_SC("Name"), &Listener::GetName, &Listener::SetName)
.Prop(_SC("Spec"), &Listener::GetSpec, &Listener::SetSpec)
.Prop(_SC("Specifier"), &Listener::GetSpec, &Listener::SetSpec)

View File

@ -805,6 +805,14 @@ public:
return GetValid()->FindByName(name);
}
/* --------------------------------------------------------------------------------------------
* Retrieve the number of managed command listeners.
*/
SQInteger GetCount() const
{
return ConvTo< SQInteger >::From(GetValid()->m_Commands.size());
}
/* --------------------------------------------------------------------------------------------
* See whether an execution context is currently active.
*/
@ -1172,6 +1180,24 @@ public:
return (!m_Controller.Expired() && m_Controller.Lock()->Attached(this));
}
/* --------------------------------------------------------------------------------------------
* Retrieve the manager associated with this command listener instance.
*/
Object GetManager() const
{
// Are we even associated with a controller?
if (!m_Controller)
{
return NullObject(); // Default to null
}
// Obtain the initial stack size
const StackGuard sg;
// Push the instance on the stack
ClassType< Manager >::PushInstance(DefaultVM::Get(), m_Controller.Lock()->m_Manager);
// Grab the instance from the stack
return Var< Object >(DefaultVM::Get(), -1).value;
}
/* --------------------------------------------------------------------------------------------
* Retrieve the name that triggers this command listener instance.
*/