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

Add a helper function to append multiple elements into a script array more efficiently and easier.

This commit is contained in:
Sandu Liviu Catalin 2017-06-19 14:06:01 +03:00
parent d8c9be59d4
commit c17a54b907

View File

@ -498,6 +498,28 @@ public:
sq_pop(vm, 1);
return r;
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Appends values to the end of the Array
///
/// \param func Functor that is continuously called to push values on the stack
///
/// \tparam F Type of functor (usually doesnt need to be defined explicitly)
///
/// \return The Array itself so the call can be chained
///
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
template<class F>
ArrayBase& AppendFrom(F&& func) {
sq_pushobject(vm, GetObject());
while (func(vm))
{
sq_arrayappend(vm, -2);
}
sq_pop(vm,1); // pop array
return *this;
}
};
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////