diff --git a/include/sqrat/sqratGlobalMethods.h b/include/sqrat/sqratGlobalMethods.h index ce4adf37..319fe1fe 100644 --- a/include/sqrat/sqratGlobalMethods.h +++ b/include/sqrat/sqratGlobalMethods.h @@ -47,7 +47,7 @@ namespace Sqrat { template struct SqGlobalProxy { template static SQInteger Run(HSQUIRRELVM vm, SQInteger idx) { ArgPop a(vm, idx); - if (SQ_FAILED(a.Proc())) { + if (SQ_FAILED(a.Proc(sq_gettop(vm) == idx - 1 + static_cast< SQInteger >(sizeof...(A))))) { return a.ProcRes(); } a.Call(vm, [](HSQUIRRELVM vm, A... a) { @@ -68,7 +68,7 @@ template struct SqGlobalProxy { template struct SqGlobalProxy { template static SQInteger Run(HSQUIRRELVM vm, SQInteger idx) { ArgPop a(vm, idx); - if (SQ_FAILED(a.Proc())) { + if (SQ_FAILED(a.Proc(sq_gettop(vm) == idx - 1 + static_cast< SQInteger >(sizeof...(A))))) { return a.ProcRes(); } a.Call(vm, [](HSQUIRRELVM vm, A... a) { @@ -89,7 +89,7 @@ template struct SqGlobalProxy { template <> struct SqGlobalProxy { template static SQInteger Run(HSQUIRRELVM vm, SQInteger idx) { ArgPop a(vm, idx); - if (SQ_FAILED(a.Proc())) { + if (SQ_FAILED(a.Proc(sq_gettop(vm) == idx - 1 + static_cast< SQInteger >(sizeof...(A))))) { return a.ProcRes(); } a.Call(vm, [](HSQUIRRELVM vm, A... a) { @@ -109,7 +109,7 @@ template struct SqGlobalParamCheck { }; template<> struct SqGlobalParamCheck { static inline bool Invalid(SQInteger top, SQInteger count) { - return top < count; + return top < (count - 1); } }; @@ -145,7 +145,7 @@ template struct SqGlobal { template static SQFUNCTION GetProxy() noexcept { return +[](HSQUIRRELVM vm) noexcept -> SQInteger { #if !defined (SCRAT_NO_ERROR_CHECKING) - if (!SQRAT_CONST_CONDITION(overloaded) && sq_gettop(vm) && + if (!SQRAT_CONST_CONDITION(overloaded) && SqGlobalParamCheck< ArgPop::HASFMT >::Invalid(sq_gettop(vm), startIdx + sizeof...(A))) { return sq_throwerror(vm, _SC("wrong number of parameters")); } @@ -169,7 +169,7 @@ template <> struct SqGlobal { template static SQFUNCTION GetProxy() noexcept { return +[](HSQUIRRELVM vm) noexcept -> SQInteger { #if !defined (SCRAT_NO_ERROR_CHECKING) - if (!SQRAT_CONST_CONDITION(overloaded) && sq_gettop(vm) && + if (!SQRAT_CONST_CONDITION(overloaded) && SqGlobalParamCheck< ArgPop::HASFMT >::Invalid(sq_gettop(vm), startIdx + sizeof...(A))) { return sq_throwerror(vm, _SC("wrong number of parameters")); } diff --git a/include/sqrat/sqratUtil.h b/include/sqrat/sqratUtil.h index cda6e281..010d019f 100644 --- a/include/sqrat/sqratUtil.h +++ b/include/sqrat/sqratUtil.h @@ -1593,7 +1593,7 @@ struct StackStrF ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// StackStrF(HSQUIRRELVM vm, SQInteger idx) : mPtr(nullptr) - , mLen(-1) + , mLen(SQ_ERROR) , mRes(SQ_OK) , mObj() , mVM(vm) @@ -1659,6 +1659,7 @@ struct StackStrF // Since this is a dummy then avoid making it look like a failure mPtr = _SC(""); mLen = 0; + mRes = SQ_OK; // We're not supposed to proceed with this! return mRes; } @@ -1669,6 +1670,14 @@ struct StackStrF { mRes = sq_throwerror(mVM, "Missing string or value"); } + // If null was specified then treat it as a dummy + else if (sq_gettype(mVM, mIdx) == OT_NULL) + { + // Default to an empty string and ignore formatting even if possible + mPtr = _SC(""); + mLen = 0; + mRes = SQ_OK; + } // Do we have enough values to call the format function and are we allowed to? else if (fmt && (top - 1) >= mIdx) {