From e9cbcd173d16452e21b1e0cf31c6937234407f7d Mon Sep 17 00:00:00 2001 From: James Mitchell Date: Sat, 20 Jun 2020 13:10:37 +1000 Subject: [PATCH 1/2] Adding IsValid to vscript --- sp/src/vscript/vscript_squirrel.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/sp/src/vscript/vscript_squirrel.cpp b/sp/src/vscript/vscript_squirrel.cpp index 81c2f308..17d018cd 100644 --- a/sp/src/vscript/vscript_squirrel.cpp +++ b/sp/src/vscript/vscript_squirrel.cpp @@ -1067,6 +1067,14 @@ SQInteger tostring_stub(HSQUIRRELVM vm) return 1; } +SQInteger IsValid_stub(HSQUIRRELVM vm) +{ + ClassInstanceData* classInstanceData = nullptr; + sq_getinstanceup(vm, 1, (SQUserPointer*)&classInstanceData, 0); + sq_pushbool(vm, classInstanceData == nullptr); + return 1; +} + struct SquirrelSafeCheck { SquirrelSafeCheck(HSQUIRRELVM vm, int outputCount = 0) : @@ -1719,6 +1727,10 @@ bool SquirrelVM::RegisterClass(ScriptClassDesc_t* pClassDesc) sq_newclosure(vm_, tostring_stub, 0); sq_newslot(vm_, -3, SQFalse); + sq_pushstring(vm_, "IsValid", -1); + sq_newclosure(vm_, IsValid_stub, 0); + sq_newslot(vm_, -3, SQFalse); + for (int i = 0; i < pClassDesc->m_FunctionBindings.Count(); ++i) { From 1d4dfe7d4c4820de46ccb8c61890bb1791c8bfd7 Mon Sep 17 00:00:00 2001 From: James Date: Sat, 20 Jun 2020 14:10:10 +1000 Subject: [PATCH 2/2] Fixing IsValid outputting the opposite of being valid --- sp/src/vscript/vscript_squirrel.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sp/src/vscript/vscript_squirrel.cpp b/sp/src/vscript/vscript_squirrel.cpp index 17d018cd..a16ac7a5 100644 --- a/sp/src/vscript/vscript_squirrel.cpp +++ b/sp/src/vscript/vscript_squirrel.cpp @@ -1071,7 +1071,7 @@ SQInteger IsValid_stub(HSQUIRRELVM vm) { ClassInstanceData* classInstanceData = nullptr; sq_getinstanceup(vm, 1, (SQUserPointer*)&classInstanceData, 0); - sq_pushbool(vm, classInstanceData == nullptr); + sq_pushbool(vm, classInstanceData != nullptr); return 1; } @@ -3034,4 +3034,4 @@ bool SquirrelVM::RaiseException(const char* pszExceptionText) IScriptVM* makeSquirrelVM() { return new SquirrelVM; -} \ No newline at end of file +}