diff --git a/dependencies/sqrat/include/sqrat/sqratArray.h b/dependencies/sqrat/include/sqrat/sqratArray.h index 1de05d1..5d08c39 100644 --- a/dependencies/sqrat/include/sqrat/sqratArray.h +++ b/dependencies/sqrat/include/sqrat/sqratArray.h @@ -94,14 +94,17 @@ public: /// /// \param index The index in the array being assigned a function /// \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 /// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - 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_pushinteger(vm, index); sq_newclosure(vm, func, 0); + sq_setparamscheck(vm, nparamscheck, typemask); sq_set(vm, -3); sq_pop(vm,1); // pop array return *this; diff --git a/dependencies/sqrat/include/sqrat/sqratClass.h b/dependencies/sqrat/include/sqrat/sqratClass.h index 663c6f3..c66fea5 100644 --- a/dependencies/sqrat/include/sqrat/sqratClass.h +++ b/dependencies/sqrat/include/sqrat/sqratClass.h @@ -491,6 +491,8 @@ public: /// /// \param name Name of the function as it will appear in Squirrel /// \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 /// @@ -499,10 +501,11 @@ public: /// 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::getClassData(vm)->classObj); sq_pushstring(vm, name, -1); sq_newclosure(vm, func, 0); + sq_setparamscheck(vm, nparamscheck, typemask); sq_newslot(vm, -3, false); sq_pop(vm, 1); // pop table diff --git a/dependencies/sqrat/include/sqrat/sqratClassType.h b/dependencies/sqrat/include/sqrat/sqratClassType.h index 3beca6a..28e7f2c 100644 --- a/dependencies/sqrat/include/sqrat/sqratClassType.h +++ b/dependencies/sqrat/include/sqrat/sqratClassType.h @@ -161,7 +161,16 @@ public: return 0; } - static void PushInstance(HSQUIRRELVM vm, C* ptr) { + static SQInteger DeleteInstanceFree(SQUserPointer ptr, SQInteger size) { + SQUNUSED(size); + std::pair::type> >* instance = reinterpret_cast::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) { sq_pushnull(vm); return; @@ -179,7 +188,7 @@ public: sq_createinstance(vm, -1); sq_remove(vm, -2); sq_setinstanceup(vm, -1, new std::pair::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])); } diff --git a/dependencies/sqrat/include/sqrat/sqratObject.h b/dependencies/sqrat/include/sqrat/sqratObject.h index cc7ed7a..bb8d03b 100644 --- a/dependencies/sqrat/include/sqrat/sqratObject.h +++ b/dependencies/sqrat/include/sqrat/sqratObject.h @@ -36,6 +36,10 @@ #include "sqratOverloadMethods.h" #include "sqratUtil.h" +#ifdef WIN32 +// Windows defines fix +#undef GetObject +#endif namespace Sqrat { ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -99,10 +103,11 @@ public: /// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// template - Object(T* instance, HSQUIRRELVM v = DefaultVM::Get()) : vm(v), release(true) { - ClassType::PushInstance(vm, instance); + Object(T* instance, HSQUIRRELVM v = DefaultVM::Get(), bool free = false) : vm(v), release(true) { + ClassType::PushInstance(vm, instance, free); sq_getstackobj(vm, -1, &obj); sq_addref(vm, &obj); + sq_pop(vm, 1); } ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/dependencies/sqrat/include/sqrat/sqratTypes.h b/dependencies/sqrat/include/sqrat/sqratTypes.h index e2fb54e..9b609f9 100644 --- a/dependencies/sqrat/include/sqrat/sqratTypes.h +++ b/dependencies/sqrat/include/sqrat/sqratTypes.h @@ -84,7 +84,7 @@ struct popAsInt case OT_FLOAT: SQFloat sqValuef; sq_getfloat(vm, idx, &sqValuef); - value = static_cast(static_cast(sqValuef)); + value = static_cast(static_cast(sqValuef)); break; default: SQTHROW(vm, FormatTypeError(vm, idx, _SC("integer"))); @@ -858,40 +858,40 @@ struct Var { template<> struct Var { - 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 - /// - /// \param vm Target VM - /// \param idx Index trying to be read - /// - /// \remarks - /// This function MUST have its Error handled if it occurred. - /// - ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - Var(HSQUIRRELVM vm, SQInteger idx) { - SQUserPointer sqValue; + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + /// Attempts to get the value off the stack at idx as a SQUserPointer + /// + /// \param vm Target VM + /// \param idx Index trying to be read + /// + /// \remarks + /// This function MUST have its Error handled if it occurred. + /// + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + Var(HSQUIRRELVM vm, SQInteger idx) { + SQUserPointer sqValue; #if !defined (SCRAT_NO_ERROR_CHECKING) - if (SQ_FAILED(sq_getuserpointer(vm, idx, &sqValue))) { - SQTHROW(vm, FormatTypeError(vm, idx, _SC("userpointer"))); - } + if (SQ_FAILED(sq_getuserpointer(vm, idx, &sqValue))) { + SQTHROW(vm, FormatTypeError(vm, idx, _SC("userpointer"))); + } #else - sq_getuserpointer(vm, idx, &sqValue); + sq_getuserpointer(vm, idx, &sqValue); #endif - value = sqValue; - } + value = sqValue; + } - ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - /// Called by Sqrat::PushVar to put a SQUserPointer on the stack - /// - /// \param vm Target VM - /// \param value Value to push on to the VM's stack - /// - ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - static void push(HSQUIRRELVM vm, const SQUserPointer value) { - sq_pushuserpointer(vm, value); - } + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + /// Called by Sqrat::PushVar to put a SQUserPointer on the stack + /// + /// \param vm Target VM + /// \param value Value to push on to the VM's stack + /// + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + static void push(HSQUIRRELVM vm, const SQUserPointer value) { + sq_pushuserpointer(vm, value); + } }; #ifdef SQUNICODE