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

Allow null parameters in StackStrF.

This commit is contained in:
Sandu Liviu Catalin 2018-07-30 20:40:52 +03:00
parent 4e31fc478c
commit ecca09d6ce
2 changed files with 16 additions and 7 deletions

View File

@ -47,7 +47,7 @@ namespace Sqrat {
template <class R> struct SqGlobalProxy { template <class R> struct SqGlobalProxy {
template <class... A> static SQInteger Run(HSQUIRRELVM vm, SQInteger idx) { template <class... A> static SQInteger Run(HSQUIRRELVM vm, SQInteger idx) {
ArgPop<A...> a(vm, idx); ArgPop<A...> 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(); return a.ProcRes();
} }
a.Call(vm, [](HSQUIRRELVM vm, A... a) { a.Call(vm, [](HSQUIRRELVM vm, A... a) {
@ -68,7 +68,7 @@ template <class R> struct SqGlobalProxy {
template <class R> struct SqGlobalProxy<R&> { template <class R> struct SqGlobalProxy<R&> {
template <class... A> static SQInteger Run(HSQUIRRELVM vm, SQInteger idx) { template <class... A> static SQInteger Run(HSQUIRRELVM vm, SQInteger idx) {
ArgPop<A...> a(vm, idx); ArgPop<A...> 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(); return a.ProcRes();
} }
a.Call(vm, [](HSQUIRRELVM vm, A... a) { a.Call(vm, [](HSQUIRRELVM vm, A... a) {
@ -89,7 +89,7 @@ template <class R> struct SqGlobalProxy<R&> {
template <> struct SqGlobalProxy<void> { template <> struct SqGlobalProxy<void> {
template <class... A> static SQInteger Run(HSQUIRRELVM vm, SQInteger idx) { template <class... A> static SQInteger Run(HSQUIRRELVM vm, SQInteger idx) {
ArgPop<A...> a(vm, idx); ArgPop<A...> 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(); return a.ProcRes();
} }
a.Call(vm, [](HSQUIRRELVM vm, A... a) { a.Call(vm, [](HSQUIRRELVM vm, A... a) {
@ -109,7 +109,7 @@ template<bool> struct SqGlobalParamCheck {
}; };
template<> struct SqGlobalParamCheck<true> { template<> struct SqGlobalParamCheck<true> {
static inline bool Invalid(SQInteger top, SQInteger count) { static inline bool Invalid(SQInteger top, SQInteger count) {
return top < count; return top < (count - 1);
} }
}; };
@ -145,7 +145,7 @@ template <class R> struct SqGlobal<R&> {
template <SQInteger startIdx, bool overloaded, class... A> static SQFUNCTION GetProxy() noexcept { template <SQInteger startIdx, bool overloaded, class... A> static SQFUNCTION GetProxy() noexcept {
return +[](HSQUIRRELVM vm) noexcept -> SQInteger { return +[](HSQUIRRELVM vm) noexcept -> SQInteger {
#if !defined (SCRAT_NO_ERROR_CHECKING) #if !defined (SCRAT_NO_ERROR_CHECKING)
if (!SQRAT_CONST_CONDITION(overloaded) && sq_gettop(vm) && if (!SQRAT_CONST_CONDITION(overloaded) &&
SqGlobalParamCheck< ArgPop<A...>::HASFMT >::Invalid(sq_gettop(vm), startIdx + sizeof...(A))) { SqGlobalParamCheck< ArgPop<A...>::HASFMT >::Invalid(sq_gettop(vm), startIdx + sizeof...(A))) {
return sq_throwerror(vm, _SC("wrong number of parameters")); return sq_throwerror(vm, _SC("wrong number of parameters"));
} }
@ -169,7 +169,7 @@ template <> struct SqGlobal<void> {
template <SQInteger startIdx, bool overloaded, class... A> static SQFUNCTION GetProxy() noexcept { template <SQInteger startIdx, bool overloaded, class... A> static SQFUNCTION GetProxy() noexcept {
return +[](HSQUIRRELVM vm) noexcept -> SQInteger { return +[](HSQUIRRELVM vm) noexcept -> SQInteger {
#if !defined (SCRAT_NO_ERROR_CHECKING) #if !defined (SCRAT_NO_ERROR_CHECKING)
if (!SQRAT_CONST_CONDITION(overloaded) && sq_gettop(vm) && if (!SQRAT_CONST_CONDITION(overloaded) &&
SqGlobalParamCheck< ArgPop<A...>::HASFMT >::Invalid(sq_gettop(vm), startIdx + sizeof...(A))) { SqGlobalParamCheck< ArgPop<A...>::HASFMT >::Invalid(sq_gettop(vm), startIdx + sizeof...(A))) {
return sq_throwerror(vm, _SC("wrong number of parameters")); return sq_throwerror(vm, _SC("wrong number of parameters"));
} }

View File

@ -1593,7 +1593,7 @@ struct StackStrF
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
StackStrF(HSQUIRRELVM vm, SQInteger idx) StackStrF(HSQUIRRELVM vm, SQInteger idx)
: mPtr(nullptr) : mPtr(nullptr)
, mLen(-1) , mLen(SQ_ERROR)
, mRes(SQ_OK) , mRes(SQ_OK)
, mObj() , mObj()
, mVM(vm) , mVM(vm)
@ -1659,6 +1659,7 @@ struct StackStrF
// Since this is a dummy then avoid making it look like a failure // Since this is a dummy then avoid making it look like a failure
mPtr = _SC(""); mPtr = _SC("");
mLen = 0; mLen = 0;
mRes = SQ_OK;
// We're not supposed to proceed with this! // We're not supposed to proceed with this!
return mRes; return mRes;
} }
@ -1669,6 +1670,14 @@ struct StackStrF
{ {
mRes = sq_throwerror(mVM, "Missing string or value"); 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? // Do we have enough values to call the format function and are we allowed to?
else if (fmt && (top - 1) >= mIdx) else if (fmt && (top - 1) >= mIdx)
{ {