Add: [Script] Optional filter parameter to more ScriptXXXList constructors (#11698)

This commit is contained in:
Loïc Guilloux
2024-01-09 09:39:13 +01:00
committed by GitHub
parent f1e999ec59
commit c86d918921
17 changed files with 283 additions and 120 deletions

View File

@@ -361,6 +361,15 @@ void sq_setdebughook(HSQUIRRELVM v);
#define sq_isweakref(o) ((o)._type==OT_WEAKREF)
#define sq_type(o) ((o)._type)
/* Limit the total number of ops that can be consumed by an operation */
struct SQOpsLimiter {
SQOpsLimiter(HSQUIRRELVM v, SQInteger ops, const char *label);
~SQOpsLimiter();
private:
HSQUIRRELVM _v;
SQInteger _ops;
};
/* deprecated */
#define sq_createslot(v,n) sq_newslot(v,n,SQFalse)

View File

@@ -1323,3 +1323,16 @@ void sq_free(void *p,SQUnsignedInteger size)
SQ_FREE(p,size);
}
SQOpsLimiter::SQOpsLimiter(HSQUIRRELVM v, SQInteger ops, const char *label) : _v(v)
{
this->_ops = v->_ops_till_suspend_error_threshold;
if (this->_ops == INT64_MIN) {
v->_ops_till_suspend_error_threshold = v->_ops_till_suspend - ops;
v->_ops_till_suspend_error_label = label;
}
}
SQOpsLimiter::~SQOpsLimiter()
{
this->_v->_ops_till_suspend_error_threshold = this->_ops;
}