mirror of
https://github.com/VCMP-SqMod/SqMod.git
synced 2025-01-19 03:57:14 +01:00
Always name native functions to help debugging with a more clear traceback.
This commit is contained in:
parent
b1c8ab0f7b
commit
7ad3790f8c
@ -156,10 +156,12 @@ public:
|
|||||||
/// \return The Array itself so the call can be chained
|
/// \return The Array itself so the call can be chained
|
||||||
///
|
///
|
||||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
ArrayBase& SquirrelFunc(const SQInteger index, SQFUNCTION func) {
|
ArrayBase& SquirrelFunc(const SQInteger index, SQFUNCTION func, const SQChar* name = nullptr) {
|
||||||
sq_pushobject(vm, GetObject());
|
sq_pushobject(vm, GetObject());
|
||||||
sq_pushinteger(vm, index);
|
sq_pushinteger(vm, index);
|
||||||
sq_newclosure(vm, func, 0);
|
sq_newclosure(vm, func, 0);
|
||||||
|
// Set the closure name (for debug purposes)
|
||||||
|
if (name) sq_setnativeclosurename(vm, -1, name);
|
||||||
sq_set(vm, -3);
|
sq_set(vm, -3);
|
||||||
sq_pop(vm,1); // pop array
|
sq_pop(vm,1); // pop array
|
||||||
return *this;
|
return *this;
|
||||||
@ -215,8 +217,8 @@ public:
|
|||||||
///
|
///
|
||||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
template<class F>
|
template<class F>
|
||||||
ArrayBase& Func(const SQInteger index, F method) {
|
ArrayBase& Func(const SQInteger index, F method, const SQChar* name = nullptr) {
|
||||||
BindFunc(index, &method, sizeof(method), SqGlobalFunc(method));
|
BindFunc(index, &method, sizeof(method), SqGlobalFunc(method), name);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -558,6 +558,8 @@ public:
|
|||||||
sq_pushobject(vm, ClassType<C>::getClassData(vm)->classObj);
|
sq_pushobject(vm, ClassType<C>::getClassData(vm)->classObj);
|
||||||
sq_pushstring(vm, name, -1);
|
sq_pushstring(vm, name, -1);
|
||||||
sq_newclosure(vm, func, 0);
|
sq_newclosure(vm, func, 0);
|
||||||
|
// Set the closure name (for debug purposes)
|
||||||
|
sq_setnativeclosurename(vm, -1, name);
|
||||||
sq_newslot(vm, -3, false);
|
sq_newslot(vm, -3, false);
|
||||||
sq_pop(vm, 1); // pop table
|
sq_pop(vm, 1); // pop table
|
||||||
|
|
||||||
@ -644,6 +646,8 @@ protected:
|
|||||||
// add the default constructor
|
// add the default constructor
|
||||||
sq_pushstring(vm, _SC("constructor"), -1);
|
sq_pushstring(vm, _SC("constructor"), -1);
|
||||||
sq_newclosure(vm, &A::New, 0);
|
sq_newclosure(vm, &A::New, 0);
|
||||||
|
// Set the closure name (for debug purposes)
|
||||||
|
sq_setnativeclosurename(vm, -1, _SC("constructor"));
|
||||||
sq_newslot(vm, -3, false);
|
sq_newslot(vm, -3, false);
|
||||||
|
|
||||||
// add the set table (static)
|
// add the set table (static)
|
||||||
@ -668,27 +672,37 @@ protected:
|
|||||||
sq_pushstring(vm, _SC("_set"), -1);
|
sq_pushstring(vm, _SC("_set"), -1);
|
||||||
sq_pushobject(vm, setTable); // Push the set table as a free variable
|
sq_pushobject(vm, setTable); // Push the set table as a free variable
|
||||||
sq_newclosure(vm, &sqVarSet, 1);
|
sq_newclosure(vm, &sqVarSet, 1);
|
||||||
|
// Set the closure name (for debug purposes)
|
||||||
|
sq_setnativeclosurename(vm, -1, _SC("_set"));
|
||||||
sq_newslot(vm, -3, false);
|
sq_newslot(vm, -3, false);
|
||||||
|
|
||||||
// override _get
|
// override _get
|
||||||
sq_pushstring(vm, _SC("_get"), -1);
|
sq_pushstring(vm, _SC("_get"), -1);
|
||||||
sq_pushobject(vm, getTable); // Push the get table as a free variable
|
sq_pushobject(vm, getTable); // Push the get table as a free variable
|
||||||
sq_newclosure(vm, &sqVarGet, 1);
|
sq_newclosure(vm, &sqVarGet, 1);
|
||||||
|
// Set the closure name (for debug purposes)
|
||||||
|
sq_setnativeclosurename(vm, -1, _SC("_get"));
|
||||||
sq_newslot(vm, -3, false);
|
sq_newslot(vm, -3, false);
|
||||||
|
|
||||||
// add weakref (apparently not provided by default)
|
// add weakref (apparently not provided by default)
|
||||||
sq_pushstring(vm, _SC("weakref"), -1);
|
sq_pushstring(vm, _SC("weakref"), -1);
|
||||||
sq_newclosure(vm, &Class::ClassWeakref, 0);
|
sq_newclosure(vm, &Class::ClassWeakref, 0);
|
||||||
|
// Set the closure name (for debug purposes)
|
||||||
|
sq_setnativeclosurename(vm, -1, _SC("weakref"));
|
||||||
sq_newslot(vm, -3, false);
|
sq_newslot(vm, -3, false);
|
||||||
|
|
||||||
// add _typeof
|
// add _typeof
|
||||||
sq_pushstring(vm, _SC("_typeof"), -1);
|
sq_pushstring(vm, _SC("_typeof"), -1);
|
||||||
sq_newclosure(vm, &Class::ClassTypeof, 0);
|
sq_newclosure(vm, &Class::ClassTypeof, 0);
|
||||||
|
// Set the closure name (for debug purposes)
|
||||||
|
sq_setnativeclosurename(vm, -1, _SC("_typeof"));
|
||||||
sq_newslot(vm, -3, false);
|
sq_newslot(vm, -3, false);
|
||||||
|
|
||||||
// add _cloned
|
// add _cloned
|
||||||
sq_pushstring(vm, _SC("_cloned"), -1);
|
sq_pushstring(vm, _SC("_cloned"), -1);
|
||||||
sq_newclosure(vm, &Class::ClassCloned, 0);
|
sq_newclosure(vm, &Class::ClassCloned, 0);
|
||||||
|
// Set the closure name (for debug purposes)
|
||||||
|
sq_setnativeclosurename(vm, -1, _SC("_cloned"));
|
||||||
sq_newslot(vm, -3, false);
|
sq_newslot(vm, -3, false);
|
||||||
|
|
||||||
// pop the class
|
// pop the class
|
||||||
@ -707,6 +721,8 @@ protected:
|
|||||||
|
|
||||||
// Create the accessor function
|
// Create the accessor function
|
||||||
sq_newclosure(vm, func, 1);
|
sq_newclosure(vm, func, 1);
|
||||||
|
// Set the closure name (for debug purposes)
|
||||||
|
sq_setnativeclosurename(vm, -1, name);
|
||||||
|
|
||||||
// Add the accessor to the table
|
// Add the accessor to the table
|
||||||
sq_newslot(vm, -3, false);
|
sq_newslot(vm, -3, false);
|
||||||
@ -892,6 +908,8 @@ protected:
|
|||||||
// add the default constructor
|
// add the default constructor
|
||||||
sq_pushstring(vm, _SC("constructor"), -1);
|
sq_pushstring(vm, _SC("constructor"), -1);
|
||||||
sq_newclosure(vm, &A::New, 0);
|
sq_newclosure(vm, &A::New, 0);
|
||||||
|
// Set the closure name (for debug purposes)
|
||||||
|
sq_setnativeclosurename(vm, -1, _SC("constructor"));
|
||||||
sq_newslot(vm, -3, false);
|
sq_newslot(vm, -3, false);
|
||||||
|
|
||||||
// clone the base classes set table (static)
|
// clone the base classes set table (static)
|
||||||
@ -920,27 +938,37 @@ protected:
|
|||||||
sq_pushstring(vm, _SC("_set"), -1);
|
sq_pushstring(vm, _SC("_set"), -1);
|
||||||
sq_pushobject(vm, setTable); // Push the set table as a free variable
|
sq_pushobject(vm, setTable); // Push the set table as a free variable
|
||||||
sq_newclosure(vm, sqVarSet, 1);
|
sq_newclosure(vm, sqVarSet, 1);
|
||||||
|
// Set the closure name (for debug purposes)
|
||||||
|
sq_setnativeclosurename(vm, -1, _SC("_set"));
|
||||||
sq_newslot(vm, -3, false);
|
sq_newslot(vm, -3, false);
|
||||||
|
|
||||||
// override _get
|
// override _get
|
||||||
sq_pushstring(vm, _SC("_get"), -1);
|
sq_pushstring(vm, _SC("_get"), -1);
|
||||||
sq_pushobject(vm, getTable); // Push the get table as a free variable
|
sq_pushobject(vm, getTable); // Push the get table as a free variable
|
||||||
sq_newclosure(vm, sqVarGet, 1);
|
sq_newclosure(vm, sqVarGet, 1);
|
||||||
|
// Set the closure name (for debug purposes)
|
||||||
|
sq_setnativeclosurename(vm, -1, _SC("_get"));
|
||||||
sq_newslot(vm, -3, false);
|
sq_newslot(vm, -3, false);
|
||||||
|
|
||||||
// add weakref (apparently not provided by default)
|
// add weakref (apparently not provided by default)
|
||||||
sq_pushstring(vm, _SC("weakref"), -1);
|
sq_pushstring(vm, _SC("weakref"), -1);
|
||||||
sq_newclosure(vm, &Class<C, A>::ClassWeakref, 0);
|
sq_newclosure(vm, &Class<C, A>::ClassWeakref, 0);
|
||||||
|
// Set the closure name (for debug purposes)
|
||||||
|
sq_setnativeclosurename(vm, -1, _SC("weakref"));
|
||||||
sq_newslot(vm, -3, false);
|
sq_newslot(vm, -3, false);
|
||||||
|
|
||||||
// add _typeof
|
// add _typeof
|
||||||
sq_pushstring(vm, _SC("_typeof"), -1);
|
sq_pushstring(vm, _SC("_typeof"), -1);
|
||||||
sq_newclosure(vm, &Class<C, A>::ClassTypeof, 0);
|
sq_newclosure(vm, &Class<C, A>::ClassTypeof, 0);
|
||||||
|
// Set the closure name (for debug purposes)
|
||||||
|
sq_setnativeclosurename(vm, -1, _SC("_typeof"));
|
||||||
sq_newslot(vm, -3, false);
|
sq_newslot(vm, -3, false);
|
||||||
|
|
||||||
// add _cloned
|
// add _cloned
|
||||||
sq_pushstring(vm, _SC("_cloned"), -1);
|
sq_pushstring(vm, _SC("_cloned"), -1);
|
||||||
sq_newclosure(vm, &Class<C, A>::ClassCloned, 0);
|
sq_newclosure(vm, &Class<C, A>::ClassCloned, 0);
|
||||||
|
// Set the closure name (for debug purposes)
|
||||||
|
sq_setnativeclosurename(vm, -1, _SC("_cloned"));
|
||||||
sq_newslot(vm, -3, false);
|
sq_newslot(vm, -3, false);
|
||||||
|
|
||||||
// pop the class
|
// pop the class
|
||||||
|
@ -530,27 +530,39 @@ protected:
|
|||||||
|
|
||||||
// Bind a function and it's associated Squirrel closure to the object
|
// Bind a function and it's associated Squirrel closure to the object
|
||||||
inline void BindFunc(const SQChar* name, void* method, size_t methodSize, SQFUNCTION func, bool staticVar = false) {
|
inline void BindFunc(const SQChar* name, void* method, size_t methodSize, SQFUNCTION func, bool staticVar = false) {
|
||||||
|
// Push object/environment
|
||||||
sq_pushobject(vm, GetObject());
|
sq_pushobject(vm, GetObject());
|
||||||
|
// Push name where the closure will be stored
|
||||||
sq_pushstring(vm, name, -1);
|
sq_pushstring(vm, name, -1);
|
||||||
|
// Push the native closure pointer as a free variable
|
||||||
SQUserPointer methodPtr = sq_newuserdata(vm, static_cast<SQUnsignedInteger>(methodSize));
|
SQUserPointer methodPtr = sq_newuserdata(vm, static_cast<SQUnsignedInteger>(methodSize));
|
||||||
memcpy(methodPtr, method, methodSize);
|
memcpy(methodPtr, method, methodSize);
|
||||||
|
// Create the native closure
|
||||||
sq_newclosure(vm, func, 1);
|
sq_newclosure(vm, func, 1);
|
||||||
|
// Set the closure name (for debug purposes)
|
||||||
|
sq_setnativeclosurename(vm, -1, name);
|
||||||
|
// Include it into the object
|
||||||
sq_newslot(vm, -3, staticVar);
|
sq_newslot(vm, -3, staticVar);
|
||||||
sq_pop(vm,1); // pop table
|
// pop object/environment
|
||||||
|
sq_pop(vm,1);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void BindFunc(const SQInteger index, void* method, size_t methodSize, SQFUNCTION func, bool staticVar = false) {
|
inline void BindFunc(const SQInteger index, void* method, size_t methodSize, SQFUNCTION func, bool staticVar = false, const SQChar* name = nullptr) {
|
||||||
|
// Push object/environment
|
||||||
sq_pushobject(vm, GetObject());
|
sq_pushobject(vm, GetObject());
|
||||||
|
// Push index where the closure will be stored
|
||||||
sq_pushinteger(vm, index);
|
sq_pushinteger(vm, index);
|
||||||
|
// Push the native closure pointer as a free variable
|
||||||
SQUserPointer methodPtr = sq_newuserdata(vm, static_cast<SQUnsignedInteger>(methodSize));
|
SQUserPointer methodPtr = sq_newuserdata(vm, static_cast<SQUnsignedInteger>(methodSize));
|
||||||
memcpy(methodPtr, method, methodSize);
|
memcpy(methodPtr, method, methodSize);
|
||||||
|
// Create the native closure
|
||||||
sq_newclosure(vm, func, 1);
|
sq_newclosure(vm, func, 1);
|
||||||
|
// Set the closure name (for debug purposes)
|
||||||
|
if (name) sq_setnativeclosurename(vm, -1, name);
|
||||||
|
// Include it into the object
|
||||||
sq_newslot(vm, -3, staticVar);
|
sq_newslot(vm, -3, staticVar);
|
||||||
sq_pop(vm,1); // pop table
|
// pop object/environment
|
||||||
|
sq_pop(vm,1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -178,6 +178,8 @@ public:
|
|||||||
sq_pushobject(vm, GetObject());
|
sq_pushobject(vm, GetObject());
|
||||||
sq_pushstring(vm, name, -1);
|
sq_pushstring(vm, name, -1);
|
||||||
sq_newclosure(vm, func, 0);
|
sq_newclosure(vm, func, 0);
|
||||||
|
// Set the closure name (for debug purposes)
|
||||||
|
sq_setnativeclosurename(vm, -1, name);
|
||||||
sq_newslot(vm, -3, false);
|
sq_newslot(vm, -3, false);
|
||||||
sq_pop(vm,1); // pop table
|
sq_pop(vm,1); // pop table
|
||||||
return *this;
|
return *this;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user