1
0
mirror of https://github.com/VCMP-SqMod/SqMod.git synced 2025-01-19 03:57:14 +01:00

Add a function to check if a routine with a certain tag exists.

This commit is contained in:
Sandu Liviu Catalin 2018-07-29 10:47:31 +03:00
parent a5999e5b50
commit 526538fdb9
2 changed files with 26 additions and 2 deletions

View File

@ -231,6 +231,25 @@ SQInteger Routine::Create(HSQUIRRELVM vm)
return 1; return 1;
} }
// ------------------------------------------------------------------------------------------------
bool Routine::IsWithTag(const StackStrF & tag)
{
// Is the specified tag valid?
if (tag.mPtr != nullptr)
{
// Iterate routine list
for (const auto & r : s_Instances)
{
if (!r.mInst.IsNull() && r.mTag.compare(tag.mPtr) == 0)
{
return true; // Yup, we're doing this
}
}
}
// Unable to find such routine
return false;
}
/* ------------------------------------------------------------------------------------------------ /* ------------------------------------------------------------------------------------------------
* Forward the call to process routines. * Forward the call to process routines.
*/ */
@ -282,6 +301,7 @@ void Register_Routine(HSQUIRRELVM vm)
// Global functions // Global functions
RootTable(vm).SquirrelFunc(_SC("SqRoutine"), &Routine::Create); RootTable(vm).SquirrelFunc(_SC("SqRoutine"), &Routine::Create);
RootTable(vm).FmtFunc(_SC("SqFindRoutineByTag"), &Routine::FindByTag); RootTable(vm).FmtFunc(_SC("SqFindRoutineByTag"), &Routine::FindByTag);
RootTable(vm).FmtFunc(_SC("SqIsRoutineWithTag"), &Routine::IsWithTag);
} }
} // Namespace:: SqMod } // Namespace:: SqMod

View File

@ -287,9 +287,10 @@ public:
*/ */
static const LightObj & FindByTag(const StackStrF & tag) static const LightObj & FindByTag(const StackStrF & tag)
{ {
// Is the specified tag valid?
if (!tag.mPtr) if (!tag.mPtr)
{ {
STHROWF("Invalid entity tag"); STHROWF("Invalid routine tag");
} }
// Iterate routine list // Iterate routine list
for (const auto & r : s_Instances) for (const auto & r : s_Instances)
@ -304,7 +305,10 @@ public:
// Should not reach this point but if it did, we have to return something // Should not reach this point but if it did, we have to return something
return s_Instances[SQMOD_MAX_ROUTINES].mInst; // Intentional Buffer overflow! return s_Instances[SQMOD_MAX_ROUTINES].mInst; // Intentional Buffer overflow!
} }
/* --------------------------------------------------------------------------------------------
* Check if a routine with a certain tag exists.
*/
static bool IsWithTag(const StackStrF & tag);
/* -------------------------------------------------------------------------------------------- /* --------------------------------------------------------------------------------------------
* Process all active routines and update elapsed time. * Process all active routines and update elapsed time.
*/ */