Updated sqrat dependency

This commit is contained in:
Patrix
2022-07-11 06:14:33 +02:00
parent 71ce6652cc
commit 8d03f177c1
5 changed files with 56 additions and 36 deletions

View File

@@ -94,14 +94,17 @@ public:
/// ///
/// \param index The index in the array being assigned a function /// \param index The index in the array being assigned a function
/// \param func Squirrel function that is being placed in the Array /// \param func Squirrel function that is being placed in the Array
/// \param nparamscheck The parameters count used in runtime arguments count checking (including hidden this parameter)
/// \param type The type mask used in runtime parameters type checking
/// ///
/// \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, SQInteger nparamscheck = 0, const SQChar* typemask = 0) {
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);
sq_setparamscheck(vm, nparamscheck, typemask);
sq_set(vm, -3); sq_set(vm, -3);
sq_pop(vm,1); // pop array sq_pop(vm,1); // pop array
return *this; return *this;

View File

@@ -491,6 +491,8 @@ public:
/// ///
/// \param name Name of the function as it will appear in Squirrel /// \param name Name of the function as it will appear in Squirrel
/// \param func Function to bind /// \param func Function to bind
/// \param nparamscheck The parameters count used in runtime arguments count checking (including hidden this parameter)
/// \param type The type mask used in runtime parameters type checking
/// ///
/// \return The Class itself so the call can be chained /// \return The Class itself so the call can be chained
/// ///
@@ -499,10 +501,11 @@ public:
/// stack and all arguments will be after that index in the order they were given to the function. /// stack and all arguments will be after that index in the order they were given to the function.
/// ///
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Class& SquirrelFunc(const SQChar* name, SQFUNCTION func) { Class& SquirrelFunc(const SQChar* name, SQFUNCTION func, SQInteger nparamscheck = 0, const SQChar* typemask = 0) {
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);
sq_setparamscheck(vm, nparamscheck, typemask);
sq_newslot(vm, -3, false); sq_newslot(vm, -3, false);
sq_pop(vm, 1); // pop table sq_pop(vm, 1); // pop table

View File

@@ -161,7 +161,16 @@ public:
return 0; return 0;
} }
static void PushInstance(HSQUIRRELVM vm, C* ptr) { static SQInteger DeleteInstanceFree(SQUserPointer ptr, SQInteger size) {
SQUNUSED(size);
std::pair<C*, SharedPtr<typename unordered_map<C*, HSQOBJECT>::type> >* instance = reinterpret_cast<std::pair<C*, SharedPtr<typename unordered_map<C*, HSQOBJECT>::type> >*>(ptr);
instance->second->erase(instance->first);
delete instance->first;
delete instance;
return 0;
}
static void PushInstance(HSQUIRRELVM vm, C* ptr, bool free = false) {
if (!ptr) { if (!ptr) {
sq_pushnull(vm); sq_pushnull(vm);
return; return;
@@ -179,7 +188,7 @@ public:
sq_createinstance(vm, -1); sq_createinstance(vm, -1);
sq_remove(vm, -2); sq_remove(vm, -2);
sq_setinstanceup(vm, -1, new std::pair<C*, SharedPtr<typename unordered_map<C*, HSQOBJECT>::type> >(ptr, cd->instances)); sq_setinstanceup(vm, -1, new std::pair<C*, SharedPtr<typename unordered_map<C*, HSQOBJECT>::type> >(ptr, cd->instances));
sq_setreleasehook(vm, -1, &DeleteInstance); free ? sq_setreleasehook(vm, -1, &DeleteInstanceFree) : sq_setreleasehook(vm, -1, &DeleteInstance);
sq_getstackobj(vm, -1, &((*cd->instances)[ptr])); sq_getstackobj(vm, -1, &((*cd->instances)[ptr]));
} }

View File

@@ -36,6 +36,10 @@
#include "sqratOverloadMethods.h" #include "sqratOverloadMethods.h"
#include "sqratUtil.h" #include "sqratUtil.h"
#ifdef WIN32
// Windows defines fix
#undef GetObject
#endif
namespace Sqrat { namespace Sqrat {
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -99,10 +103,11 @@ public:
/// ///
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
template<class T> template<class T>
Object(T* instance, HSQUIRRELVM v = DefaultVM::Get()) : vm(v), release(true) { Object(T* instance, HSQUIRRELVM v = DefaultVM::Get(), bool free = false) : vm(v), release(true) {
ClassType<T>::PushInstance(vm, instance); ClassType<T>::PushInstance(vm, instance, free);
sq_getstackobj(vm, -1, &obj); sq_getstackobj(vm, -1, &obj);
sq_addref(vm, &obj); sq_addref(vm, &obj);
sq_pop(vm, 1);
} }
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

View File

@@ -84,7 +84,7 @@ struct popAsInt
case OT_FLOAT: case OT_FLOAT:
SQFloat sqValuef; SQFloat sqValuef;
sq_getfloat(vm, idx, &sqValuef); sq_getfloat(vm, idx, &sqValuef);
value = static_cast<T>(static_cast<int>(sqValuef)); value = static_cast<T>(static_cast<int>(sqValuef));
break; break;
default: default:
SQTHROW(vm, FormatTypeError(vm, idx, _SC("integer"))); SQTHROW(vm, FormatTypeError(vm, idx, _SC("integer")));
@@ -858,40 +858,40 @@ struct Var<const string&> {
template<> template<>
struct Var<SQUserPointer> { struct Var<SQUserPointer> {
SQUserPointer value; ///< The actual value of get operations SQUserPointer value; ///< The actual value of get operations
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Attempts to get the value off the stack at idx as a SQUserPointer /// Attempts to get the value off the stack at idx as a SQUserPointer
/// ///
/// \param vm Target VM /// \param vm Target VM
/// \param idx Index trying to be read /// \param idx Index trying to be read
/// ///
/// \remarks /// \remarks
/// This function MUST have its Error handled if it occurred. /// This function MUST have its Error handled if it occurred.
/// ///
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Var(HSQUIRRELVM vm, SQInteger idx) { Var(HSQUIRRELVM vm, SQInteger idx) {
SQUserPointer sqValue; SQUserPointer sqValue;
#if !defined (SCRAT_NO_ERROR_CHECKING) #if !defined (SCRAT_NO_ERROR_CHECKING)
if (SQ_FAILED(sq_getuserpointer(vm, idx, &sqValue))) { if (SQ_FAILED(sq_getuserpointer(vm, idx, &sqValue))) {
SQTHROW(vm, FormatTypeError(vm, idx, _SC("userpointer"))); SQTHROW(vm, FormatTypeError(vm, idx, _SC("userpointer")));
} }
#else #else
sq_getuserpointer(vm, idx, &sqValue); sq_getuserpointer(vm, idx, &sqValue);
#endif #endif
value = sqValue; value = sqValue;
} }
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Called by Sqrat::PushVar to put a SQUserPointer on the stack /// Called by Sqrat::PushVar to put a SQUserPointer on the stack
/// ///
/// \param vm Target VM /// \param vm Target VM
/// \param value Value to push on to the VM's stack /// \param value Value to push on to the VM's stack
/// ///
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
static void push(HSQUIRRELVM vm, const SQUserPointer value) { static void push(HSQUIRRELVM vm, const SQUserPointer value) {
sq_pushuserpointer(vm, value); sq_pushuserpointer(vm, value);
} }
}; };
#ifdef SQUNICODE #ifdef SQUNICODE