Skip to content

Fallback if IScriptInstanceHelper::Get/Set are not implemented #441

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 37 additions & 9 deletions sp/src/vscript/vscript_squirrel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1604,7 +1604,19 @@ SQInteger get_stub(HSQUIRRELVM vm)
}
else
{
sq_retval = sqstd_throwerrorf(vm, "the index '%.50s' does not exist", key);
// Fallback
// Extra stack variables don't need to be popped, they are cleaned up on exit
sq_pushroottable(vm);
sq_push(vm, -2);

if ( SQ_SUCCEEDED( sq_rawget(vm, -2) ) )
{
sq_retval = 1;
}
else
{
sq_retval = sqstd_throwerrorf(vm, "the index '%.50s' does not exist", key);
}
}

var.Free();
Expand Down Expand Up @@ -1635,11 +1647,24 @@ SQInteger set_stub(HSQUIRRELVM vm)
classInstanceData->desc->pHelper->Set(classInstanceData->instance, key, var)
))
{
sq_retval = sqstd_throwerrorf(vm, "the index '%.50s' does not exist", key);
// Fallback
sq_pushroottable(vm);
sq_push(vm, -3);
sq_push(vm, -3);

if ( SQ_SUCCEEDED( sq_rawset(vm, -3) ) )
{
// rawset doesn't return correctly, pop env to return val
sq_pop(vm, 1);
sq_retval = 1;
}
else
{
sq_retval = sqstd_throwerrorf(vm, "the index '%.50s' does not exist", key);
}
}

var.Free();
sq_pop(vm, 1);
return sq_retval;
}

Expand Down Expand Up @@ -2515,13 +2540,16 @@ bool SquirrelVM::RegisterClass(ScriptClassDesc_t* pClassDesc)
sq_newclosure(vm_, tostring_stub, 0);
sq_newslot(vm_, -3, SQFalse);

sq_pushstring(vm_, "_get", -1);
sq_newclosure(vm_, get_stub, 0);
sq_newslot(vm_, -3, SQFalse);
if ( pClassDesc->pHelper )
{
sq_pushstring(vm_, "_get", -1);
sq_newclosure(vm_, get_stub, 0);
sq_newslot(vm_, -3, SQFalse);

sq_pushstring(vm_, "_set", -1);
sq_newclosure(vm_, set_stub, 0);
sq_newslot(vm_, -3, SQFalse);
sq_pushstring(vm_, "_set", -1);
sq_newclosure(vm_, set_stub, 0);
sq_newslot(vm_, -3, SQFalse);
}

sq_pushstring(vm_, "IsValid", -1);
sq_newclosure(vm_, IsValid_stub, 0);
Expand Down