From 01c359e51cd2d7a192eb4dad5747fb1cea45d995 Mon Sep 17 00:00:00 2001 From: Patrix Date: Wed, 6 Jul 2022 22:12:13 +0200 Subject: [PATCH] Updated sqrat dependency --- dependencies/sqrat/include/sqrat.h | 1 + .../sqrat/include/sqrat/sqratBytecode.h | 174 ++++++++++++++++++ dependencies/sqrat/include/sqrat/sqratClass.h | 8 +- .../sqrat/include/sqrat/sqratClassType.h | 20 +- .../sqrat/include/sqrat/sqratFunction.h | 93 ++++++---- dependencies/sqrat/include/sqrat/sqratNull.h | 72 ++++++++ .../sqrat/include/sqrat/sqratObject.h | 61 ++++-- .../sqrat/include/sqrat/sqratScript.h | 53 ++++++ dependencies/sqrat/include/sqrat/sqratTable.h | 2 +- dependencies/sqrat/include/sqrat/sqratTypes.h | 118 ++++-------- dependencies/sqrat/include/sqrat/sqratUtil.h | 14 +- dependencies/sqrat/include/sqrat/sqratVM.h | 8 +- 12 files changed, 469 insertions(+), 155 deletions(-) create mode 100644 dependencies/sqrat/include/sqrat/sqratBytecode.h create mode 100644 dependencies/sqrat/include/sqrat/sqratNull.h diff --git a/dependencies/sqrat/include/sqrat.h b/dependencies/sqrat/include/sqrat.h index 81efc50..ee797ef 100644 --- a/dependencies/sqrat/include/sqrat.h +++ b/dependencies/sqrat/include/sqrat.h @@ -65,5 +65,6 @@ #include "sqrat/sqratUtil.h" #include "sqrat/sqratScript.h" #include "sqrat/sqratArray.h" +#include "sqrat/sqratNull.h" #endif diff --git a/dependencies/sqrat/include/sqrat/sqratBytecode.h b/dependencies/sqrat/include/sqrat/sqratBytecode.h new file mode 100644 index 0000000..d42fc00 --- /dev/null +++ b/dependencies/sqrat/include/sqrat/sqratBytecode.h @@ -0,0 +1,174 @@ +// +// SqratBytecode: Script bytecode saving and loading +// + +// +// Copyright (c) 2009 Brandon Jones +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// +// 3. This notice may not be removed or altered from any source +// distribution. +// + +#ifndef _SCRAT_BYTECODE_H_ +#define _SCRAT_BYTECODE_H_ + +#include +#include +#include + +namespace Sqrat { + +///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +/// Helper class for managing Squirrel scripts bytecode +///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +class Bytecode { +public: + + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + /// Default constructor + /// + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + Bytecode() + : m_data(0) + , m_size(0) + , m_readpos(0) + { + } + + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + /// Default destructor + /// + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + ~Bytecode() { + if (m_data) { + free(m_data); + } + } + + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + /// Returns pointer to bytecode + /// + /// \returns Pointer to bytecode data + /// + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + inline void * Data() const { + return m_data; + } + + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + /// Copies bytecode from provided buffer + /// + /// \param data Pointer to buffer containing bytecode + /// \param size Size of buffer containing bytecode + /// \returns SQ_OK on success, SQ_ERROR on failure + /// + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + SQRESULT SetData(const void * data, size_t size) { + if (m_data) { + free(m_data); + } + m_data = static_cast(malloc(size)); + memcpy(m_data, data, size); + m_size = size; + m_readpos = 0; + return SQ_OK; + } + + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + /// Appends bytecode from provided buffer + /// + /// \param data Pointer to buffer containing bytecode to append + /// \param size Size of buffer containing bytecode to append + /// \returns Number of bytes appended + /// + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + SQInteger AppendData(const void * data, size_t size) { + if (!m_data) { + m_data = static_cast(malloc(size)); + } + else { + m_data = static_cast(realloc(m_data, m_size + size)); + } + memcpy(m_data + m_size, data, size); + m_size += size; + return static_cast(size); + } + + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + /// Reads bytecode + /// + /// \param data Pointer to receiving buffer + /// \param size Number of bytes to read + /// \returns Number of read bytes or -1 if error occurs or there is no more data available + /// + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + SQInteger ReadData(void * data, size_t size) { + if (!m_data || m_size == 0 || m_readpos == m_size) + return -1; + size_t bytes_to_read = (m_readpos + size <= m_size) ? size : m_size - m_readpos; + memcpy(data, m_data + m_readpos, bytes_to_read); + m_readpos += bytes_to_read; + return static_cast(bytes_to_read); + } + + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + /// Returns bytecode size + /// + /// \returns Bytecode size in bytes + /// + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + inline size_t Size() const { + return m_size; + } + +private: + char * m_data; // Buffer holding bytecode + size_t m_size; // Bytecode size + size_t m_readpos; // Current bytecode ReadData() position +}; + +///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +/// Helper bytecode reader callback to use with sq_readclosure +/// +/// \param user_data Pointer to \a Bytecode object to read from +/// \param data Pointer to receiving buffer +/// \param size Number of bytes to read +/// +///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +SQInteger BytecodeReader(SQUserPointer user_data, SQUserPointer data, SQInteger size) { + Bytecode * bytecode = reinterpret_cast(user_data); + return bytecode->ReadData(data, static_cast(size));; +} + +///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +/// Helper bytecode writer callback to use with sq_writeclosure +/// +/// \param user_data Pointer to \a Bytecode object to write to +/// \param data Pointer to bytecode data +/// \param size Number of bytes to write +/// +///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +SQInteger BytecodeWriter(SQUserPointer user_data, SQUserPointer data, SQInteger size) { + Bytecode * bytecode = reinterpret_cast(user_data); + return bytecode->AppendData(data, static_cast(size)); +} + +} + +#endif //_SCRAT_BYTECODE_H_ diff --git a/dependencies/sqrat/include/sqrat/sqratClass.h b/dependencies/sqrat/include/sqrat/sqratClass.h index ca863e0..663c6f3 100644 --- a/dependencies/sqrat/include/sqrat/sqratClass.h +++ b/dependencies/sqrat/include/sqrat/sqratClass.h @@ -84,10 +84,10 @@ public: Class(HSQUIRRELVM v, const string& className, bool createClass = true) : Object(v, false) { if (createClass && !ClassType::hasClassData(v)) { sq_pushregistrytable(v); - sq_pushstring(v, "__classes", -1); + sq_pushstring(v, _SC("__classes"), -1); if (SQ_FAILED(sq_rawget(v, -2))) { sq_newtable(v); - sq_pushstring(v, "__classes", -1); + sq_pushstring(v, _SC("__classes"), -1); sq_push(v, -2); sq_rawset(v, -4); } @@ -932,10 +932,10 @@ public: DerivedClass(HSQUIRRELVM v, const string& className) : Class(v, string(), false) { if (!ClassType::hasClassData(v)) { sq_pushregistrytable(v); - sq_pushstring(v, "__classes", -1); + sq_pushstring(v, _SC("__classes"), -1); if (SQ_FAILED(sq_rawget(v, -2))) { sq_newtable(v); - sq_pushstring(v, "__classes", -1); + sq_pushstring(v, _SC("__classes"), -1); sq_push(v, -2); sq_rawset(v, -4); } diff --git a/dependencies/sqrat/include/sqrat/sqratClassType.h b/dependencies/sqrat/include/sqrat/sqratClassType.h index eefceb3..3beca6a 100644 --- a/dependencies/sqrat/include/sqrat/sqratClassType.h +++ b/dependencies/sqrat/include/sqrat/sqratClassType.h @@ -97,7 +97,7 @@ public: static inline ClassData* getClassData(HSQUIRRELVM vm) { sq_pushregistrytable(vm); - sq_pushstring(vm, "__classes", -1); + sq_pushstring(vm, _SC("__classes"), -1); #ifndef NDEBUG SQRESULT r = sq_rawget(vm, -2); assert(SQ_SUCCEEDED(r)); // fails if getClassData is called when the data does not exist for the given VM yet (bind the class) @@ -124,7 +124,7 @@ public: static inline bool hasClassData(HSQUIRRELVM vm) { if (!getStaticClassData().Expired()) { sq_pushregistrytable(vm); - sq_pushstring(vm, "__classes", -1); + sq_pushstring(vm, _SC("__classes"), -1); if (SQ_SUCCEEDED(sq_rawget(vm, -2))) { sq_pushstring(vm, ClassName().c_str(), -1); if (SQ_SUCCEEDED(sq_rawget(vm, -2))) { @@ -157,23 +157,11 @@ public: SQUNUSED(size); std::pair::type> >* instance = reinterpret_cast::type> >*>(ptr); instance->second->erase(instance->first); - delete instance; return 0; } - 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) { + static void PushInstance(HSQUIRRELVM vm, C* ptr) { if (!ptr) { sq_pushnull(vm); return; @@ -191,7 +179,7 @@ public: sq_createinstance(vm, -1); sq_remove(vm, -2); sq_setinstanceup(vm, -1, new std::pair::type> >(ptr, cd->instances)); - free ? sq_setreleasehook(vm, -1, &DeleteInstanceFree) : sq_setreleasehook(vm, -1, &DeleteInstance); + sq_setreleasehook(vm, -1, &DeleteInstance); sq_getstackobj(vm, -1, &((*cd->instances)[ptr])); } diff --git a/dependencies/sqrat/include/sqrat/sqratFunction.h b/dependencies/sqrat/include/sqrat/sqratFunction.h index 2c03a58..f2e69b6 100644 --- a/dependencies/sqrat/include/sqrat/sqratFunction.h +++ b/dependencies/sqrat/include/sqrat/sqratFunction.h @@ -139,7 +139,7 @@ public: /// \return True if the Function currently has a null value, otherwise false /// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - bool IsNull() { + bool IsNull() const { return sq_isnull(obj); } @@ -237,8 +237,8 @@ public: #if !defined (SCRAT_NO_ERROR_CHECKING) SQUnsignedInteger nparams; SQUnsignedInteger nfreevars; - - if (SQ_SUCCEEDED(sq_getclosureinfo(vm, -2, &nparams, &nfreevars)) && (nparams != 1)) { + if (obj._type != OT_NATIVECLOSURE && + SQ_SUCCEEDED(sq_getclosureinfo(vm, -2, &nparams, &nfreevars)) && (nparams != 1)) { sq_pop(vm, 2); SQTHROW(vm, _SC("wrong number of parameters")); return SharedPtr(); @@ -286,7 +286,8 @@ public: SQUnsignedInteger nparams; SQUnsignedInteger nfreevars; - if (SQ_SUCCEEDED(sq_getclosureinfo(vm, -2, &nparams, &nfreevars)) && (nparams != 2)) { + if (obj._type != OT_NATIVECLOSURE && + SQ_SUCCEEDED(sq_getclosureinfo(vm, -2, &nparams, &nfreevars)) && (nparams != 2)) { sq_pop(vm, 2); SQTHROW(vm, _SC("wrong number of parameters")); return SharedPtr(); @@ -340,7 +341,8 @@ public: SQUnsignedInteger nparams; SQUnsignedInteger nfreevars; - if (SQ_SUCCEEDED(sq_getclosureinfo(vm, -2, &nparams, &nfreevars)) && (nparams != 3)) { + if (obj._type != OT_NATIVECLOSURE && + SQ_SUCCEEDED(sq_getclosureinfo(vm, -2, &nparams, &nfreevars)) && (nparams != 3)) { sq_pop(vm, 2); SQTHROW(vm, _SC("wrong number of parameters")); return SharedPtr(); @@ -396,7 +398,8 @@ public: #if !defined (SCRAT_NO_ERROR_CHECKING) SQUnsignedInteger nparams; SQUnsignedInteger nfreevars; - if (SQ_SUCCEEDED(sq_getclosureinfo(vm, -2, &nparams, &nfreevars)) && (nparams != 4)) { + if (obj._type != OT_NATIVECLOSURE && + SQ_SUCCEEDED(sq_getclosureinfo(vm, -2, &nparams, &nfreevars)) && (nparams != 4)) { sq_pop(vm, 2); SQTHROW(vm, _SC("wrong number of parameters")); return SharedPtr(); @@ -455,7 +458,8 @@ public: #if !defined (SCRAT_NO_ERROR_CHECKING) SQUnsignedInteger nparams; SQUnsignedInteger nfreevars; - if (SQ_SUCCEEDED(sq_getclosureinfo(vm, -2, &nparams, &nfreevars)) && (nparams != 5)) { + if (obj._type != OT_NATIVECLOSURE && + SQ_SUCCEEDED(sq_getclosureinfo(vm, -2, &nparams, &nfreevars)) && (nparams != 5)) { sq_pop(vm, 2); SQTHROW(vm, _SC("wrong number of parameters")); return SharedPtr(); @@ -517,7 +521,8 @@ public: #if !defined (SCRAT_NO_ERROR_CHECKING) SQUnsignedInteger nparams; SQUnsignedInteger nfreevars; - if (SQ_SUCCEEDED(sq_getclosureinfo(vm, -2, &nparams, &nfreevars)) && (nparams != 6)) { + if (obj._type != OT_NATIVECLOSURE && + SQ_SUCCEEDED(sq_getclosureinfo(vm, -2, &nparams, &nfreevars)) && (nparams != 6)) { sq_pop(vm, 2); SQTHROW(vm, _SC("wrong number of parameters")); return SharedPtr(); @@ -583,7 +588,8 @@ public: SQUnsignedInteger nparams; SQUnsignedInteger nfreevars; - if (SQ_SUCCEEDED(sq_getclosureinfo(vm, -2, &nparams, &nfreevars)) && (nparams != 7)) { + if (obj._type != OT_NATIVECLOSURE && + SQ_SUCCEEDED(sq_getclosureinfo(vm, -2, &nparams, &nfreevars)) && (nparams != 7)) { sq_pop(vm, 2); SQTHROW(vm, _SC("wrong number of parameters")); return SharedPtr(); @@ -651,7 +657,8 @@ public: #if !defined (SCRAT_NO_ERROR_CHECKING) SQUnsignedInteger nparams; SQUnsignedInteger nfreevars; - if (SQ_SUCCEEDED(sq_getclosureinfo(vm, -2, &nparams, &nfreevars)) && (nparams != 8)) { + if (obj._type != OT_NATIVECLOSURE && + SQ_SUCCEEDED(sq_getclosureinfo(vm, -2, &nparams, &nfreevars)) && (nparams != 8)) { sq_pop(vm, 2); SQTHROW(vm, _SC("wrong number of parameters")); return SharedPtr(); @@ -722,7 +729,8 @@ public: #if !defined (SCRAT_NO_ERROR_CHECKING) SQUnsignedInteger nparams; SQUnsignedInteger nfreevars; - if (SQ_SUCCEEDED(sq_getclosureinfo(vm, -2, &nparams, &nfreevars)) && (nparams != 9)) { + if (obj._type != OT_NATIVECLOSURE && + SQ_SUCCEEDED(sq_getclosureinfo(vm, -2, &nparams, &nfreevars)) && (nparams != 9)) { sq_pop(vm, 2); SQTHROW(vm, _SC("wrong number of parameters")); return SharedPtr(); @@ -796,7 +804,8 @@ public: #if !defined (SCRAT_NO_ERROR_CHECKING) SQUnsignedInteger nparams; SQUnsignedInteger nfreevars; - if (SQ_SUCCEEDED(sq_getclosureinfo(vm, -2, &nparams, &nfreevars)) && (nparams != 10)) { + if (obj._type != OT_NATIVECLOSURE && + SQ_SUCCEEDED(sq_getclosureinfo(vm, -2, &nparams, &nfreevars)) && (nparams != 10)) { sq_pop(vm, 2); SQTHROW(vm, _SC("wrong number of parameters")); return SharedPtr(); @@ -873,7 +882,8 @@ public: #if !defined (SCRAT_NO_ERROR_CHECKING) SQUnsignedInteger nparams; SQUnsignedInteger nfreevars; - if (SQ_SUCCEEDED(sq_getclosureinfo(vm, -2, &nparams, &nfreevars)) && (nparams != 11)) { + if (obj._type != OT_NATIVECLOSURE && + SQ_SUCCEEDED(sq_getclosureinfo(vm, -2, &nparams, &nfreevars)) && (nparams != 11)) { sq_pop(vm, 2); SQTHROW(vm, _SC("wrong number of parameters")); return SharedPtr(); @@ -953,7 +963,8 @@ public: #if !defined (SCRAT_NO_ERROR_CHECKING) SQUnsignedInteger nparams; SQUnsignedInteger nfreevars; - if (SQ_SUCCEEDED(sq_getclosureinfo(vm, -2, &nparams, &nfreevars)) && (nparams != 12)) { + if (obj._type != OT_NATIVECLOSURE && + SQ_SUCCEEDED(sq_getclosureinfo(vm, -2, &nparams, &nfreevars)) && (nparams != 12)) { sq_pop(vm, 2); SQTHROW(vm, _SC("wrong number of parameters")); return SharedPtr(); @@ -1036,7 +1047,8 @@ public: #if !defined (SCRAT_NO_ERROR_CHECKING) SQUnsignedInteger nparams; SQUnsignedInteger nfreevars; - if (SQ_SUCCEEDED(sq_getclosureinfo(vm, -2, &nparams, &nfreevars)) && (nparams != 13)) { + if (obj._type != OT_NATIVECLOSURE && + SQ_SUCCEEDED(sq_getclosureinfo(vm, -2, &nparams, &nfreevars)) && (nparams != 13)) { sq_pop(vm, 2); SQTHROW(vm, _SC("wrong number of parameters")); return SharedPtr(); @@ -1122,7 +1134,8 @@ public: #if !defined (SCRAT_NO_ERROR_CHECKING) SQUnsignedInteger nparams; SQUnsignedInteger nfreevars; - if (SQ_SUCCEEDED(sq_getclosureinfo(vm, -2, &nparams, &nfreevars)) && (nparams != 14)) { + if (obj._type != OT_NATIVECLOSURE && + SQ_SUCCEEDED(sq_getclosureinfo(vm, -2, &nparams, &nfreevars)) && (nparams != 14)) { sq_pop(vm, 2); SQTHROW(vm, _SC("wrong number of parameters")); return SharedPtr(); @@ -1211,7 +1224,8 @@ public: #if !defined (SCRAT_NO_ERROR_CHECKING) SQUnsignedInteger nparams; SQUnsignedInteger nfreevars; - if (SQ_SUCCEEDED(sq_getclosureinfo(vm, -2, &nparams, &nfreevars)) && (nparams != 15)) { + if (obj._type != OT_NATIVECLOSURE && + SQ_SUCCEEDED(sq_getclosureinfo(vm, -2, &nparams, &nfreevars)) && (nparams != 15)) { sq_pop(vm, 2); SQTHROW(vm, _SC("wrong number of parameters")); return SharedPtr(); @@ -1267,7 +1281,8 @@ public: #if !defined (SCRAT_NO_ERROR_CHECKING) SQUnsignedInteger nparams; SQUnsignedInteger nfreevars; - if (SQ_SUCCEEDED(sq_getclosureinfo(vm, -2, &nparams, &nfreevars)) && (nparams != 1)) { + if (obj._type != OT_NATIVECLOSURE && + SQ_SUCCEEDED(sq_getclosureinfo(vm, -2, &nparams, &nfreevars)) && (nparams != 1)) { sq_pop(vm, 2); SQTHROW(vm, _SC("wrong number of parameters")); return; @@ -1308,7 +1323,8 @@ public: #if !defined (SCRAT_NO_ERROR_CHECKING) SQUnsignedInteger nparams; SQUnsignedInteger nfreevars; - if (SQ_SUCCEEDED(sq_getclosureinfo(vm, -2, &nparams, &nfreevars)) && (nparams != 2)) { + if (obj._type != OT_NATIVECLOSURE && + SQ_SUCCEEDED(sq_getclosureinfo(vm, -2, &nparams, &nfreevars)) && (nparams != 2)) { sq_pop(vm, 2); SQTHROW(vm, _SC("wrong number of parameters")); return; @@ -1355,7 +1371,8 @@ public: #if !defined (SCRAT_NO_ERROR_CHECKING) SQUnsignedInteger nparams; SQUnsignedInteger nfreevars; - if (SQ_SUCCEEDED(sq_getclosureinfo(vm, -2, &nparams, &nfreevars)) && (nparams != 3)) { + if (obj._type != OT_NATIVECLOSURE && + SQ_SUCCEEDED(sq_getclosureinfo(vm, -2, &nparams, &nfreevars)) && (nparams != 3)) { sq_pop(vm, 2); SQTHROW(vm, _SC("wrong number of parameters")); return; @@ -1405,7 +1422,8 @@ public: #if !defined (SCRAT_NO_ERROR_CHECKING) SQUnsignedInteger nparams; SQUnsignedInteger nfreevars; - if (SQ_SUCCEEDED(sq_getclosureinfo(vm, -2, &nparams, &nfreevars)) && (nparams != 4)) { + if (obj._type != OT_NATIVECLOSURE && + SQ_SUCCEEDED(sq_getclosureinfo(vm, -2, &nparams, &nfreevars)) && (nparams != 4)) { sq_pop(vm, 2); SQTHROW(vm, _SC("wrong number of parameters")); return; @@ -1458,7 +1476,8 @@ public: #if !defined (SCRAT_NO_ERROR_CHECKING) SQUnsignedInteger nparams; SQUnsignedInteger nfreevars; - if (SQ_SUCCEEDED(sq_getclosureinfo(vm, -2, &nparams, &nfreevars)) && (nparams != 5)) { + if (obj._type != OT_NATIVECLOSURE && + SQ_SUCCEEDED(sq_getclosureinfo(vm, -2, &nparams, &nfreevars)) && (nparams != 5)) { sq_pop(vm, 2); SQTHROW(vm, _SC("wrong number of parameters")); return; @@ -1514,7 +1533,8 @@ public: #if !defined (SCRAT_NO_ERROR_CHECKING) SQUnsignedInteger nparams; SQUnsignedInteger nfreevars; - if (SQ_SUCCEEDED(sq_getclosureinfo(vm, -2, &nparams, &nfreevars)) && (nparams != 6)) { + if (obj._type != OT_NATIVECLOSURE && + SQ_SUCCEEDED(sq_getclosureinfo(vm, -2, &nparams, &nfreevars)) && (nparams != 6)) { sq_pop(vm, 2); SQTHROW(vm, _SC("wrong number of parameters")); return; @@ -1573,7 +1593,8 @@ public: #if !defined (SCRAT_NO_ERROR_CHECKING) SQUnsignedInteger nparams; SQUnsignedInteger nfreevars; - if (SQ_SUCCEEDED(sq_getclosureinfo(vm, -2, &nparams, &nfreevars)) && (nparams != 7)) { + if (obj._type != OT_NATIVECLOSURE && + SQ_SUCCEEDED(sq_getclosureinfo(vm, -2, &nparams, &nfreevars)) && (nparams != 7)) { sq_pop(vm, 2); SQTHROW(vm, _SC("wrong number of parameters")); return; @@ -1635,7 +1656,8 @@ public: #if !defined (SCRAT_NO_ERROR_CHECKING) SQUnsignedInteger nparams; SQUnsignedInteger nfreevars; - if (SQ_SUCCEEDED(sq_getclosureinfo(vm, -2, &nparams, &nfreevars)) && (nparams != 8)) { + if (obj._type != OT_NATIVECLOSURE && + SQ_SUCCEEDED(sq_getclosureinfo(vm, -2, &nparams, &nfreevars)) && (nparams != 8)) { sq_pop(vm, 2); SQTHROW(vm, _SC("wrong number of parameters")); return; @@ -1700,7 +1722,8 @@ public: #if !defined (SCRAT_NO_ERROR_CHECKING) SQUnsignedInteger nparams; SQUnsignedInteger nfreevars; - if (SQ_SUCCEEDED(sq_getclosureinfo(vm, -2, &nparams, &nfreevars)) && (nparams != 9)) { + if (obj._type != OT_NATIVECLOSURE && + SQ_SUCCEEDED(sq_getclosureinfo(vm, -2, &nparams, &nfreevars)) && (nparams != 9)) { sq_pop(vm, 2); SQTHROW(vm, _SC("wrong number of parameters")); return; @@ -1768,7 +1791,8 @@ public: #if !defined (SCRAT_NO_ERROR_CHECKING) SQUnsignedInteger nparams; SQUnsignedInteger nfreevars; - if (SQ_SUCCEEDED(sq_getclosureinfo(vm, -2, &nparams, &nfreevars)) && (nparams != 10)) { + if (obj._type != OT_NATIVECLOSURE && + SQ_SUCCEEDED(sq_getclosureinfo(vm, -2, &nparams, &nfreevars)) && (nparams != 10)) { sq_pop(vm, 2); SQTHROW(vm, _SC("wrong number of parameters")); return; @@ -1839,7 +1863,8 @@ public: #if !defined (SCRAT_NO_ERROR_CHECKING) SQUnsignedInteger nparams; SQUnsignedInteger nfreevars; - if (SQ_SUCCEEDED(sq_getclosureinfo(vm, -2, &nparams, &nfreevars)) && (nparams != 11)) { + if (obj._type != OT_NATIVECLOSURE && + SQ_SUCCEEDED(sq_getclosureinfo(vm, -2, &nparams, &nfreevars)) && (nparams != 11)) { sq_pop(vm, 2); SQTHROW(vm, _SC("wrong number of parameters")); return; @@ -1913,7 +1938,8 @@ public: #if !defined (SCRAT_NO_ERROR_CHECKING) SQUnsignedInteger nparams; SQUnsignedInteger nfreevars; - if (SQ_SUCCEEDED(sq_getclosureinfo(vm, -2, &nparams, &nfreevars)) && (nparams != 12)) { + if (obj._type != OT_NATIVECLOSURE && + SQ_SUCCEEDED(sq_getclosureinfo(vm, -2, &nparams, &nfreevars)) && (nparams != 12)) { sq_pop(vm, 2); SQTHROW(vm, _SC("wrong number of parameters")); return; @@ -1991,7 +2017,8 @@ public: #if !defined (SCRAT_NO_ERROR_CHECKING) SQUnsignedInteger nparams; SQUnsignedInteger nfreevars; - if (SQ_SUCCEEDED(sq_getclosureinfo(vm, -2, &nparams, &nfreevars)) && (nparams != 13)) { + if (obj._type != OT_NATIVECLOSURE && + SQ_SUCCEEDED(sq_getclosureinfo(vm, -2, &nparams, &nfreevars)) && (nparams != 13)) { sq_pop(vm, 2); SQTHROW(vm, _SC("wrong number of parameters")); return; @@ -2071,7 +2098,8 @@ public: #if !defined (SCRAT_NO_ERROR_CHECKING) SQUnsignedInteger nparams; SQUnsignedInteger nfreevars; - if (SQ_SUCCEEDED(sq_getclosureinfo(vm, -2, &nparams, &nfreevars)) && (nparams != 14)) { + if (obj._type != OT_NATIVECLOSURE && + SQ_SUCCEEDED(sq_getclosureinfo(vm, -2, &nparams, &nfreevars)) && (nparams != 14)) { sq_pop(vm, 2); SQTHROW(vm, _SC("wrong number of parameters")); return; @@ -2154,7 +2182,8 @@ public: #if !defined (SCRAT_NO_ERROR_CHECKING) SQUnsignedInteger nparams; SQUnsignedInteger nfreevars; - if (SQ_SUCCEEDED(sq_getclosureinfo(vm, -2, &nparams, &nfreevars)) && (nparams != 15)) { + if (obj._type != OT_NATIVECLOSURE && + SQ_SUCCEEDED(sq_getclosureinfo(vm, -2, &nparams, &nfreevars)) && (nparams != 15)) { sq_pop(vm, 2); SQTHROW(vm, _SC("wrong number of parameters")); return; diff --git a/dependencies/sqrat/include/sqrat/sqratNull.h b/dependencies/sqrat/include/sqrat/sqratNull.h new file mode 100644 index 0000000..e3c4dd9 --- /dev/null +++ b/dependencies/sqrat/include/sqrat/sqratNull.h @@ -0,0 +1,72 @@ +// +// sqratNull: nullptr support +// + +// +// Copyright (c) 2009 Brandon Jones +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// +// 3. This notice may not be removed or altered from any source +// distribution. +// + +#if !defined(_SCRAT_NULL_H_) +#define _SCRAT_NULL_H_ + +#include // std::nullptr_t +#include "sqratTypes.h" + +namespace Sqrat { + template<> + struct Var { + + std::nullptr_t value; ///< The actual value of get operations + + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + /// Attempts to get the value off the stack at idx as an nullptr + /// + /// \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) { +#if !defined (SCRAT_NO_ERROR_CHECKING) + SQObjectType value_type = sq_gettype(vm, idx); + if (value_type != OT_NULL) { + SQTHROW(vm, FormatTypeError(vm, idx, _SC("null"))); + } +#endif + value = nullptr; + } + + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + /// Called by Sqrat::PushVar to put an nullptr on the stack + /// + /// \param vm Target VM + /// \param value Value to push on to the VM's stack + /// + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + static void push(HSQUIRRELVM vm, const std::nullptr_t value) { + sq_pushnull(vm); + } + }; +} +#endif \ No newline at end of file diff --git a/dependencies/sqrat/include/sqrat/sqratObject.h b/dependencies/sqrat/include/sqrat/sqratObject.h index 3938db4..cc7ed7a 100644 --- a/dependencies/sqrat/include/sqrat/sqratObject.h +++ b/dependencies/sqrat/include/sqrat/sqratObject.h @@ -36,11 +36,6 @@ #include "sqratOverloadMethods.h" #include "sqratUtil.h" -#ifdef WIN32 -// Windows defines fix -#undef GetObject -#endif - namespace Sqrat { ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -104,11 +99,10 @@ public: /// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// template - Object(T* instance, HSQUIRRELVM v = DefaultVM::Get(), bool free = false) : vm(v), release(true) { - ClassType::PushInstance(vm, instance, free); + Object(T* instance, HSQUIRRELVM v = DefaultVM::Get()) : vm(v), release(true) { + ClassType::PushInstance(vm, instance); sq_getstackobj(vm, -1, &obj); sq_addref(vm, &obj); - sq_pop(vm, 1); } ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -131,13 +125,14 @@ public: /// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// Object& operator=(const Object& so) { - if(release) { - Release(); + if( this != &so ) { + if(release) { + Release(); + } + vm = so.vm; + obj = so.obj; + sq_addref(vm, &GetObject()); } - vm = so.vm; - obj = so.obj; - release = so.release; - sq_addref(vm, &GetObject()); return *this; } @@ -282,6 +277,44 @@ public: #endif } + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + /// Checks if the object has a slot with a specified key + /// + /// \param key Name of the key + /// + /// \return True if the Object has a value associated with key, otherwise false + /// + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + bool HasKey(const SQChar* key) const { + sq_pushobject(vm, GetObject()); + sq_pushstring(vm, key, -1); + if (SQ_FAILED(sq_get(vm, -2))) { + sq_pop(vm, 1); + return false; + } + sq_pop(vm, 2); + return true; + } + + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + /// Checks if the object has a slot with a specified index + /// + /// \param index Index to check + /// + /// \return True if the Object has a value associated with index, otherwise false + /// + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + bool HasKey(SQInteger index) const { + sq_pushobject(vm, GetObject()); + sq_pushinteger(vm, index); + if (SQ_FAILED(sq_get(vm, -2))) { + sq_pop(vm, 1); + return false; + } + sq_pop(vm, 2); + return true; + } + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /// Casts the object to a certain C++ type /// diff --git a/dependencies/sqrat/include/sqrat/sqratScript.h b/dependencies/sqrat/include/sqrat/sqratScript.h index f0a3b00..af8a9ee 100644 --- a/dependencies/sqrat/include/sqrat/sqratScript.h +++ b/dependencies/sqrat/include/sqrat/sqratScript.h @@ -33,6 +33,7 @@ #include #include "sqratObject.h" +#include "sqratBytecode.h" namespace Sqrat { @@ -236,6 +237,58 @@ public: #endif sq_pop(vm, 1); // needed? } + + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + /// Saves script's bytecode to string + /// + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + std::string SaveBytecode() { + Bytecode bytecode; +#if !defined (SCRAT_NO_ERROR_CHECKING) + if (!sq_isnull(obj)) { + sq_pushobject(vm, obj); + if (SQ_FAILED(sq_writeclosure(vm, BytecodeWriter, &bytecode))) { + SQTHROW(vm, LastErrorString(vm)); + } + } +#else + sq_pushobject(vm, obj); + sq_writeclosure(vm, BytecodeWriter, &bytecode); +#endif + sq_pop(vm, 1); // needed? + return std::string(reinterpret_cast(bytecode.Data()), bytecode.Size()); + } + + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + /// Loads script's bytecode from string + /// + /// \param str String containing script's bytecode + /// + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + bool LoadBytecode(const std::string& str) { +#if !defined (SCRAT_NO_ERROR_CHECKING) + if (str.empty()) { + return false; + } +#endif + if(!sq_isnull(obj)) { + sq_release(vm, &obj); + sq_resetobject(&obj); + } + Bytecode bytecode; + bytecode.SetData(str.c_str(), str.size()); +#if !defined (SCRAT_NO_ERROR_CHECKING) + if (SQ_FAILED(sq_readclosure(vm, BytecodeReader, &bytecode))) { + return false; + } +#else + sq_readclosure(vm, BytecodeReader, &bytecode); +#endif + sq_getstackobj(vm,-1,&obj); + sq_addref(vm, &obj); + sq_pop(vm, 1); + return true; + } }; } diff --git a/dependencies/sqrat/include/sqrat/sqratTable.h b/dependencies/sqrat/include/sqrat/sqratTable.h index 3e35654..906221c 100644 --- a/dependencies/sqrat/include/sqrat/sqratTable.h +++ b/dependencies/sqrat/include/sqrat/sqratTable.h @@ -94,7 +94,7 @@ public: /// /// \param name The key in the table being assigned a function /// \param func Squirrel function that is being placed in the Table - /// \param nparamscheck The parameters count used in runtime arguments count checking (including hidden this parameter). + /// \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 Table itself so the call can be chained diff --git a/dependencies/sqrat/include/sqrat/sqratTypes.h b/dependencies/sqrat/include/sqrat/sqratTypes.h index 2efc145..fbb0d57 100644 --- a/dependencies/sqrat/include/sqrat/sqratTypes.h +++ b/dependencies/sqrat/include/sqrat/sqratTypes.h @@ -193,11 +193,11 @@ struct Var { /// \param value Value to push on to the VM's stack /// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - static void push(HSQUIRRELVM vm, const T& value) { + static void push(HSQUIRRELVM vm, const T& val) { if (ClassType::hasClassData(vm)) - ClassType::PushInstanceCopy(vm, value); + ClassType::PushInstanceCopy(vm, val); else /* try integral type */ - pushAsInt::YES>().push(vm, value); + pushAsInt::YES>().push(vm, val); } private: @@ -212,8 +212,8 @@ private: template struct pushAsInt { - void push(HSQUIRRELVM vm, const T2& value) { - sq_pushinteger(vm, static_cast(value)); + void push(HSQUIRRELVM vm, const T2& val) { + sq_pushinteger(vm, static_cast(val)); } }; }; @@ -268,8 +268,8 @@ private: template struct pushAsInt { - void push(HSQUIRRELVM vm, const T2& value) { - sq_pushinteger(vm, static_cast(value)); + void push(HSQUIRRELVM vm, const T2& val) { + sq_pushinteger(vm, static_cast(val)); } }; }; @@ -305,8 +305,8 @@ struct Var { /// \param value Value to push on to the VM's stack /// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - static void push(HSQUIRRELVM vm, T* value) { - ClassType::PushInstance(vm, value); + static void push(HSQUIRRELVM vm, T* val) { + ClassType::PushInstance(vm, val); } }; @@ -341,8 +341,8 @@ struct Var { /// \param value Value to push on to the VM's stack /// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - static void push(HSQUIRRELVM vm, T* const value) { - ClassType::PushInstance(vm, value); + static void push(HSQUIRRELVM vm, T* const val) { + ClassType::PushInstance(vm, val); } }; @@ -377,8 +377,8 @@ struct Var { /// \param value Value to push on to the VM's stack /// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - static void push(HSQUIRRELVM vm, const T& value) { - ClassType::PushInstanceCopy(vm, value); + static void push(HSQUIRRELVM vm, const T& val) { + ClassType::PushInstanceCopy(vm, val); } }; @@ -413,8 +413,8 @@ struct Var { /// \param value Value to push on to the VM's stack /// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - static void push(HSQUIRRELVM vm, const T* value) { - ClassType::PushInstance(vm, const_cast(value)); + static void push(HSQUIRRELVM vm, const T* val) { + ClassType::PushInstance(vm, const_cast(val)); } }; @@ -449,8 +449,8 @@ struct Var { /// \param value Value to push on to the VM's stack /// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - static void push(HSQUIRRELVM vm, const T* const value) { - ClassType::PushInstance(vm, const_cast(value)); + static void push(HSQUIRRELVM vm, const T* const val) { + ClassType::PushInstance(vm, const_cast(val)); } }; @@ -493,8 +493,8 @@ struct Var > { /// \param value Value to push on to the VM's stack /// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - static void push(HSQUIRRELVM vm, const SharedPtr& value) { - PushVarR(vm, *value); + static void push(HSQUIRRELVM vm, const SharedPtr& val) { + PushVarR(vm, *val); } }; @@ -595,8 +595,8 @@ struct Var { /// \param value Value to push on to the VM's stack /// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - static void push(HSQUIRRELVM vm, const bool& value) { - sq_pushbool(vm, static_cast(value)); + static void push(HSQUIRRELVM vm, const bool& val) { + sq_pushbool(vm, static_cast(val)); } }; @@ -628,8 +628,8 @@ struct Var { /// \param value Value to push on to the VM's stack /// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - static void push(HSQUIRRELVM vm, const bool& value) { - sq_pushbool(vm, static_cast(value)); + static void push(HSQUIRRELVM vm, const bool& val) { + sq_pushbool(vm, static_cast(val)); } }; @@ -682,8 +682,8 @@ public: /// \param len Length of the string (defaults to finding the length by searching for a terminating null-character) /// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - static void push(HSQUIRRELVM vm, const SQChar* value, SQInteger len = -1) { - sq_pushstring(vm, value, len); + static void push(HSQUIRRELVM vm, const SQChar* val, SQInteger len = -1) { + sq_pushstring(vm, val, len); } }; @@ -736,8 +736,8 @@ public: /// \param len Length of the string (defaults to finding the length by searching for a terminating null-character) /// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - static void push(HSQUIRRELVM vm, const SQChar* value, SQInteger len = -1) { - sq_pushstring(vm, value, len); + static void push(HSQUIRRELVM vm, const SQChar* val, SQInteger len = -1) { + sq_pushstring(vm, val, len); } }; @@ -771,8 +771,8 @@ struct Var { /// \param value Value to push on to the VM's stack /// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - static void push(HSQUIRRELVM vm, const string& value) { - sq_pushstring(vm, value.c_str(), value.size()); + static void push(HSQUIRRELVM vm, const string& val) { + sq_pushstring(vm, val.c_str(), val.size()); } }; @@ -806,51 +806,11 @@ struct Var { /// \param value Value to push on to the VM's stack /// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - static void push(HSQUIRRELVM vm, const string& value) { - sq_pushstring(vm, value.c_str(), value.size()); + static void push(HSQUIRRELVM vm, const string& val) { + sq_pushstring(vm, val.c_str(), val.size()); } }; -///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -/// Used to get and push SQUserPointer to and from the stack -///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -template<> -struct Var { - - SQUserPointer value; ///< The actual value of get operations - - ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - /// Attempts to get the value off the stack at idx as a bool - /// - /// \param vm Target VM - /// \param idx Index trying to be read - /// - ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - Var(HSQUIRRELVM vm, SQInteger idx) { - SQUserPointer sqValue; - if (sq_getuserpointer(vm, idx, &sqValue) == SQ_ERROR) - { - SQTHROW(vm, FormatTypeError(vm, idx, _SC("integer"))); - value = nullptr; - return; - } - - value = sqValue; - } - - ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - /// Called by Sqrat::PushVar to put a bool 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 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /// Used to get and push std::string to and from the stack when SQChar is not char (must define SQUNICODE) @@ -882,8 +842,8 @@ struct Var { /// \param value Value to push on to the VM's stack /// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - static void push(HSQUIRRELVM vm, const std::string& value) { - std::wstring s = string_to_wstring(value); + static void push(HSQUIRRELVM vm, const std::string& val) { + std::wstring s = string_to_wstring(val); sq_pushstring(vm, s.c_str(), s.size()); } }; @@ -918,8 +878,8 @@ struct Var { /// \param value Value to push on to the VM's stack /// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - static void push(HSQUIRRELVM vm, const std::string& value) { - std::wstring s = string_to_wstring(value); + static void push(HSQUIRRELVM vm, const std::string& val) { + std::wstring s = string_to_wstring(val); sq_pushstring(vm, s.c_str(), s.size()); } }; @@ -978,8 +938,8 @@ public: /// \param len Length of the string (defaults to finding the length by searching for a terminating null-character) /// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - static void push(HSQUIRRELVM vm, const char* value, SQInteger len = -1) { - sq_pushstring(vm, string_to_wstring(std::string(value)).c_str(), len); + static void push(HSQUIRRELVM vm, const char* val, SQInteger len = -1) { + sq_pushstring(vm, string_to_wstring(std::string(val)).c_str(), len); } }; @@ -1037,8 +997,8 @@ public: /// \param len Length of the string (defaults to finding the length by searching for a terminating null-character) /// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - static void push(HSQUIRRELVM vm, const char* value, SQInteger len = -1) { - sq_pushstring(vm, string_to_wstring(std::string(value)).c_str(), len); + static void push(HSQUIRRELVM vm, const char* val, SQInteger len = -1) { + sq_pushstring(vm, string_to_wstring(std::string(val)).c_str(), len); } }; #endif diff --git a/dependencies/sqrat/include/sqrat/sqratUtil.h b/dependencies/sqrat/include/sqrat/sqratUtil.h index 3a221c0..21ff183 100644 --- a/dependencies/sqrat/include/sqrat/sqratUtil.h +++ b/dependencies/sqrat/include/sqrat/sqratUtil.h @@ -257,7 +257,7 @@ public: ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// static void Clear(HSQUIRRELVM vm) { sq_pushregistrytable(vm); - sq_pushstring(vm, "__error", -1); + sq_pushstring(vm, _SC("__error"), -1); sq_rawdeleteslot(vm, -2, false); sq_pop(vm, 1); } @@ -272,18 +272,18 @@ public: ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// static string Message(HSQUIRRELVM vm) { sq_pushregistrytable(vm); - sq_pushstring(vm, "__error", -1); + sq_pushstring(vm, _SC("__error"), -1); if (SQ_SUCCEEDED(sq_rawget(vm, -2))) { string** ud; sq_getuserdata(vm, -1, (SQUserPointer*)&ud, NULL); sq_pop(vm, 1); string err = **ud; - sq_pushstring(vm, "__error", -1); + sq_pushstring(vm, _SC("__error"), -1); sq_rawdeleteslot(vm, -2, false); sq_pop(vm, 1); return err; } - sq_pushstring(vm, "__error", -1); + sq_pushstring(vm, _SC("__error"), -1); sq_rawdeleteslot(vm, -2, false); sq_pop(vm, 1); return string(_SC("an unknown error has occurred")); @@ -299,7 +299,7 @@ public: ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// static bool Occurred(HSQUIRRELVM vm) { sq_pushregistrytable(vm); - sq_pushstring(vm, "__error", -1); + sq_pushstring(vm, _SC("__error"), -1); if (SQ_SUCCEEDED(sq_rawget(vm, -2))) { sq_pop(vm, 2); return true; @@ -317,9 +317,9 @@ public: ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// static void Throw(HSQUIRRELVM vm, const string& err) { sq_pushregistrytable(vm); - sq_pushstring(vm, "__error", -1); + sq_pushstring(vm, _SC("__error"), -1); if (SQ_FAILED(sq_rawget(vm, -2))) { - sq_pushstring(vm, "__error", -1); + sq_pushstring(vm, _SC("__error"), -1); string** ud = reinterpret_cast(sq_newuserdata(vm, sizeof(string*))); *ud = new string(err); sq_setreleasehook(vm, -1, &error_cleanup_hook); diff --git a/dependencies/sqrat/include/sqrat/sqratVM.h b/dependencies/sqrat/include/sqrat/sqratVM.h index 4a47862..ec53a5b 100644 --- a/dependencies/sqrat/include/sqrat/sqratVM.h +++ b/dependencies/sqrat/include/sqrat/sqratVM.h @@ -121,8 +121,12 @@ private: SQInteger column) { SQChar buf[512]; - scsprintf(buf, _SC("%s:%d:%d: %s"), source, (int) line, (int) column, desc); - buf[sizeof(buf) - 1] = 0; + #ifdef _MSC_VER + scsprintf(buf, 512, _SC("%s:%d:%d: %s"), source, (int) line, (int) column, desc); + #else + scsprintf(buf, _SC("%s:%d:%d: %s"), source, (int) line, (int) column, desc); + #endif + buf[sizeof(buf)/sizeof(SQChar) - 1] = 0; s_getVM(v)->m_lastErrorMsg = buf; }