diff --git a/dependencies/sqrat/include/sqrat/sqratBytecode.h b/dependencies/sqrat/include/sqrat/sqratBytecode.h deleted file mode 100644 index d42fc00..0000000 --- a/dependencies/sqrat/include/sqrat/sqratBytecode.h +++ /dev/null @@ -1,174 +0,0 @@ -// -// 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 663c6f3..ca863e0 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, _SC("__classes"), -1); + sq_pushstring(v, "__classes", -1); if (SQ_FAILED(sq_rawget(v, -2))) { sq_newtable(v); - sq_pushstring(v, _SC("__classes"), -1); + sq_pushstring(v, "__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, _SC("__classes"), -1); + sq_pushstring(v, "__classes", -1); if (SQ_FAILED(sq_rawget(v, -2))) { sq_newtable(v); - sq_pushstring(v, _SC("__classes"), -1); + sq_pushstring(v, "__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 3beca6a..eefceb3 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, _SC("__classes"), -1); + sq_pushstring(vm, "__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, _SC("__classes"), -1); + sq_pushstring(vm, "__classes", -1); if (SQ_SUCCEEDED(sq_rawget(vm, -2))) { sq_pushstring(vm, ClassName().c_str(), -1); if (SQ_SUCCEEDED(sq_rawget(vm, -2))) { @@ -157,11 +157,23 @@ public: SQUNUSED(size); std::pair::type> >* instance = reinterpret_cast::type> >*>(ptr); instance->second->erase(instance->first); + delete instance; 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 +191,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/sqratFunction.h b/dependencies/sqrat/include/sqrat/sqratFunction.h index ed7e634..2c03a58 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() const { + bool IsNull() { return sq_isnull(obj); } diff --git a/dependencies/sqrat/include/sqrat/sqratObject.h b/dependencies/sqrat/include/sqrat/sqratObject.h index 15a1ffd..3938db4 100644 --- a/dependencies/sqrat/include/sqrat/sqratObject.h +++ b/dependencies/sqrat/include/sqrat/sqratObject.h @@ -36,6 +36,11 @@ #include "sqratOverloadMethods.h" #include "sqratUtil.h" +#ifdef WIN32 +// Windows defines fix +#undef GetObject +#endif + namespace Sqrat { ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -99,10 +104,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); } ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -276,44 +282,6 @@ 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 af8a9ee..f0a3b00 100644 --- a/dependencies/sqrat/include/sqrat/sqratScript.h +++ b/dependencies/sqrat/include/sqrat/sqratScript.h @@ -33,7 +33,6 @@ #include #include "sqratObject.h" -#include "sqratBytecode.h" namespace Sqrat { @@ -237,58 +236,6 @@ 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/sqratTypes.h b/dependencies/sqrat/include/sqrat/sqratTypes.h index fbb0d57..2efc145 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& val) { + static void push(HSQUIRRELVM vm, const T& value) { if (ClassType::hasClassData(vm)) - ClassType::PushInstanceCopy(vm, val); + ClassType::PushInstanceCopy(vm, value); else /* try integral type */ - pushAsInt::YES>().push(vm, val); + pushAsInt::YES>().push(vm, value); } private: @@ -212,8 +212,8 @@ private: template struct pushAsInt { - void push(HSQUIRRELVM vm, const T2& val) { - sq_pushinteger(vm, static_cast(val)); + void push(HSQUIRRELVM vm, const T2& value) { + sq_pushinteger(vm, static_cast(value)); } }; }; @@ -268,8 +268,8 @@ private: template struct pushAsInt { - void push(HSQUIRRELVM vm, const T2& val) { - sq_pushinteger(vm, static_cast(val)); + void push(HSQUIRRELVM vm, const T2& value) { + sq_pushinteger(vm, static_cast(value)); } }; }; @@ -305,8 +305,8 @@ struct Var { /// \param value Value to push on to the VM's stack /// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - static void push(HSQUIRRELVM vm, T* val) { - ClassType::PushInstance(vm, val); + static void push(HSQUIRRELVM vm, T* value) { + ClassType::PushInstance(vm, value); } }; @@ -341,8 +341,8 @@ struct Var { /// \param value Value to push on to the VM's stack /// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - static void push(HSQUIRRELVM vm, T* const val) { - ClassType::PushInstance(vm, val); + static void push(HSQUIRRELVM vm, T* const value) { + ClassType::PushInstance(vm, value); } }; @@ -377,8 +377,8 @@ struct Var { /// \param value Value to push on to the VM's stack /// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - static void push(HSQUIRRELVM vm, const T& val) { - ClassType::PushInstanceCopy(vm, val); + static void push(HSQUIRRELVM vm, const T& value) { + ClassType::PushInstanceCopy(vm, value); } }; @@ -413,8 +413,8 @@ struct Var { /// \param value Value to push on to the VM's stack /// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - static void push(HSQUIRRELVM vm, const T* val) { - ClassType::PushInstance(vm, const_cast(val)); + static void push(HSQUIRRELVM vm, const T* value) { + ClassType::PushInstance(vm, const_cast(value)); } }; @@ -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 val) { - ClassType::PushInstance(vm, const_cast(val)); + static void push(HSQUIRRELVM vm, const T* const value) { + ClassType::PushInstance(vm, const_cast(value)); } }; @@ -493,8 +493,8 @@ struct Var > { /// \param value Value to push on to the VM's stack /// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - static void push(HSQUIRRELVM vm, const SharedPtr& val) { - PushVarR(vm, *val); + static void push(HSQUIRRELVM vm, const SharedPtr& value) { + PushVarR(vm, *value); } }; @@ -595,8 +595,8 @@ struct Var { /// \param value Value to push on to the VM's stack /// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - static void push(HSQUIRRELVM vm, const bool& val) { - sq_pushbool(vm, static_cast(val)); + static void push(HSQUIRRELVM vm, const bool& value) { + sq_pushbool(vm, static_cast(value)); } }; @@ -628,8 +628,8 @@ struct Var { /// \param value Value to push on to the VM's stack /// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - static void push(HSQUIRRELVM vm, const bool& val) { - sq_pushbool(vm, static_cast(val)); + static void push(HSQUIRRELVM vm, const bool& value) { + sq_pushbool(vm, static_cast(value)); } }; @@ -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* val, SQInteger len = -1) { - sq_pushstring(vm, val, len); + static void push(HSQUIRRELVM vm, const SQChar* value, SQInteger len = -1) { + sq_pushstring(vm, value, 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* val, SQInteger len = -1) { - sq_pushstring(vm, val, len); + static void push(HSQUIRRELVM vm, const SQChar* value, SQInteger len = -1) { + sq_pushstring(vm, value, 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& val) { - sq_pushstring(vm, val.c_str(), val.size()); + static void push(HSQUIRRELVM vm, const string& value) { + sq_pushstring(vm, value.c_str(), value.size()); } }; @@ -806,11 +806,51 @@ struct Var { /// \param value Value to push on to the VM's stack /// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - static void push(HSQUIRRELVM vm, const string& val) { - sq_pushstring(vm, val.c_str(), val.size()); + static void push(HSQUIRRELVM vm, const string& value) { + sq_pushstring(vm, value.c_str(), value.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) @@ -842,8 +882,8 @@ struct Var { /// \param value Value to push on to the VM's stack /// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - static void push(HSQUIRRELVM vm, const std::string& val) { - std::wstring s = string_to_wstring(val); + static void push(HSQUIRRELVM vm, const std::string& value) { + std::wstring s = string_to_wstring(value); sq_pushstring(vm, s.c_str(), s.size()); } }; @@ -878,8 +918,8 @@ struct Var { /// \param value Value to push on to the VM's stack /// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - static void push(HSQUIRRELVM vm, const std::string& val) { - std::wstring s = string_to_wstring(val); + static void push(HSQUIRRELVM vm, const std::string& value) { + std::wstring s = string_to_wstring(value); sq_pushstring(vm, s.c_str(), s.size()); } }; @@ -938,8 +978,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* val, SQInteger len = -1) { - sq_pushstring(vm, string_to_wstring(std::string(val)).c_str(), len); + static void push(HSQUIRRELVM vm, const char* value, SQInteger len = -1) { + sq_pushstring(vm, string_to_wstring(std::string(value)).c_str(), len); } }; @@ -997,8 +1037,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* val, SQInteger len = -1) { - sq_pushstring(vm, string_to_wstring(std::string(val)).c_str(), len); + static void push(HSQUIRRELVM vm, const char* value, SQInteger len = -1) { + sq_pushstring(vm, string_to_wstring(std::string(value)).c_str(), len); } }; #endif diff --git a/dependencies/sqrat/include/sqrat/sqratUtil.h b/dependencies/sqrat/include/sqrat/sqratUtil.h index 21ff183..3a221c0 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, _SC("__error"), -1); + sq_pushstring(vm, "__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, _SC("__error"), -1); + sq_pushstring(vm, "__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, _SC("__error"), -1); + sq_pushstring(vm, "__error", -1); sq_rawdeleteslot(vm, -2, false); sq_pop(vm, 1); return err; } - sq_pushstring(vm, _SC("__error"), -1); + sq_pushstring(vm, "__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, _SC("__error"), -1); + sq_pushstring(vm, "__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, _SC("__error"), -1); + sq_pushstring(vm, "__error", -1); if (SQ_FAILED(sq_rawget(vm, -2))) { - sq_pushstring(vm, _SC("__error"), -1); + sq_pushstring(vm, "__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 ec53a5b..4a47862 100644 --- a/dependencies/sqrat/include/sqrat/sqratVM.h +++ b/dependencies/sqrat/include/sqrat/sqratVM.h @@ -121,12 +121,8 @@ private: SQInteger column) { SQChar buf[512]; - #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; + scsprintf(buf, _SC("%s:%d:%d: %s"), source, (int) line, (int) column, desc); + buf[sizeof(buf) - 1] = 0; s_getVM(v)->m_lastErrorMsg = buf; }