mirror of
https://github.com/VCMP-SqMod/SqMod.git
synced 2025-01-31 09:57:14 +01:00
Take into account StackStrF when checking parameter count.
This commit is contained in:
parent
3080c20341
commit
3225e119a2
@ -232,7 +232,7 @@ struct Function {
|
||||
template<class R, class... Args> SharedPtr<R> Evaluate(Args &&... args) {
|
||||
static constexpr unsigned ARGC = sizeof...(Args) + 1; // + environment
|
||||
HSQUIRRELVM vm = DefaultVM::Get_();
|
||||
SQInteger top = sq_gettop(vm);
|
||||
const SQInteger top = sq_gettop(vm);
|
||||
// Push the environment followed by the function
|
||||
sq_pushobject(vm, mObj);
|
||||
sq_pushobject(vm, mEnv);
|
||||
@ -240,7 +240,8 @@ struct Function {
|
||||
#if !defined (SCRAT_NO_ERROR_CHECKING)
|
||||
SQInteger nparams;
|
||||
SQInteger nfreevars;
|
||||
if (SQ_SUCCEEDED(sq_getclosureinfo(vm, -2, &nparams, &nfreevars)) && (nparams != ARGC)) {
|
||||
if (SQ_SUCCEEDED(sq_getclosureinfo(vm, -2, &nparams, &nfreevars)) &&
|
||||
SqGlobalParamInspect< ArgFwd<Args...>::HASFMT >::Invalid(nparams, ARGC)) {
|
||||
sq_pop(vm, 2);
|
||||
SQTHROW(vm, _SC("wrong number of parameters"));
|
||||
return SharedPtr<R>();
|
||||
@ -271,7 +272,7 @@ struct Function {
|
||||
void Execute(Args &&... args) {
|
||||
static constexpr unsigned ARGC = sizeof...(Args) + 1; // + environment
|
||||
HSQUIRRELVM vm = DefaultVM::Get_();
|
||||
SQInteger top = sq_gettop(vm);
|
||||
const SQInteger top = sq_gettop(vm);
|
||||
// Push the environment followed by the function
|
||||
sq_pushobject(vm, mObj);
|
||||
sq_pushobject(vm, mEnv);
|
||||
@ -279,7 +280,8 @@ struct Function {
|
||||
#if !defined (SCRAT_NO_ERROR_CHECKING)
|
||||
SQInteger nparams;
|
||||
SQInteger nfreevars;
|
||||
if (SQ_SUCCEEDED(sq_getclosureinfo(vm, -2, &nparams, &nfreevars)) && (nparams != ARGC)) {
|
||||
if (SQ_SUCCEEDED(sq_getclosureinfo(vm, -2, &nparams, &nfreevars)) &&
|
||||
SqGlobalParamInspect< ArgFwd<Args...>::HASFMT >::Invalid(nparams, ARGC)) {
|
||||
sq_pop(vm, 2);
|
||||
SQTHROW(vm, _SC("wrong number of parameters"));
|
||||
return;
|
||||
|
@ -101,6 +101,17 @@ template<> struct SqGlobalParamCheck<true> {
|
||||
}
|
||||
};
|
||||
|
||||
template<bool> struct SqGlobalParamInspect {
|
||||
static inline bool Invalid(SQInteger need, SQInteger have) {
|
||||
return need != have;
|
||||
}
|
||||
};
|
||||
template<> struct SqGlobalParamInspect<true> {
|
||||
static inline bool Invalid(SQInteger need, SQInteger have) {
|
||||
return need < (have - 1);
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
// Squirrel Global Functions
|
||||
//
|
||||
|
Loading…
x
Reference in New Issue
Block a user