Updated sqrat dependency
This commit is contained in:
1
dependencies/sqrat/include/sqrat.h
vendored
1
dependencies/sqrat/include/sqrat.h
vendored
@@ -65,5 +65,6 @@
|
||||
#include "sqrat/sqratUtil.h"
|
||||
#include "sqrat/sqratScript.h"
|
||||
#include "sqrat/sqratArray.h"
|
||||
#include "sqrat/sqratNull.h"
|
||||
|
||||
#endif
|
||||
|
||||
174
dependencies/sqrat/include/sqrat/sqratBytecode.h
vendored
Normal file
174
dependencies/sqrat/include/sqrat/sqratBytecode.h
vendored
Normal file
@@ -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 <squirrel.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
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<char *>(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<char *>(malloc(size));
|
||||
}
|
||||
else {
|
||||
m_data = static_cast<char *>(realloc(m_data, m_size + size));
|
||||
}
|
||||
memcpy(m_data + m_size, data, size);
|
||||
m_size += size;
|
||||
return static_cast<SQInteger>(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<SQInteger>(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<Bytecode *>(user_data);
|
||||
return bytecode->ReadData(data, static_cast<size_t>(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<Bytecode *>(user_data);
|
||||
return bytecode->AppendData(data, static_cast<size_t>(size));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif //_SCRAT_BYTECODE_H_
|
||||
@@ -84,10 +84,10 @@ public:
|
||||
Class(HSQUIRRELVM v, const string& className, bool createClass = true) : Object(v, false) {
|
||||
if (createClass && !ClassType<C>::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<C, A>(v, string(), false) {
|
||||
if (!ClassType<C>::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);
|
||||
}
|
||||
|
||||
@@ -97,7 +97,7 @@ public:
|
||||
|
||||
static inline ClassData<C>* 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<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;
|
||||
return 0;
|
||||
}
|
||||
|
||||
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) {
|
||||
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<C*, SharedPtr<typename unordered_map<C*, HSQOBJECT>::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]));
|
||||
}
|
||||
|
||||
|
||||
93
dependencies/sqrat/include/sqrat/sqratFunction.h
vendored
93
dependencies/sqrat/include/sqrat/sqratFunction.h
vendored
@@ -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<R>();
|
||||
@@ -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<R>();
|
||||
@@ -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<R>();
|
||||
@@ -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<R>();
|
||||
@@ -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<R>();
|
||||
@@ -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<R>();
|
||||
@@ -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<R>();
|
||||
@@ -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<R>();
|
||||
@@ -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<R>();
|
||||
@@ -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<R>();
|
||||
@@ -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<R>();
|
||||
@@ -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<R>();
|
||||
@@ -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<R>();
|
||||
@@ -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<R>();
|
||||
@@ -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<R>();
|
||||
@@ -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;
|
||||
|
||||
72
dependencies/sqrat/include/sqrat/sqratNull.h
vendored
Normal file
72
dependencies/sqrat/include/sqrat/sqratNull.h
vendored
Normal file
@@ -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 <cstddef> // std::nullptr_t
|
||||
#include "sqratTypes.h"
|
||||
|
||||
namespace Sqrat {
|
||||
template<>
|
||||
struct Var<std::nullptr_t> {
|
||||
|
||||
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
|
||||
51
dependencies/sqrat/include/sqrat/sqratObject.h
vendored
51
dependencies/sqrat/include/sqrat/sqratObject.h
vendored
@@ -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<class T>
|
||||
Object(T* instance, HSQUIRRELVM v = DefaultVM::Get(), bool free = false) : vm(v), release(true) {
|
||||
ClassType<T>::PushInstance(vm, instance, free);
|
||||
Object(T* instance, HSQUIRRELVM v = DefaultVM::Get()) : vm(v), release(true) {
|
||||
ClassType<T>::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( this != &so ) {
|
||||
if(release) {
|
||||
Release();
|
||||
}
|
||||
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
|
||||
///
|
||||
|
||||
53
dependencies/sqrat/include/sqrat/sqratScript.h
vendored
53
dependencies/sqrat/include/sqrat/sqratScript.h
vendored
@@ -33,6 +33,7 @@
|
||||
#include <string.h>
|
||||
|
||||
#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<char*>(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;
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
118
dependencies/sqrat/include/sqrat/sqratTypes.h
vendored
118
dependencies/sqrat/include/sqrat/sqratTypes.h
vendored
@@ -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<T>::hasClassData(vm))
|
||||
ClassType<T>::PushInstanceCopy(vm, value);
|
||||
ClassType<T>::PushInstanceCopy(vm, val);
|
||||
else /* try integral type */
|
||||
pushAsInt<T, is_convertible<T, SQInteger>::YES>().push(vm, value);
|
||||
pushAsInt<T, is_convertible<T, SQInteger>::YES>().push(vm, val);
|
||||
}
|
||||
|
||||
private:
|
||||
@@ -212,8 +212,8 @@ private:
|
||||
|
||||
template <class T2>
|
||||
struct pushAsInt<T2, true> {
|
||||
void push(HSQUIRRELVM vm, const T2& value) {
|
||||
sq_pushinteger(vm, static_cast<SQInteger>(value));
|
||||
void push(HSQUIRRELVM vm, const T2& val) {
|
||||
sq_pushinteger(vm, static_cast<SQInteger>(val));
|
||||
}
|
||||
};
|
||||
};
|
||||
@@ -268,8 +268,8 @@ private:
|
||||
|
||||
template <class T2>
|
||||
struct pushAsInt<T2, true> {
|
||||
void push(HSQUIRRELVM vm, const T2& value) {
|
||||
sq_pushinteger(vm, static_cast<SQInteger>(value));
|
||||
void push(HSQUIRRELVM vm, const T2& val) {
|
||||
sq_pushinteger(vm, static_cast<SQInteger>(val));
|
||||
}
|
||||
};
|
||||
};
|
||||
@@ -305,8 +305,8 @@ struct Var<T*> {
|
||||
/// \param value Value to push on to the VM's stack
|
||||
///
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
static void push(HSQUIRRELVM vm, T* value) {
|
||||
ClassType<T>::PushInstance(vm, value);
|
||||
static void push(HSQUIRRELVM vm, T* val) {
|
||||
ClassType<T>::PushInstance(vm, val);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -341,8 +341,8 @@ struct Var<T* const> {
|
||||
/// \param value Value to push on to the VM's stack
|
||||
///
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
static void push(HSQUIRRELVM vm, T* const value) {
|
||||
ClassType<T>::PushInstance(vm, value);
|
||||
static void push(HSQUIRRELVM vm, T* const val) {
|
||||
ClassType<T>::PushInstance(vm, val);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -377,8 +377,8 @@ struct Var<const T&> {
|
||||
/// \param value Value to push on to the VM's stack
|
||||
///
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
static void push(HSQUIRRELVM vm, const T& value) {
|
||||
ClassType<T>::PushInstanceCopy(vm, value);
|
||||
static void push(HSQUIRRELVM vm, const T& val) {
|
||||
ClassType<T>::PushInstanceCopy(vm, val);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -413,8 +413,8 @@ struct Var<const T*> {
|
||||
/// \param value Value to push on to the VM's stack
|
||||
///
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
static void push(HSQUIRRELVM vm, const T* value) {
|
||||
ClassType<T>::PushInstance(vm, const_cast<T*>(value));
|
||||
static void push(HSQUIRRELVM vm, const T* val) {
|
||||
ClassType<T>::PushInstance(vm, const_cast<T*>(val));
|
||||
}
|
||||
};
|
||||
|
||||
@@ -449,8 +449,8 @@ struct Var<const T* const> {
|
||||
/// \param value Value to push on to the VM's stack
|
||||
///
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
static void push(HSQUIRRELVM vm, const T* const value) {
|
||||
ClassType<T>::PushInstance(vm, const_cast<T*>(value));
|
||||
static void push(HSQUIRRELVM vm, const T* const val) {
|
||||
ClassType<T>::PushInstance(vm, const_cast<T*>(val));
|
||||
}
|
||||
};
|
||||
|
||||
@@ -493,8 +493,8 @@ struct Var<SharedPtr<T> > {
|
||||
/// \param value Value to push on to the VM's stack
|
||||
///
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
static void push(HSQUIRRELVM vm, const SharedPtr<T>& value) {
|
||||
PushVarR(vm, *value);
|
||||
static void push(HSQUIRRELVM vm, const SharedPtr<T>& val) {
|
||||
PushVarR(vm, *val);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -595,8 +595,8 @@ struct Var<bool> {
|
||||
/// \param value Value to push on to the VM's stack
|
||||
///
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
static void push(HSQUIRRELVM vm, const bool& value) {
|
||||
sq_pushbool(vm, static_cast<SQBool>(value));
|
||||
static void push(HSQUIRRELVM vm, const bool& val) {
|
||||
sq_pushbool(vm, static_cast<SQBool>(val));
|
||||
}
|
||||
};
|
||||
|
||||
@@ -628,8 +628,8 @@ struct Var<const bool&> {
|
||||
/// \param value Value to push on to the VM's stack
|
||||
///
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
static void push(HSQUIRRELVM vm, const bool& value) {
|
||||
sq_pushbool(vm, static_cast<SQBool>(value));
|
||||
static void push(HSQUIRRELVM vm, const bool& val) {
|
||||
sq_pushbool(vm, static_cast<SQBool>(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<string> {
|
||||
/// \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<const string&> {
|
||||
/// \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> {
|
||||
|
||||
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<std::string> {
|
||||
/// \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<const std::string&> {
|
||||
/// \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
|
||||
|
||||
14
dependencies/sqrat/include/sqrat/sqratUtil.h
vendored
14
dependencies/sqrat/include/sqrat/sqratUtil.h
vendored
@@ -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<string**>(sq_newuserdata(vm, sizeof(string*)));
|
||||
*ud = new string(err);
|
||||
sq_setreleasehook(vm, -1, &error_cleanup_hook);
|
||||
|
||||
6
dependencies/sqrat/include/sqrat/sqratVM.h
vendored
6
dependencies/sqrat/include/sqrat/sqratVM.h
vendored
@@ -121,8 +121,12 @@ 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);
|
||||
buf[sizeof(buf) - 1] = 0;
|
||||
#endif
|
||||
buf[sizeof(buf)/sizeof(SQChar) - 1] = 0;
|
||||
s_getVM(v)->m_lastErrorMsg = buf;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user