1
0
mirror of https://github.com/VCMP-SqMod/SqMod.git synced 2025-04-01 01:47:13 +02:00

Update sqratFunction.h

Allow the Assign method to use null.
This commit is contained in:
Sandu Liviu Catalin 2019-08-19 22:28:17 +03:00
parent 789fb31273
commit f97bf22673

View File

@ -180,7 +180,7 @@ struct Function {
// If `idx1` is null, it defaults to root table // If `idx1` is null, it defaults to root table
// If `idx1` is an object, it will be used as the environment // If `idx1` is an object, it will be used as the environment
// If `idx1` is actually a function/closure then `idx2` is ignored // If `idx1` is actually a function/closure then `idx2` is ignored
bool Assign(HSQUIRRELVM vm, SQInteger idx1, SQInteger idx2) { bool Assign(HSQUIRRELVM vm, SQInteger idx1, SQInteger idx2, bool bind_null=false) {
// Release current callback, if any // Release current callback, if any
Release(); Release();
// Tells if the current environment was used // Tells if the current environment was used
@ -209,8 +209,12 @@ struct Function {
} }
// Retrieve the callback type // Retrieve the callback type
const SQObjectType ty2 = sq_gettype(vm, idx2); const SQObjectType ty2 = sq_gettype(vm, idx2);
// Can we bind null?
if (bind_null && ty2 == OT_NULL) {
sq_resetobject(&mEnv); // Drop the environment, if any
return cenv; // Just stop knowing this is what we want
// Is the callback is valid? // Is the callback is valid?
if (ty2 & (_RT_CLOSURE | _RT_NATIVECLOSURE)) { } else if (ty2 & (_RT_CLOSURE | _RT_NATIVECLOSURE)) {
sq_getstackobj(vm, idx2, &mObj); sq_getstackobj(vm, idx2, &mObj);
// Reference the environment and function // Reference the environment and function
sq_addref(vm, &mEnv); sq_addref(vm, &mEnv);