diff --git a/source/Routine.cpp b/source/Routine.cpp index 3590ed79..f7de0d2a 100644 --- a/source/Routine.cpp +++ b/source/Routine.cpp @@ -231,6 +231,25 @@ SQInteger Routine::Create(HSQUIRRELVM vm) 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. */ @@ -282,6 +301,7 @@ void Register_Routine(HSQUIRRELVM vm) // Global functions RootTable(vm).SquirrelFunc(_SC("SqRoutine"), &Routine::Create); RootTable(vm).FmtFunc(_SC("SqFindRoutineByTag"), &Routine::FindByTag); + RootTable(vm).FmtFunc(_SC("SqIsRoutineWithTag"), &Routine::IsWithTag); } } // Namespace:: SqMod diff --git a/source/Routine.hpp b/source/Routine.hpp index 4a1036f8..75a78502 100644 --- a/source/Routine.hpp +++ b/source/Routine.hpp @@ -287,9 +287,10 @@ public: */ static const LightObj & FindByTag(const StackStrF & tag) { + // Is the specified tag valid? if (!tag.mPtr) { - STHROWF("Invalid entity tag"); + STHROWF("Invalid routine tag"); } // Iterate routine list 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 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. */