mirror of
https://github.com/VCMP-SqMod/SqMod.git
synced 2024-11-08 00:37:15 +01:00
Update sqratFunction.h
This commit is contained in:
parent
e86e5d5741
commit
cdf57cd0be
@ -318,6 +318,45 @@ struct Function {
|
|||||||
sq_settop(vm, top);
|
sq_settop(vm, top);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
// Runs the Function and returns its value as R
|
||||||
|
template<class R, class... Args> R Evaluate_(SqTypeIdentity<R>, Args &&... args) const {
|
||||||
|
static constexpr unsigned ARGC = sizeof...(Args) + 1; // + environment
|
||||||
|
HSQUIRRELVM vm = SqVM();
|
||||||
|
const SQInteger top = sq_gettop(vm);
|
||||||
|
// Push the environment followed by the function
|
||||||
|
sq_pushobject(vm, mObj);
|
||||||
|
sq_pushobject(vm, mEnv);
|
||||||
|
// Validate the funtion parameter count
|
||||||
|
#if !defined (SCRAT_NO_ERROR_CHECKING)
|
||||||
|
SQInteger nparams;
|
||||||
|
SQInteger nfreevars;
|
||||||
|
if (SQ_SUCCEEDED(sq_getclosureinfo(vm, -2, &nparams, &nfreevars)) &&
|
||||||
|
SqGlobalParamInspect< ArgFwd<Args...>::HASOPT >::Invalid(nparams, ARGC)) {
|
||||||
|
sq_pop(vm, 2);
|
||||||
|
SQTHROW(vm, _SC("wrong number of parameters"));
|
||||||
|
return R();
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
// Push the arguments
|
||||||
|
PushVars(vm, std::forward<Args>(args)...);
|
||||||
|
|
||||||
|
#if !defined (SCRAT_NO_ERROR_CHECKING)
|
||||||
|
SQRESULT result = sq_call(vm, ARGC, true, ErrorHandling::IsEnabled());
|
||||||
|
|
||||||
|
//handle an error: pop the stack and throw the exception
|
||||||
|
if (SQ_FAILED(result)) {
|
||||||
|
sq_settop(vm, top);
|
||||||
|
SQTHROW(vm, LastErrorString(vm));
|
||||||
|
return R();
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
sq_call(vm, ARGC, true, ErrorHandling::IsEnabled());
|
||||||
|
#endif
|
||||||
|
|
||||||
|
Var<R> r(vm, -1);
|
||||||
|
sq_settop(vm, top);
|
||||||
|
return r.value;
|
||||||
|
}
|
||||||
// Runs the Function
|
// Runs the Function
|
||||||
template< class... Args >
|
template< class... Args >
|
||||||
void Execute(Args &&... args) const {
|
void Execute(Args &&... args) const {
|
||||||
|
Loading…
Reference in New Issue
Block a user