From e2528e88ddfc7972aabec9dce208b11445575c40 Mon Sep 17 00:00:00 2001 From: Sandu Liviu Catalin Date: Mon, 15 Mar 2021 07:00:39 +0200 Subject: [PATCH] Update sqratFunction.h --- module/Sqrat/sqratFunction.h | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/module/Sqrat/sqratFunction.h b/module/Sqrat/sqratFunction.h index e4ee50aa..fdc1307e 100644 --- a/module/Sqrat/sqratFunction.h +++ b/module/Sqrat/sqratFunction.h @@ -85,6 +85,33 @@ struct Function { if (value_type != OT_CLOSURE && value_type != OT_NATIVECLOSURE) { SQTHROW(vm, FormatTypeError(vm, idx, _SC("closure"))); } +#endif + } + // Constructs a Function from a table off the stack at the specified index + Function(HSQUIRRELVM vm, SQInteger idx, const SQChar* slot) { + sq_pushstring(vm, slot, -1); +#if !defined (SCRAT_NO_ERROR_CHECKING) + if(SQ_FAILED(sq_get(vm, idx))) { + sq_poptop(vm); + sq_resetobject(&mEnv); + sq_resetobject(&mObj); + } else { + sq_getstackobj(vm, -1, &mObj); + sq_getstackobj(vm, idx, &mEnv); + if (sq_type(mObj) == OT_CLOSURE || sq_type(mObj) == OT_NATIVECLOSURE) { + sq_addref(vm, &mEnv); + sq_addref(vm, &mObj); + } else { + sq_resetobject(&mEnv); + sq_resetobject(&mObj); + } + sq_poptop(vm); + } +#else + sq_get(vm, idx); + sq_getstackobj(vm, -1, &mObj); + sq_getstackobj(vm, idx, &mEnv); + sq_poptop(vm); #endif } // Constructs a Function from a value off the stack at the specified index pointed by `idx2`