Welcome Guest Search | Active Topics | Log In | Register

Problems embedding squirrel into library.
#1 Posted : Tuesday, May 22, 2018 3:45:01 PM(UTC)
Rank: Newbie

Groups: Registered
Joined: 5/21/2018(UTC)
Posts: 1
Location: america

Thanks: 0 times
Was thanked: 0 time(s) in 0 post(s)
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.");
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.
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.
Users browsing this topic
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

Clean Slate theme by Jaben Cargman (Tiny Gecko)
Powered by YAF 1.9.4 | YAF © 2003-2010, Yet Another Forum.NET
This page was generated in 0.045 seconds.