mirror of
https://github.com/VCMP-SqMod/SqMod.git
synced 2025-01-31 09:57:14 +01:00
Add a helper function to iterate over the elements in a script object more efficiently and easier.
This commit is contained in:
parent
c17a54b907
commit
641fa973e0
@ -499,6 +499,30 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/// Used to go through all the slots in an Object (same limitations as sq_next)
|
||||
///
|
||||
/// \param func Functor that is continuously called to process values on the stack
|
||||
///
|
||||
/// \tparam F Type of functor (usually doesnt need to be defined explicitly)
|
||||
///
|
||||
/// \return Nothing
|
||||
///
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
template<class F>
|
||||
void Foreach(F&& func) const
|
||||
{
|
||||
sq_pushobject(vm,obj);
|
||||
sq_pushnull(vm);
|
||||
while(SQ_SUCCEEDED(sq_next(vm,-2)))
|
||||
{
|
||||
func(vm); // -1 is the value and -2 is the key
|
||||
sq_pop(vm,2); // Pop the key and value
|
||||
}
|
||||
// Pop the null iterator and the object
|
||||
sq_pop(vm,2);
|
||||
}
|
||||
|
||||
protected:
|
||||
/// @cond DEV
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user