Skip to content

Instantly share code, notes, and snippets.

@mathewmariani
Last active June 23, 2017 15:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mathewmariani/870552fa9a49ef4bb12d9657bb155cce to your computer and use it in GitHub Desktop.
Save mathewmariani/870552fa9a49ef4bb12d9657bb155cce to your computer and use it in GitHub Desktop.
static SQRegFunction reg[] = {
// I believe the main reason this fails is due to the arguments.
// but when looking at DXSquirrel (specifically DXSquirrel_Device.cpp) there's nothing special done about it.
{ "getData", wrap_getData, 2, _SC("ts") },
{ "getTestData", wrap_getTestData, NULL, NULL },
{ 0, 0 }
};
int wrap_getData(SQVM* v) {
// fails when we have arguments
const char* arg0;
sq_getstring(v, -1, &arg0);
auto instance = new Data;
// pop arguments off stack
// fails with or without poping arguments off stack
SQInteger nargs = sq_gettop(v);
sq_pop(v, nargs);
// fails with or without lambda
auto ret = [&]() -> int {
sq_pushstring(v, "Data", -1);
if (SQ_FAILED(sq_get(v, -2))) {
// failure here.
return sq_throwerror(v, "Couldn't resolve squirrel type 'Data'");
}
if (SQ_FAILED(sq_createinstance(v, 1)) || SQ_FAILED(sq_setinstanceup(v, 1, instance))) {
return sq_throwerror(v, "Couldn't setup squirrel instance for object type 'Data'");
}
sq_setreleasehook(v, 1, release_hook<Data>);
sq_remove(v, -2); // remove object name
return 1;
};
return ret();
}
int wrap_getTestData(SQVM* v) {
sq_pushstring(v, "Data", -1);
if (SQ_FAILED(sq_get(v, -2))) {
throw sq_throwerror(v, "Couldn't resolve squirrel type 'Data'");
}
auto instance = new Data;
if (SQ_FAILED(sq_createinstance(v, -1)) || SQ_FAILED(sq_setinstanceup(v, -1, instance))) {
throw sq_throwerror(v, "Couldn't setup squirrel instance for object type 'Data'");
}
sq_setreleasehook(v, -1, release_hook<Data>);
sq_remove(v, -2); // remove object name
return 1;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment