Is there any way to use or include capture lambdas?
Trying to build a generic library with squirrel, but I cannot use my functions without templates, and since the methodology requires the functions to be virtual it wont work.
For example if I try to pack down the arguments into a void pointer array to avoid templates, and pass an argument list then arbitrarily pop them off the stack with some sort of helper function,
I need to be able to pass some sort of state information along with the function.
Option 1:
Any way to mod squirrel to accept a state through sq_newclosure?
void sq_newclosure(HSQUIRRELVM v,SQFUNCTION func,void* state,SQUnsignedInteger nfreevars)
So if I used a helper struct.
struct Helper
{
SQInteger callback(HSQUIRRELVM v)
{
SQInteger args = sq_gettop(v); //Get number of arguments in function call.
if (args != arguments.size())
{
sq_throwerror(v, "Invalid Number of arguments.");
return;
}
void** data = new void*[arguments.size()];
for (unsigned int i = 0; i < arguments.size();i++)
{
if (sq_typeof(v, -1 * i) != typeof(arguments[i]) //Check types match.
{
sq_throwerror(v, "Argument number bla is invalid");
}
//Pop from sq stack cast to void* and store in data.
}
f(data);
delete[] data;
}
std::string arguments;
function_callback f;
};
I could then pass the state of the helper struct along through the sq_newclosure, setting the state as needed.