diff --git a/.gitmodules b/.gitmodules
new file mode 100644
index 0000000..7c4aa63
--- /dev/null
+++ b/.gitmodules
@@ -0,0 +1,3 @@
+[submodule "dependencies/sqapi"]
+ path = dependencies/sqapi
+ url = https://gitlab.com/GothicMultiplayerTeam/dependencies/sqapi.git
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 7d962b4..ad70c4d 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -2,11 +2,6 @@ cmake_minimum_required(VERSION 3.17)
project(squirrel-template)
-option(INSTALL_AFTER_BUILD "Run cmake --install separately for every target after each build. By default this option is set to OFF" OFF)
-
-set(GAME_PATH "" CACHE PATH "This option specifies the game location. It's only used for the installation step.")
-set(SERVER_PATH "" CACHE PATH "This option specifies the server location. It's only used for the installation step.")
-
file(GLOB SRC
"src/api/squirrel_api.h"
@@ -23,12 +18,6 @@ target_compile_definitions(squirrel-template
SCRAT_EXPORT
)
-target_precompile_headers(squirrel-template
- PRIVATE
- "src/api/module_api.h"
- "src/api/squirrel_api.h"
-)
-
target_include_directories(squirrel-template
INTERFACE
"include/"
@@ -44,34 +33,4 @@ if(DEFINED OUT_FILE_SUFFIX)
PREFIX ""
SUFFIX ".${OUT_FILE_SUFFIX}${CMAKE_SHARED_LIBRARY_SUFFIX}"
)
-endif()
-
-if (NOT ${GAME_PATH} STREQUAL "")
- install(TARGETS squirrel-template
- RUNTIME
- DESTINATION ${GAME_PATH}
- COMPONENT "clientModule"
- )
-
- if(INSTALL_AFTER_BUILD)
- add_custom_command(TARGET squirrel-template
- POST_BUILD
- COMMAND ${CMAKE_COMMAND} --install ${CMAKE_CURRENT_BINARY_DIR} --component "clientModule"
- )
- endif()
-endif()
-
-if (NOT ${SERVER_PATH} STREQUAL "")
- install(TARGETS squirrel-template
- RUNTIME
- DESTINATION ${SERVER_PATH}
- COMPONENT "serverModule"
- )
-
- if(INSTALL_AFTER_BUILD)
- add_custom_command(TARGET squirrel-template
- POST_BUILD
- COMMAND ${CMAKE_COMMAND} --install ${CMAKE_CURRENT_BINARY_DIR} --component "serverModule"
- )
- endif()
-endif()
+endif()
\ No newline at end of file
diff --git a/dependencies/CMakeLists.txt b/dependencies/CMakeLists.txt
index cc8375a..94f5c9b 100644
--- a/dependencies/CMakeLists.txt
+++ b/dependencies/CMakeLists.txt
@@ -1,5 +1,3 @@
-add_subdirectory(squirrel)
-add_subdirectory(sqrat)
+add_subdirectory(sqapi)
-target_link_libraries(squirrel-template PUBLIC Squirrel)
-target_link_libraries(squirrel-template PUBLIC SqRat)
\ No newline at end of file
+target_link_libraries(squirrel-template PUBLIC sqapi)
\ No newline at end of file
diff --git a/dependencies/sqapi b/dependencies/sqapi
new file mode 160000
index 0000000..af0918c
--- /dev/null
+++ b/dependencies/sqapi
@@ -0,0 +1 @@
+Subproject commit af0918cc4043ec5426f3a3a60b88b830a32632f0
diff --git a/dependencies/sqrat/CMakeLists.txt b/dependencies/sqrat/CMakeLists.txt
deleted file mode 100644
index eeb4fe6..0000000
--- a/dependencies/sqrat/CMakeLists.txt
+++ /dev/null
@@ -1,15 +0,0 @@
-cmake_minimum_required(VERSION 3.17)
-
-project(SqRat)
-
-file(GLOB_RECURSE SRC
- "include/*.h"
-)
-
-add_library(SqRat INTERFACE)
-target_sources(SqRat INTERFACE ${SRC})
-
-target_include_directories(SqRat
- INTERFACE
- "include/"
-)
\ No newline at end of file
diff --git a/dependencies/sqrat/include/sqmodule.h b/dependencies/sqrat/include/sqmodule.h
deleted file mode 100644
index 696df61..0000000
--- a/dependencies/sqrat/include/sqmodule.h
+++ /dev/null
@@ -1,243 +0,0 @@
-//
-// SqModule: API used to communicate with and register squirrel modules
-//
-
-//
-// 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(_SQ_MODULE_H_)
-#define _SQ_MODULE_H_
-
-#include "squirrel.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- /// @cond DEV
- /// Allows modules to interface with Squirrel's C api without linking to the squirrel library
- /// If new functions are added to the Squirrel API, they should be added here too
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- typedef struct {
- /*vm*/
- HSQUIRRELVM (*open)(SQInteger initialstacksize);
- HSQUIRRELVM (*newthread)(HSQUIRRELVM friendvm, SQInteger initialstacksize);
- void (*seterrorhandler)(HSQUIRRELVM v);
- void (*close)(HSQUIRRELVM v);
- void (*setforeignptr)(HSQUIRRELVM v,SQUserPointer p);
- SQUserPointer (*getforeignptr)(HSQUIRRELVM v);
-#if SQUIRREL_VERSION_NUMBER >= 300
- void (*setprintfunc)(HSQUIRRELVM v, SQPRINTFUNCTION printfunc, SQPRINTFUNCTION);
-#else
- void (*setprintfunc)(HSQUIRRELVM v, SQPRINTFUNCTION printfunc);
-#endif
- SQPRINTFUNCTION (*getprintfunc)(HSQUIRRELVM v);
- SQRESULT (*suspendvm)(HSQUIRRELVM v);
- SQRESULT (*wakeupvm)(HSQUIRRELVM v,SQBool resumedret,SQBool retval,SQBool raiseerror,SQBool throwerror);
- SQInteger (*getvmstate)(HSQUIRRELVM v);
-
- /*compiler*/
- SQRESULT (*compile)(HSQUIRRELVM v,SQLEXREADFUNC read,SQUserPointer p,const SQChar *sourcename,SQBool raiseerror);
- SQRESULT (*compilebuffer)(HSQUIRRELVM v,const SQChar *s,SQInteger size,const SQChar *sourcename,SQBool raiseerror);
- void (*enabledebuginfo)(HSQUIRRELVM v, SQBool enable);
- void (*notifyallexceptions)(HSQUIRRELVM v, SQBool enable);
- void (*setcompilererrorhandler)(HSQUIRRELVM v,SQCOMPILERERROR f);
-
- /*stack operations*/
- void (*push)(HSQUIRRELVM v,SQInteger idx);
- void (*pop)(HSQUIRRELVM v,SQInteger nelemstopop);
- void (*poptop)(HSQUIRRELVM v);
- void (*remove)(HSQUIRRELVM v,SQInteger idx);
- SQInteger (*gettop)(HSQUIRRELVM v);
- void (*settop)(HSQUIRRELVM v,SQInteger newtop);
-#if SQUIRREL_VERSION_NUMBER >= 300
- SQRESULT (*reservestack)(HSQUIRRELVM v,SQInteger nsize);
-#else
- void (*reservestack)(HSQUIRRELVM v,SQInteger nsize);
-#endif
- SQInteger (*cmp)(HSQUIRRELVM v);
- void (*move)(HSQUIRRELVM dest,HSQUIRRELVM src,SQInteger idx);
-
- /*object creation handling*/
- SQUserPointer (*newuserdata)(HSQUIRRELVM v,SQUnsignedInteger size);
- void (*newtable)(HSQUIRRELVM v);
- void (*newarray)(HSQUIRRELVM v,SQInteger size);
- void (*newclosure)(HSQUIRRELVM v,SQFUNCTION func,SQUnsignedInteger nfreevars);
- SQRESULT (*setparamscheck)(HSQUIRRELVM v,SQInteger nparamscheck,const SQChar *typemask);
- SQRESULT (*bindenv)(HSQUIRRELVM v,SQInteger idx);
- void (*pushstring)(HSQUIRRELVM v,const SQChar *s,SQInteger len);
- void (*pushfloat)(HSQUIRRELVM v,SQFloat f);
- void (*pushinteger)(HSQUIRRELVM v,SQInteger n);
- void (*pushbool)(HSQUIRRELVM v,SQBool b);
- void (*pushuserpointer)(HSQUIRRELVM v,SQUserPointer p);
- void (*pushnull)(HSQUIRRELVM v);
- SQObjectType (*gettype)(HSQUIRRELVM v,SQInteger idx);
- SQInteger (*getsize)(HSQUIRRELVM v,SQInteger idx);
- SQRESULT (*getbase)(HSQUIRRELVM v,SQInteger idx);
- SQBool (*instanceof)(HSQUIRRELVM v);
-#if SQUIRREL_VERSION_NUMBER >= 300
- SQRESULT (*tostring)(HSQUIRRELVM v,SQInteger idx);
-#else
- void (*tostring)(HSQUIRRELVM v,SQInteger idx);
-#endif
- void (*tobool)(HSQUIRRELVM v, SQInteger idx, SQBool *b);
- SQRESULT (*getstring)(HSQUIRRELVM v,SQInteger idx,const SQChar **c);
- SQRESULT (*getinteger)(HSQUIRRELVM v,SQInteger idx,SQInteger *i);
- SQRESULT (*getfloat)(HSQUIRRELVM v,SQInteger idx,SQFloat *f);
- SQRESULT (*getbool)(HSQUIRRELVM v,SQInteger idx,SQBool *b);
- SQRESULT (*getthread)(HSQUIRRELVM v,SQInteger idx,HSQUIRRELVM *thread);
- SQRESULT (*getuserpointer)(HSQUIRRELVM v,SQInteger idx,SQUserPointer *p);
- SQRESULT (*getuserdata)(HSQUIRRELVM v,SQInteger idx,SQUserPointer *p,SQUserPointer *typetag);
- SQRESULT (*settypetag)(HSQUIRRELVM v,SQInteger idx,SQUserPointer typetag);
- SQRESULT (*gettypetag)(HSQUIRRELVM v,SQInteger idx,SQUserPointer *typetag);
- void (*setreleasehook)(HSQUIRRELVM v,SQInteger idx,SQRELEASEHOOK hook);
- SQChar* (*getscratchpad)(HSQUIRRELVM v,SQInteger minsize);
- SQRESULT (*getclosureinfo)(HSQUIRRELVM v,SQInteger idx,SQInteger *nparams,SQInteger *nfreevars);
- SQRESULT (*setnativeclosurename)(HSQUIRRELVM v,SQInteger idx,const SQChar *name);
- SQRESULT (*setinstanceup)(HSQUIRRELVM v, SQInteger idx, SQUserPointer p);
- SQRESULT (*getinstanceup)(HSQUIRRELVM v, SQInteger idx, SQUserPointer *p,SQUserPointer typetag, SQBool throwerror);
- SQRESULT (*setclassudsize)(HSQUIRRELVM v, SQInteger idx, SQInteger udsize);
- SQRESULT (*newclass)(HSQUIRRELVM v,SQBool hasbase);
- SQRESULT (*createinstance)(HSQUIRRELVM v,SQInteger idx);
- SQRESULT (*setattributes)(HSQUIRRELVM v,SQInteger idx);
- SQRESULT (*getattributes)(HSQUIRRELVM v,SQInteger idx);
- SQRESULT (*getclass)(HSQUIRRELVM v,SQInteger idx);
- void (*weakref)(HSQUIRRELVM v,SQInteger idx);
- SQRESULT (*getdefaultdelegate)(HSQUIRRELVM v,SQObjectType t);
-
- /*object manipulation*/
- void (*pushroottable)(HSQUIRRELVM v);
- void (*pushregistrytable)(HSQUIRRELVM v);
- void (*pushconsttable)(HSQUIRRELVM v);
- SQRESULT (*setroottable)(HSQUIRRELVM v);
- SQRESULT (*setconsttable)(HSQUIRRELVM v);
- SQRESULT (*newslot)(HSQUIRRELVM v, SQInteger idx, SQBool bstatic);
- SQRESULT (*deleteslot)(HSQUIRRELVM v,SQInteger idx,SQBool pushval);
- SQRESULT (*set)(HSQUIRRELVM v,SQInteger idx);
- SQRESULT (*get)(HSQUIRRELVM v,SQInteger idx);
- SQRESULT (*rawget)(HSQUIRRELVM v,SQInteger idx);
- SQRESULT (*rawset)(HSQUIRRELVM v,SQInteger idx);
- SQRESULT (*rawdeleteslot)(HSQUIRRELVM v,SQInteger idx,SQBool pushval);
- SQRESULT (*arrayappend)(HSQUIRRELVM v,SQInteger idx);
- SQRESULT (*arraypop)(HSQUIRRELVM v,SQInteger idx,SQBool pushval);
- SQRESULT (*arrayresize)(HSQUIRRELVM v,SQInteger idx,SQInteger newsize);
- SQRESULT (*arrayreverse)(HSQUIRRELVM v,SQInteger idx);
- SQRESULT (*arrayremove)(HSQUIRRELVM v,SQInteger idx,SQInteger itemidx);
- SQRESULT (*arrayinsert)(HSQUIRRELVM v,SQInteger idx,SQInteger destpos);
- SQRESULT (*setdelegate)(HSQUIRRELVM v,SQInteger idx);
- SQRESULT (*getdelegate)(HSQUIRRELVM v,SQInteger idx);
- SQRESULT (*clone)(HSQUIRRELVM v,SQInteger idx);
- SQRESULT (*setfreevariable)(HSQUIRRELVM v,SQInteger idx,SQUnsignedInteger nval);
- SQRESULT (*next)(HSQUIRRELVM v,SQInteger idx);
- SQRESULT (*getweakrefval)(HSQUIRRELVM v,SQInteger idx);
- SQRESULT (*clear)(HSQUIRRELVM v,SQInteger idx);
-
- /*calls*/
- SQRESULT (*call)(HSQUIRRELVM v,SQInteger params,SQBool retval,SQBool raiseerror);
- SQRESULT (*resume)(HSQUIRRELVM v,SQBool retval,SQBool raiseerror);
- const SQChar* (*getlocal)(HSQUIRRELVM v,SQUnsignedInteger level,SQUnsignedInteger idx);
- const SQChar* (*getfreevariable)(HSQUIRRELVM v,SQInteger idx,SQUnsignedInteger nval);
- SQRESULT (*throwerror)(HSQUIRRELVM v,const SQChar *err);
- void (*reseterror)(HSQUIRRELVM v);
- void (*getlasterror)(HSQUIRRELVM v);
-
- /*raw object handling*/
- SQRESULT (*getstackobj)(HSQUIRRELVM v,SQInteger idx,HSQOBJECT *po);
- void (*pushobject)(HSQUIRRELVM v,HSQOBJECT obj);
- void (*addref)(HSQUIRRELVM v,HSQOBJECT *po);
- SQBool (*release)(HSQUIRRELVM v,HSQOBJECT *po);
- void (*resetobject)(HSQOBJECT *po);
- const SQChar* (*objtostring)(const HSQOBJECT *o);
- SQBool (*objtobool)(const HSQOBJECT *o);
- SQInteger (*objtointeger)(const HSQOBJECT *o);
- SQFloat (*objtofloat)(const HSQOBJECT *o);
- SQRESULT (*getobjtypetag)(const HSQOBJECT *o,SQUserPointer * typetag);
-
- /*GC*/
- SQInteger (*collectgarbage)(HSQUIRRELVM v);
-
- /*serialization*/
- SQRESULT (*writeclosure)(HSQUIRRELVM vm,SQWRITEFUNC writef,SQUserPointer up);
- SQRESULT (*readclosure)(HSQUIRRELVM vm,SQREADFUNC readf,SQUserPointer up);
-
- /*mem allocation*/
- void* (*malloc)(SQUnsignedInteger size);
- void* (*realloc)(void* p,SQUnsignedInteger oldsize,SQUnsignedInteger newsize);
- void (*free)(void *p,SQUnsignedInteger size);
-
- /*debug*/
- SQRESULT (*stackinfos)(HSQUIRRELVM v,SQInteger level,SQStackInfos *si);
- void (*setdebughook)(HSQUIRRELVM v);
-
- /*missing vm*/
- void (*setsharedforeignptr)(HSQUIRRELVM v, SQUserPointer p);
- SQUserPointer (*getsharedforeignptr)(HSQUIRRELVM v);
- void (*setvmreleasehook)(HSQUIRRELVM v, SQRELEASEHOOK hook);
- SQRELEASEHOOK (*getvmreleasehook)(HSQUIRRELVM v);
- void (*setsharedreleasehook)(HSQUIRRELVM v, SQRELEASEHOOK hook);
- SQRELEASEHOOK (*getsharedreleasehook)(HSQUIRRELVM v);
- SQPRINTFUNCTION (*geterrorfunc)(HSQUIRRELVM v);
- SQInteger (*getversion)();
-
- /*missing object creation handling*/
- void (*newtableex)(HSQUIRRELVM v, SQInteger initialcapacity);
- SQRESULT (*setclosureroot)(HSQUIRRELVM v, SQInteger idx);
- SQRESULT (*getclosureroot)(HSQUIRRELVM v, SQInteger idx);
- void (*pushthread)(HSQUIRRELVM v, HSQUIRRELVM thread);
- SQRESULT (*type_of)(HSQUIRRELVM v, SQInteger idx);
- SQHash (*gethash)(HSQUIRRELVM v, SQInteger idx);
- SQRELEASEHOOK (*getreleasehook)(HSQUIRRELVM v, SQInteger idx);
- SQRESULT (*getfunctioninfo)(HSQUIRRELVM v, SQInteger level, SQFunctionInfo* fi);
- SQRESULT (*getclosurename)(HSQUIRRELVM v, SQInteger idx);
- SQRESULT (*getmemberhandle)(HSQUIRRELVM v, SQInteger idx, HSQMEMBERHANDLE* handle);
- SQRESULT (*getbyhandle)(HSQUIRRELVM v, SQInteger idx, const HSQMEMBERHANDLE* handle);
- SQRESULT (*setbyhandle)(HSQUIRRELVM v, SQInteger idx, const HSQMEMBERHANDLE* handle);
-
- /*missing object manipulation*/
- SQRESULT (*newmember)(HSQUIRRELVM v, SQInteger idx, SQBool bstatic);
- SQRESULT (*rawnewmember)(HSQUIRRELVM v, SQInteger idx, SQBool bstatic);
-
- /*missing calls*/
- SQRESULT (*getcallee)(HSQUIRRELVM v);
- SQRESULT (*throwobject)(HSQUIRRELVM v);
-
- /*missing raw object handling*/
- SQUnsignedInteger (*getrefcount)(HSQUIRRELVM v, HSQOBJECT* po);
- SQUserPointer (*objtouserpointer)(const HSQOBJECT* o);
- SQUnsignedInteger (*getvmrefcount)(HSQUIRRELVM v, const HSQOBJECT* po);
-
- /*missing GC*/
- SQRESULT (*resurrectunreachable)(HSQUIRRELVM v);
-
- /*missing debug*/
- void (*setnativedebughook)(HSQUIRRELVM v, SQDEBUGHOOK hook);
- } sq_api;
- typedef sq_api* HSQAPI;
- /// @endcond
-
-#ifdef __cplusplus
-} /*extern "C"*/
-#endif
-
-#endif /*_SQ_MODULE_H_*/
diff --git a/dependencies/sqrat/include/sqrat.h b/dependencies/sqrat/include/sqrat.h
deleted file mode 100644
index 81efc50..0000000
--- a/dependencies/sqrat/include/sqrat.h
+++ /dev/null
@@ -1,69 +0,0 @@
-//
-// Sqrat: Squirrel C++ Binding Utility
-//
-
-//
-// 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.
-//
-
-/*! \mainpage Sqrat Main Page
- *
- * \section intro_sec Introduction
- *
- * Sqrat is a C++ library for Squirrel that facilitates exposing classes and other native functionality to Squirrel scripts. It models the underlying Squirrel API closely to give access to a wider range of functionality than other binding libraries. In addition to the binding library, Sqrat features a threading library and a module import library.
- *
- * \section install_sec Installation
- *
- * Sqrat only contains C++ headers so for installation you just need to copy the files in the include directory to some common header path.
- *
- * \section sec_faq Frequently Asked Questions
- *
- * Q: My application is crashing when I call sq_close. Why is this happening?
- * A: All Sqrat::Object instances and derived type instances must be destroyed before calling sq_close.
- *
- * \section discuss_sec Discussion and User Support
- *
- * Discussion about Sqrat happens at the Squirrel language forum, the Bindings section
- * http://squirrel-lang.org/forums/default.aspx?g=topics&f=4
- *
- * \section bug_sec Bug Reporting
- *
- * Bug reports or feature enhancement requests and patches can be submitted at the SourceForge Sqrat site
- * https://sourceforge.net/p/scrat/sqrat/
- *
- * You're invited to make documentation suggestions for Sqrat. Together, we can make Sqrat as easy to understand as possible!
- */
-
-#if !defined(_SCRAT_MAIN_H_)
-#define _SCRAT_MAIN_H_
-
-#include
-
-#include "sqrat/sqratTable.h"
-#include "sqrat/sqratClass.h"
-#include "sqrat/sqratFunction.h"
-#include "sqrat/sqratConst.h"
-#include "sqrat/sqratUtil.h"
-#include "sqrat/sqratScript.h"
-#include "sqrat/sqratArray.h"
-
-#endif
diff --git a/dependencies/sqrat/include/sqrat/sqratAllocator.h b/dependencies/sqrat/include/sqrat/sqratAllocator.h
deleted file mode 100644
index 1eb7c15..0000000
--- a/dependencies/sqrat/include/sqrat/sqratAllocator.h
+++ /dev/null
@@ -1,863 +0,0 @@
-//
-// SqratAllocator: Custom Class Allocation/Deallocation
-//
-
-//
-// 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_ALLOCATOR_H_)
-#define _SCRAT_ALLOCATOR_H_
-
-#include
-#include
-
-#include "sqratObject.h"
-#include "sqratTypes.h"
-
-namespace Sqrat {
-
-/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-/// @cond DEV
-/// utility taken from http://stackoverflow.com/questions/2733377/is-there-a-way-to-test-whether-a-c-class-has-a-default-constructor-other-than/2770326#2770326
-/// may be obsolete in C++ 11
-/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-template< class T >
-class is_default_constructible {
- template
- class receive_size{};
-
- template< class U >
- static int sfinae( receive_size< sizeof U() > * );
-
- template< class U >
- static char sfinae( ... );
-
-public:
- enum { value = sizeof( sfinae(0) ) == sizeof(int) };
-};
-/// @endcond
-
-/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-/// DefaultAllocator is the allocator to use for Class that can both be constructed and copied
-///
-/// \tparam C Type of class
-///
-/// \remarks
-/// There is mechanisms defined in this class that allow the Class::Ctor method to work properly (e.g. iNew).
-///
-/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-template
-class DefaultAllocator {
-
- template
- struct NewC
- {
- T* p;
- NewC()
- {
- p = new T();
- }
- };
-
- template
- struct NewC
- {
- T* p;
- NewC()
- {
- p = 0;
- }
- };
-
-public:
-
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- /// Associates a newly created instance with an object allocated with the new operator (which is automatically deleted)
- ///
- /// \param vm VM that has an instance object of the correct type at idx
- /// \param idx Index of the stack that the instance object is at
- /// \param ptr Should be the return value from a call to the new operator
- ///
- /// \remarks
- /// This function should only need to be used when custom constructors are bound with Class::SquirrelFunc.
- ///
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- static void SetInstance(HSQUIRRELVM vm, SQInteger idx, C* ptr)
- {
- ClassData* cd = ClassType::getClassData(vm);
- sq_setinstanceup(vm, idx, new std::pair::type> >(ptr, cd->instances));
- sq_setreleasehook(vm, idx, &Delete);
- sq_getstackobj(vm, idx, &((*cd->instances)[ptr]));
- }
-
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- /// Called by Sqrat to set up an instance on the stack for the template class
- ///
- /// \param vm VM that has an instance object of the correct type at position 1 in its stack
- ///
- /// \return Squirrel error code
- ///
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- static SQInteger New(HSQUIRRELVM vm) {
- SetInstance(vm, 1, NewC::value >().p);
- return 0;
- }
-
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- /// @cond DEV
- /// following iNew functions are used only if constructors are bound via Ctor() in Sqrat::Class (safe to ignore)
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- static SQInteger iNew(HSQUIRRELVM vm) {
- return New(vm);
- }
-
- template
- static SQInteger iNew(HSQUIRRELVM vm) {
- SQTRY()
- Var a1(vm, 2);
- SQCATCH_NOEXCEPT(vm) {
- return sq_throwerror(vm, SQWHAT_NOEXCEPT(vm));
- }
- SetInstance(vm, 1, new C(
- a1.value
- ));
- SQCATCH(vm) {
- return sq_throwerror(vm, SQWHAT(vm));
- }
- return 0;
- }
- template
- static SQInteger iNew(HSQUIRRELVM vm) {
- SQTRY()
- Var a1(vm, 2);
- Var a2(vm, 3);
- SQCATCH_NOEXCEPT(vm) {
- return sq_throwerror(vm, SQWHAT_NOEXCEPT(vm));
- }
- SetInstance(vm, 1, new C(
- a1.value,
- a2.value
- ));
- SQCATCH(vm) {
- return sq_throwerror(vm, SQWHAT(vm));
- }
- return 0;
- }
- template
- static SQInteger iNew(HSQUIRRELVM vm) {
- SQTRY()
- Var a1(vm, 2);
- Var a2(vm, 3);
- Var a3(vm, 4);
- SQCATCH_NOEXCEPT(vm) {
- return sq_throwerror(vm, SQWHAT_NOEXCEPT(vm));
- }
- SetInstance(vm, 1, new C(
- a1.value,
- a2.value,
- a3.value
- ));
- SQCATCH(vm) {
- return sq_throwerror(vm, SQWHAT(vm));
- }
- return 0;
- }
- template
- static SQInteger iNew(HSQUIRRELVM vm) {
- SQTRY()
- Var a1(vm, 2);
- Var a2(vm, 3);
- Var a3(vm, 4);
- Var a4(vm, 5);
- SQCATCH_NOEXCEPT(vm) {
- return sq_throwerror(vm, SQWHAT_NOEXCEPT(vm));
- }
- SetInstance(vm, 1, new C(
- a1.value,
- a2.value,
- a3.value,
- a4.value
- ));
- SQCATCH(vm) {
- return sq_throwerror(vm, SQWHAT(vm));
- }
- return 0;
- }
- template
- static SQInteger iNew(HSQUIRRELVM vm) {
- SQTRY()
- Var a1(vm, 2);
- Var a2(vm, 3);
- Var a3(vm, 4);
- Var a4(vm, 5);
- Var a5(vm, 6);
- SQCATCH_NOEXCEPT(vm) {
- return sq_throwerror(vm, SQWHAT_NOEXCEPT(vm));
- }
- SetInstance(vm, 1, new C(
- a1.value,
- a2.value,
- a3.value,
- a4.value,
- a5.value
- ));
- SQCATCH(vm) {
- return sq_throwerror(vm, SQWHAT(vm));
- }
- return 0;
- }
- template
- static SQInteger iNew(HSQUIRRELVM vm) {
- SQTRY()
- Var a1(vm, 2);
- Var a2(vm, 3);
- Var a3(vm, 4);
- Var a4(vm, 5);
- Var a5(vm, 6);
- Var a6(vm, 7);
- SQCATCH_NOEXCEPT(vm) {
- return sq_throwerror(vm, SQWHAT_NOEXCEPT(vm));
- }
- SetInstance(vm, 1, new C(
- a1.value,
- a2.value,
- a3.value,
- a4.value,
- a5.value,
- a6.value
- ));
- SQCATCH(vm) {
- return sq_throwerror(vm, SQWHAT(vm));
- }
- return 0;
- }
- template
- static SQInteger iNew(HSQUIRRELVM vm) {
- SQTRY()
- Var a1(vm, 2);
- Var a2(vm, 3);
- Var a3(vm, 4);
- Var a4(vm, 5);
- Var a5(vm, 6);
- Var a6(vm, 7);
- Var a7(vm, 8);
- SQCATCH_NOEXCEPT(vm) {
- return sq_throwerror(vm, SQWHAT_NOEXCEPT(vm));
- }
- SetInstance(vm, 1, new C(
- a1.value,
- a2.value,
- a3.value,
- a4.value,
- a5.value,
- a6.value,
- a7.value
- ));
- SQCATCH(vm) {
- return sq_throwerror(vm, SQWHAT(vm));
- }
- return 0;
- }
- template
- static SQInteger iNew(HSQUIRRELVM vm) {
- SQTRY()
- Var a1(vm, 2);
- Var a2(vm, 3);
- Var a3(vm, 4);
- Var a4(vm, 5);
- Var a5(vm, 6);
- Var a6(vm, 7);
- Var a7(vm, 8);
- Var a8(vm, 9);
- SQCATCH_NOEXCEPT(vm) {
- return sq_throwerror(vm, SQWHAT_NOEXCEPT(vm));
- }
- SetInstance(vm, 1, new C(
- a1.value,
- a2.value,
- a3.value,
- a4.value,
- a5.value,
- a6.value,
- a7.value,
- a8.value
- ));
- SQCATCH(vm) {
- return sq_throwerror(vm, SQWHAT(vm));
- }
- return 0;
- }
- template
- static SQInteger iNew(HSQUIRRELVM vm) {
- SQTRY()
- Var a1(vm, 2);
- Var a2(vm, 3);
- Var a3(vm, 4);
- Var a4(vm, 5);
- Var a5(vm, 6);
- Var a6(vm, 7);
- Var a7(vm, 8);
- Var a8(vm, 9);
- Var a9(vm, 10);
- SQCATCH_NOEXCEPT(vm) {
- return sq_throwerror(vm, SQWHAT_NOEXCEPT(vm));
- }
- SetInstance(vm, 1, new C(
- a1.value,
- a2.value,
- a3.value,
- a4.value,
- a5.value,
- a6.value,
- a7.value,
- a8.value,
- a9.value
- ));
- SQCATCH(vm) {
- return sq_throwerror(vm, SQWHAT(vm));
- }
- return 0;
- }
- /// @endcond
-
-public:
-
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- /// Called by Sqrat to set up the instance at idx on the stack as a copy of a value of the same type
- ///
- /// \param vm VM that has an instance object of the correct type at idx
- /// \param idx Index of the stack that the instance object is at
- /// \param value A pointer to data of the same type as the instance object
- ///
- /// \return Squirrel error code
- ///
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- static SQInteger Copy(HSQUIRRELVM vm, SQInteger idx, const void* value) {
- SetInstance(vm, idx, new C(*static_cast(value)));
- return 0;
- }
-
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- /// Called by Sqrat to delete an instance's data
- ///
- /// \param ptr Pointer to the data contained by the instance
- /// \param size Size of the data contained by the instance
- ///
- /// \return Squirrel error code
- ///
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- static SQInteger Delete(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;
- }
-};
-
-/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-/// NoConstructor is the allocator to use for Class that can NOT be constructed or copied
-///
-/// \tparam C Type of class
-///
-/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-template
-class NoConstructor {
-public:
-
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- /// Associates a newly created instance with an object allocated with the new operator (which is automatically deleted)
- ///
- /// \param vm VM that has an instance object of the correct type at idx
- /// \param idx Index of the stack that the instance object is at
- /// \param ptr Should be the return value from a call to the new operator
- ///
- /// \remarks
- /// This function should only need to be used when custom constructors are bound with Class::SquirrelFunc.
- ///
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- static void SetInstance(HSQUIRRELVM vm, SQInteger idx, C* ptr)
- {
- ClassData* cd = ClassType::getClassData(vm);
- sq_setinstanceup(vm, idx, new std::pair::type> >(ptr, cd->instance));
- sq_setreleasehook(vm, idx, &Delete);
- sq_getstackobj(vm, idx, &((*cd->instances)[ptr]));
- }
-
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- /// Called by Sqrat to set up an instance on the stack for the template class (not allowed in this allocator)
- ///
- /// \param vm VM that has an instance object of the correct type at position 1 in its stack
- ///
- /// \return Squirrel error code
- ///
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- static SQInteger New(HSQUIRRELVM vm) {
-#if !defined (SCRAT_NO_ERROR_CHECKING)
- return sq_throwerror(vm, (ClassType::ClassName() + string(_SC(" constructing is not allowed"))).c_str());
-#else
- SQUNUSED(vm);
- return 0;
-#endif
- }
-
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- /// Called by Sqrat to set up the instance at idx on the stack as a copy of a value of the same type (not used in this allocator)
- ///
- /// \param vm VM that has an instance object of the correct type at idx
- /// \param idx Index of the stack that the instance object is at
- /// \param value A pointer to data of the same type as the instance object
- ///
- /// \return Squirrel error code
- ///
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- static SQInteger Copy(HSQUIRRELVM vm, SQInteger idx, const void* value) {
- SQUNUSED(vm);
- SQUNUSED(idx);
- SQUNUSED(value);
- return sq_throwerror(vm, (ClassType::ClassName() + string(_SC(" cloning is not allowed"))).c_str());
- }
-
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- /// Called by Sqrat to delete an instance's data
- ///
- /// \param ptr Pointer to the data contained by the instance
- /// \param size Size of the data contained by the instance
- ///
- /// \return Squirrel error code
- ///
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- static SQInteger Delete(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;
- }
-};
-
-/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-/// CopyOnly is the allocator to use for Class that can be copied but not constructed
-///
-/// \tparam C Type of class
-///
-/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-template
-class CopyOnly {
-public:
-
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- /// Associates a newly created instance with an object allocated with the new operator (which is automatically deleted)
- ///
- /// \param vm VM that has an instance object of the correct type at idx
- /// \param idx Index of the stack that the instance object is at
- /// \param ptr Should be the return value from a call to the new operator
- ///
- /// \remarks
- /// This function should only need to be used when custom constructors are bound with Class::SquirrelFunc.
- ///
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- static void SetInstance(HSQUIRRELVM vm, SQInteger idx, C* ptr)
- {
- ClassData* cd = ClassType::getClassData(vm);
- sq_setinstanceup(vm, idx, new std::pair::type> >(ptr, cd->instances));
- sq_setreleasehook(vm, idx, &Delete);
- sq_getstackobj(vm, idx, &((*cd->instances)[ptr]));
- }
-
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- /// Called by Sqrat to set up an instance on the stack for the template class (not allowed in this allocator)
- ///
- /// \param vm VM that has an instance object of the correct type at position 1 in its stack
- ///
- /// \return Squirrel error code
- ///
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- static SQInteger New(HSQUIRRELVM vm) {
-#if !defined (SCRAT_NO_ERROR_CHECKING)
- return sq_throwerror(vm, (ClassType::ClassName() + string(_SC(" constructing is not allowed"))).c_str());
-#else
- SQUNUSED(vm);
- return 0;
-#endif
- }
-
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- /// Called by Sqrat to set up the instance at idx on the stack as a copy of a value of the same type
- ///
- /// \param vm VM that has an instance object of the correct type at idx
- /// \param idx Index of the stack that the instance object is at
- /// \param value A pointer to data of the same type as the instance object
- ///
- /// \return Squirrel error code
- ///
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- static SQInteger Copy(HSQUIRRELVM vm, SQInteger idx, const void* value) {
- SetInstance(vm, idx, new C(*static_cast(value)));
- return 0;
- }
-
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- /// Called by Sqrat to delete an instance's data
- ///
- /// \param ptr Pointer to the data contained by the instance
- /// \param size Size of the data contained by the instance
- ///
- /// \return Squirrel error code
- ///
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- static SQInteger Delete(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;
- }
-};
-
-
-/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-/// NoCopy is the allocator to use for Class that can be constructed but not copied
-///
-/// \tparam C Type of class
-///
-/// \remarks
-/// There is mechanisms defined in this class that allow the Class::Ctor method to work properly (e.g. iNew).
-///
-/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-template
-class NoCopy {
-
- template
- struct NewC
- {
- T* p;
- NewC()
- {
- p = new T();
- }
- };
-
- template
- struct NewC
- {
- T* p;
- NewC()
- {
- p = 0;
- }
- };
-
-public:
-
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- /// Associates a newly created instance with an object allocated with the new operator (which is automatically deleted)
- ///
- /// \param vm VM that has an instance object of the correct type at idx
- /// \param idx Index of the stack that the instance object is at
- /// \param ptr Should be the return value from a call to the new operator
- ///
- /// \remarks
- /// This function should only need to be used when custom constructors are bound with Class::SquirrelFunc.
- ///
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- static void SetInstance(HSQUIRRELVM vm, SQInteger idx, C* ptr)
- {
- ClassData* cd = ClassType::getClassData(vm);
- sq_setinstanceup(vm, idx, new std::pair::type> >(ptr, cd->instances));
- sq_setreleasehook(vm, idx, &Delete);
- sq_getstackobj(vm, idx, &((*cd->instances)[ptr]));
- }
-
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- /// Called by Sqrat to set up an instance on the stack for the template class
- ///
- /// \param vm VM that has an instance object of the correct type at position 1 in its stack
- ///
- /// \return Squirrel error code
- ///
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- static SQInteger New(HSQUIRRELVM vm) {
- SetInstance(vm, 1, NewC::value >().p);
- return 0;
- }
-
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- /// @cond DEV
- /// following iNew functions are used only if constructors are bound via Ctor() in Sqrat::Class (safe to ignore)
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- static SQInteger iNew(HSQUIRRELVM vm) {
- return New(vm);
- }
-
- template
- static SQInteger iNew(HSQUIRRELVM vm) {
- SQTRY()
- Var a1(vm, 2);
- SQCATCH_NOEXCEPT(vm) {
- return sq_throwerror(vm, SQWHAT_NOEXCEPT(vm));
- }
- SetInstance(vm, 1, new C(
- a1.value
- ));
- SQCATCH(vm) {
- return sq_throwerror(vm, SQWHAT(vm));
- }
- return 0;
- }
- template
- static SQInteger iNew(HSQUIRRELVM vm) {
- SQTRY()
- Var a1(vm, 2);
- Var a2(vm, 3);
- SQCATCH_NOEXCEPT(vm) {
- return sq_throwerror(vm, SQWHAT_NOEXCEPT(vm));
- }
- SetInstance(vm, 1, new C(
- a1.value,
- a2.value
- ));
- SQCATCH(vm) {
- return sq_throwerror(vm, SQWHAT(vm));
- }
- return 0;
- }
- template
- static SQInteger iNew(HSQUIRRELVM vm) {
- SQTRY()
- Var a1(vm, 2);
- Var a2(vm, 3);
- Var a3(vm, 4);
- SQCATCH_NOEXCEPT(vm) {
- return sq_throwerror(vm, SQWHAT_NOEXCEPT(vm));
- }
- SetInstance(vm, 1, new C(
- a1.value,
- a2.value,
- a3.value
- ));
- SQCATCH(vm) {
- return sq_throwerror(vm, SQWHAT(vm));
- }
- return 0;
- }
- template
- static SQInteger iNew(HSQUIRRELVM vm) {
- SQTRY()
- Var a1(vm, 2);
- Var a2(vm, 3);
- Var a3(vm, 4);
- Var a4(vm, 5);
- SQCATCH_NOEXCEPT(vm) {
- return sq_throwerror(vm, SQWHAT_NOEXCEPT(vm));
- }
- SetInstance(vm, 1, new C(
- a1.value,
- a2.value,
- a3.value,
- a4.value
- ));
- SQCATCH(vm) {
- return sq_throwerror(vm, SQWHAT(vm));
- }
- return 0;
- }
- template
- static SQInteger iNew(HSQUIRRELVM vm) {
- SQTRY()
- Var a1(vm, 2);
- Var a2(vm, 3);
- Var a3(vm, 4);
- Var a4(vm, 5);
- Var a5(vm, 6);
- SQCATCH_NOEXCEPT(vm) {
- return sq_throwerror(vm, SQWHAT_NOEXCEPT(vm));
- }
- SetInstance(vm, 1, new C(
- a1.value,
- a2.value,
- a3.value,
- a4.value,
- a5.value
- ));
- SQCATCH(vm) {
- return sq_throwerror(vm, SQWHAT(vm));
- }
- return 0;
- }
- template
- static SQInteger iNew(HSQUIRRELVM vm) {
- SQTRY()
- Var a1(vm, 2);
- Var a2(vm, 3);
- Var a3(vm, 4);
- Var a4(vm, 5);
- Var a5(vm, 6);
- Var a6(vm, 7);
- SQCATCH_NOEXCEPT(vm) {
- return sq_throwerror(vm, SQWHAT_NOEXCEPT(vm));
- }
- SetInstance(vm, 1, new C(
- a1.value,
- a2.value,
- a3.value,
- a4.value,
- a5.value,
- a6.value
- ));
- SQCATCH(vm) {
- return sq_throwerror(vm, SQWHAT(vm));
- }
- return 0;
- }
- template
- static SQInteger iNew(HSQUIRRELVM vm) {
- SQTRY()
- Var a1(vm, 2);
- Var a2(vm, 3);
- Var a3(vm, 4);
- Var a4(vm, 5);
- Var a5(vm, 6);
- Var a6(vm, 7);
- Var a7(vm, 8);
- SQCATCH_NOEXCEPT(vm) {
- return sq_throwerror(vm, SQWHAT_NOEXCEPT(vm));
- }
- SetInstance(vm, 1, new C(
- a1.value,
- a2.value,
- a3.value,
- a4.value,
- a5.value,
- a6.value,
- a7.value
- ));
- SQCATCH(vm) {
- return sq_throwerror(vm, SQWHAT(vm));
- }
- return 0;
- }
- template
- static SQInteger iNew(HSQUIRRELVM vm) {
- SQTRY()
- Var a1(vm, 2);
- Var a2(vm, 3);
- Var a3(vm, 4);
- Var a4(vm, 5);
- Var a5(vm, 6);
- Var a6(vm, 7);
- Var a7(vm, 8);
- Var a8(vm, 9);
- SQCATCH_NOEXCEPT(vm) {
- return sq_throwerror(vm, SQWHAT_NOEXCEPT(vm));
- }
- SetInstance(vm, 1, new C(
- a1.value,
- a2.value,
- a3.value,
- a4.value,
- a5.value,
- a6.value,
- a7.value,
- a8.value
- ));
- SQCATCH(vm) {
- return sq_throwerror(vm, SQWHAT(vm));
- }
- return 0;
- }
- template
- static SQInteger iNew(HSQUIRRELVM vm) {
- SQTRY()
- Var a1(vm, 2);
- Var a2(vm, 3);
- Var a3(vm, 4);
- Var a4(vm, 5);
- Var a5(vm, 6);
- Var a6(vm, 7);
- Var a7(vm, 8);
- Var a8(vm, 9);
- Var a9(vm, 10);
- SQCATCH_NOEXCEPT(vm) {
- return sq_throwerror(vm, SQWHAT_NOEXCEPT(vm));
- }
- SetInstance(vm, 1, new C(
- a1.value,
- a2.value,
- a3.value,
- a4.value,
- a5.value,
- a6.value,
- a7.value,
- a8.value,
- a9.value
- ));
- SQCATCH(vm) {
- return sq_throwerror(vm, SQWHAT(vm));
- }
- return 0;
- }
- /// @endcond
-
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- /// Called by Sqrat to set up the instance at idx on the stack as a copy of a value of the same type (not used in this allocator)
- ///
- /// \param vm VM that has an instance object of the correct type at idx
- /// \param idx Index of the stack that the instance object is at
- /// \param value A pointer to data of the same type as the instance object
- ///
- /// \return Squirrel error code
- ///
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- static SQInteger Copy(HSQUIRRELVM vm, SQInteger idx, const void* value) {
- SQUNUSED(vm);
- SQUNUSED(idx);
- SQUNUSED(value);
- return sq_throwerror(vm, (ClassType::ClassName() + string(_SC(" cloning is not allowed"))).c_str());
- }
-
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- /// Called by Sqrat to delete an instance's data
- ///
- /// \param ptr Pointer to the data contained by the instance
- /// \param size Size of the data contained by the instance
- ///
- /// \return Squirrel error code
- ///
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- static SQInteger Delete(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;
- }
-};
-
-}
-
-#endif
diff --git a/dependencies/sqrat/include/sqrat/sqratArray.h b/dependencies/sqrat/include/sqrat/sqratArray.h
deleted file mode 100644
index 5d08c39..0000000
--- a/dependencies/sqrat/include/sqrat/sqratArray.h
+++ /dev/null
@@ -1,558 +0,0 @@
-//
-// SqratArray: Array Binding
-//
-
-//
-// Copyright 2011 Alston Chen
-//
-// 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_ARRAY_H_)
-#define _SCRAT_ARRAY_H_
-
-#include
-#include
-
-#include "sqratObject.h"
-#include "sqratFunction.h"
-#include "sqratGlobalMethods.h"
-
-namespace Sqrat {
-
-/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-/// The base class for Array that implements almost all of its functionality
-/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-class ArrayBase : public Object {
-public:
-
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- /// Default constructor (null)
- ///
- /// \param v VM that the array will exist in
- ///
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- ArrayBase(HSQUIRRELVM v = DefaultVM::Get()) : Object(v, true) {
- }
-
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- /// Construct the ArrayBase from an Object that already exists
- ///
- /// \param obj An Object that should already represent a Squirrel array
- ///
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- ArrayBase(const Object& obj) : Object(obj) {
- }
-
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- /// Construct the ArrayBase from a HSQOBJECT and HSQUIRRELVM that already exist
- ///
- /// \param o Squirrel object that should already represent a Squirrel array
- /// \param v Squirrel VM that contains the Squirrel object given
- ///
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- ArrayBase(HSQOBJECT o, HSQUIRRELVM v = DefaultVM::Get()) : Object(o, v) {
- }
-
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- /// Binds a Table or Class to the Array (can be used to facilitate namespaces)
- ///
- /// \param index The index in the array being assigned a Table or Class
- /// \param obj Table or Class that is being placed in the Array
- ///
- /// \remarks
- /// Bind cannot be called "inline" like other functions because it introduces order-of-initialization bugs.
- ///
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- void Bind(const SQInteger index, Object& obj) {
- sq_pushobject(vm, GetObject());
- sq_pushinteger(vm, index);
- sq_pushobject(vm, obj.GetObject());
- sq_set(vm, -3);
- sq_pop(vm,1); // pop array
- }
-
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- /// Binds a raw Squirrel closure to the Array
- ///
- /// \param index The index in the array being assigned a function
- /// \param func Squirrel function that is being placed in the Array
- /// \param nparamscheck The parameters count used in runtime arguments count checking (including hidden this parameter)
- /// \param type The type mask used in runtime parameters type checking
- ///
- /// \return The Array itself so the call can be chained
- ///
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- ArrayBase& SquirrelFunc(const SQInteger index, SQFUNCTION func, SQInteger nparamscheck = 0, const SQChar* typemask = 0) {
- sq_pushobject(vm, GetObject());
- sq_pushinteger(vm, index);
- sq_newclosure(vm, func, 0);
- sq_setparamscheck(vm, nparamscheck, typemask);
- sq_set(vm, -3);
- sq_pop(vm,1); // pop array
- return *this;
- }
-
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- /// Sets an index in the Array to a specific value
- ///
- /// \param index The index in the array being assigned a value
- /// \param val Value that is being placed in the Array
- ///
- /// \tparam V Type of value (usually doesnt need to be defined explicitly)
- ///
- /// \return The Array itself so the call can be chained
- ///
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- template
- ArrayBase& SetValue(const SQInteger index, const V& val) {
- sq_pushobject(vm, GetObject());
- sq_pushinteger(vm, index);
- PushVar(vm, val);
- sq_set(vm, -3);
- sq_pop(vm,1); // pop array
- return *this;
- }
-
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- /// Sets an index in the Array to a specific instance (like a reference)
- ///
- /// \param index The index in the array being assigned a value
- /// \param val Pointer to the instance that is being placed in the Array
- ///
- /// \tparam V Type of instance (usually doesnt need to be defined explicitly)
- ///
- /// \return The Array itself so the call can be chained
- ///
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- template
- ArrayBase& SetInstance(const SQInteger index, V* val) {
- BindInstance(index, val, false);
- return *this;
- }
-
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- /// Sets an index in the Array to a specific function
- ///
- /// \param index The index in the array being assigned a value
- /// \param method Function that is being placed in the Array
- ///
- /// \tparam F Type of function (only define this if you need to choose a certain template specialization or overload)
- ///
- /// \return The Array itself so the call can be chained
- ///
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- template
- ArrayBase& Func(const SQInteger index, F method) {
- BindFunc(index, &method, sizeof(method), SqGlobalFunc(method));
- return *this;
- }
-
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- /// Returns the element at a given index
- ///
- /// \param index Index of the element
- ///
- /// \tparam T Type of element (fails if element is not of this type)
- ///
- /// \return SharedPtr containing the element (or null if failed)
- ///
- /// \remarks
- /// This function MUST have its Error handled if it occurred.
- ///
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- template
- SharedPtr GetValue(int index)
- {
- sq_pushobject(vm, obj);
- sq_pushinteger(vm, index);
-#if !defined (SCRAT_NO_ERROR_CHECKING)
- if (SQ_FAILED(sq_get(vm, -2))) {
- sq_pop(vm, 1);
- SQTHROW(vm, _SC("illegal index"));
- return SharedPtr();
- }
-#else
- sq_get(vm, -2);
-#endif
- SQTRY()
- Var > element(vm, -1);
- SQCATCH_NOEXCEPT(vm) {
- sq_pop(vm, 2);
- return SharedPtr();
- }
- sq_pop(vm, 2);
- return element.value;
- SQCATCH(vm) {
-#if defined (SCRAT_USE_EXCEPTIONS)
- SQUNUSED(e); // avoid "unreferenced local variable" warning
-#endif
- sq_pop(vm, 2);
- SQRETHROW(vm);
- }
- return SharedPtr(); // avoid "not all control paths return a value" warning
- }
-
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- /// Gets a Function from an index in the Array
- ///
- /// \param index The index in the array that contains the Function
- ///
- /// \return Function found in the Array (null if failed)
- ///
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- Function GetFunction(const SQInteger index) {
- HSQOBJECT funcObj;
- sq_pushobject(vm, GetObject());
- sq_pushinteger(vm, index);
-#if !defined (SCRAT_NO_ERROR_CHECKING)
- if(SQ_FAILED(sq_get(vm, -2))) {
- sq_pop(vm, 1);
- return Function();
- }
- SQObjectType value_type = sq_gettype(vm, -1);
- if (value_type != OT_CLOSURE && value_type != OT_NATIVECLOSURE) {
- sq_pop(vm, 2);
- return Function();
- }
-#else
- sq_get(vm, -2);
-#endif
- sq_getstackobj(vm, -1, &funcObj);
- Function ret(vm, GetObject(), funcObj); // must addref before the pop!
- sq_pop(vm, 2);
- return ret;
- }
-
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- /// Fills a C array with the elements of the Array
- ///
- /// \param array C array to be filled
- /// \param size The amount of elements to fill the C array with
- ///
- /// \tparam T Type of elements (fails if any elements in Array are not of this type)
- ///
- /// \remarks
- /// This function MUST have its Error handled if it occurred.
- ///
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- template
- void GetArray(T* array, int size)
- {
- HSQOBJECT value = GetObject();
- sq_pushobject(vm, value);
-#if !defined (SCRAT_NO_ERROR_CHECKING)
- if (size > sq_getsize(vm, -1)) {
- sq_pop(vm, 1);
- SQTHROW(vm, _SC("array buffer size too big"));
- return;
- }
-#endif
- sq_pushnull(vm);
- SQInteger i;
- while (SQ_SUCCEEDED(sq_next(vm, -2))) {
- sq_getinteger(vm, -2, &i);
- if (i >= size) break;
- SQTRY()
- Var element(vm, -1);
- SQCATCH_NOEXCEPT(vm) {
- sq_pop(vm, 4);
- return;
- }
- sq_pop(vm, 2);
- array[i] = element.value;
- SQCATCH(vm) {
-#if defined (SCRAT_USE_EXCEPTIONS)
- SQUNUSED(e); // avoid "unreferenced local variable" warning
-#endif
- sq_pop(vm, 4);
- SQRETHROW(vm);
- }
- }
- sq_pop(vm, 2); // pops the null iterator and the array object
- }
-
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- /// Appends a value to the end of the Array
- ///
- /// \param val Value that is being placed in the Array
- ///
- /// \tparam V Type of value (usually doesnt need to be defined explicitly)
- ///
- /// \return The Array itself so the call can be chained
- ///
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- template
- ArrayBase& Append(const V& val) {
- sq_pushobject(vm, GetObject());
- PushVar(vm, val);
- sq_arrayappend(vm, -2);
- sq_pop(vm,1); // pop array
- return *this;
- }
-
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- /// Appends an instance to the end of the Array (like a reference)
- ///
- /// \param val Pointer to the instance that is being placed in the Array
- ///
- /// \tparam V Type of instance (usually doesnt need to be defined explicitly)
- ///
- /// \return The Array itself so the call can be chained
- ///
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- template
- ArrayBase& Append(V* val) {
- sq_pushobject(vm, GetObject());
- PushVar(vm, val);
- sq_arrayappend(vm, -2);
- sq_pop(vm,1); // pop array
- return *this;
- }
-
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- /// Inserts a value in a position in the Array
- ///
- /// \param destpos Index to put the new value in
- /// \param val Value that is being placed in the Array
- ///
- /// \tparam V Type of value (usually doesnt need to be defined explicitly)
- ///
- /// \return The Array itself so the call can be chained
- ///
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- template
- ArrayBase& Insert(const SQInteger destpos, const V& val) {
- sq_pushobject(vm, GetObject());
- PushVar(vm, val);
- sq_arrayinsert(vm, -2, destpos);
- sq_pop(vm,1); // pop array
- return *this;
- }
-
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- /// Inserts an instance in a position in the Array (like a reference)
- ///
- /// \param destpos Index to put the new value in
- /// \param val Pointer to the instance that is being placed in the Array
- ///
- /// \tparam V Type of instance (usually doesnt need to be defined explicitly)
- ///
- /// \return The Array itself so the call can be chained
- ///
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- template
- ArrayBase& Insert(const SQInteger destpos, V* val) {
- sq_pushobject(vm, GetObject());
- PushVar(vm, val);
- sq_arrayinsert(vm, -2, destpos);
- sq_pop(vm,1); // pop array
- return *this;
- }
-
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- /// Removes the last element from the Array
- ///
- /// \return Object for the element that was removed (null if failed)
- ///
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- Object Pop() {
- HSQOBJECT slotObj;
- sq_pushobject(vm, GetObject());
- if(SQ_FAILED(sq_arraypop(vm, -1, true))) {
- sq_pop(vm, 1);
- return Object(); // Return a NULL object
- } else {
- sq_getstackobj(vm, -1, &slotObj);
- Object ret(slotObj, vm);
- sq_pop(vm, 2);
- return ret;
- }
- }
-
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- /// Removes an element at a specific index from the Array
- ///
- /// \param itemidx Index of the element being removed
- ///
- /// \return The Array itself so the call can be chained
- ///
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- ArrayBase& Remove(const SQInteger itemidx) {
- sq_pushobject(vm, GetObject());
- sq_arrayremove(vm, -1, itemidx);
- sq_pop(vm,1); // pop array
- return *this;
- }
-
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- /// Resizes the Array
- ///
- /// \param newsize Desired size of the Array in number of elements
- ///
- /// \return The Array itself so the call can be chained
- ///
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- ArrayBase& Resize(const SQInteger newsize) {
- sq_pushobject(vm, GetObject());
- sq_arrayresize(vm, -1, newsize);
- sq_pop(vm,1); // pop array
- return *this;
- }
-
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- /// Reverses the elements of the array in place
- ///
- /// \return The Array itself so the call can be chained
- ///
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- ArrayBase& Reverse() {
- sq_pushobject(vm, GetObject());
- sq_arrayreverse(vm, -1);
- sq_pop(vm,1); // pop array
- return *this;
- }
-
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- /// Returns the length of the Array
- ///
- /// \return Length in number of elements
- ///
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- SQInteger Length() const
- {
- sq_pushobject(vm, obj);
- SQInteger r = sq_getsize(vm, -1);
- sq_pop(vm, 1);
- return r;
- }
-};
-
-/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-/// Represents an array in Squirrel
-/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-class Array : public ArrayBase {
-public:
-
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- /// Default constructor (null)
- ///
- /// \remarks
- /// The Array is invalid until it is given a VM to exist in.
- ///
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- Array() {
- }
-
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- /// Constructs an Array
- ///
- /// \param v VM to create the Array in
- /// \param size An optional size hint
- ///
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- Array(HSQUIRRELVM v, const SQInteger size = 0) : ArrayBase(v) {
- sq_newarray(vm, size);
- sq_getstackobj(vm,-1,&obj);
- sq_addref(vm, &obj);
- sq_pop(vm,1);
- }
-
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- /// Construct the Array from an Object that already exists
- ///
- /// \param obj An Object that should already represent a Squirrel array
- ///
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- Array(const Object& obj) : ArrayBase(obj) {
- }
-
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- /// Construct the Array from a HSQOBJECT and HSQUIRRELVM that already exist
- ///
- /// \param o Squirrel object that should already represent a Squirrel array
- /// \param v Squirrel VM that contains the Squirrel object given
- ///
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- Array(HSQOBJECT o, HSQUIRRELVM v = DefaultVM::Get()) : ArrayBase(o, v) {
- }
-};
-
-/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-/// Used to get and push Array instances to and from the stack as references (arrays are always references in Squirrel)
-/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-template<>
-struct Var {
-
- Array value; ///< The actual value of get operations
-
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- /// Attempts to get the value off the stack at idx as an Array
- ///
- /// \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) {
- HSQOBJECT obj;
- sq_resetobject(&obj);
- sq_getstackobj(vm,idx,&obj);
- value = Array(obj, vm);
-#if !defined (SCRAT_NO_ERROR_CHECKING)
- SQObjectType value_type = sq_gettype(vm, idx);
- if (value_type != OT_ARRAY) {
- SQTHROW(vm, FormatTypeError(vm, idx, _SC("array")));
- }
-#endif
- }
-
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- /// Called by Sqrat::PushVar to put an Array reference on the stack
- ///
- /// \param vm Target VM
- /// \param value Value to push on to the VM's stack
- ///
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- static void push(HSQUIRRELVM vm, const Array& value) {
- HSQOBJECT obj;
- sq_resetobject(&obj);
- obj = value.GetObject();
- sq_pushobject(vm,obj);
- }
-};
-
-/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-/// Used to get and push Array instances to and from the stack as references (arrays are always references in Squirrel)
-/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-template<>
-struct Var : Var {Var(HSQUIRRELVM vm, SQInteger idx) : Var(vm, idx) {}};
-
-/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-/// Used to get and push Array instances to and from the stack as references (arrays are always references in Squirrel)
-/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-template<>
-struct Var : Var {Var(HSQUIRRELVM vm, SQInteger idx) : Var(vm, idx) {}};
-
-}
-
-#endif
diff --git a/dependencies/sqrat/include/sqrat/sqratBytecode.h b/dependencies/sqrat/include/sqrat/sqratBytecode.h
deleted file mode 100644
index 69631cc..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
-///
-/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-inline 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
-///
-/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-inline 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
deleted file mode 100644
index ef7febf..0000000
--- a/dependencies/sqrat/include/sqrat/sqratClass.h
+++ /dev/null
@@ -1,1118 +0,0 @@
-//
-// SqratClass: Class Binding
-//
-
-//
-// 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_CLASS_H_)
-#define _SCRAT_CLASS_H_
-
-#include
-#include
-#include
-
-#include "sqratObject.h"
-#include "sqratClassType.h"
-#include "sqratMemberMethods.h"
-#include "sqratAllocator.h"
-#include "sqratTypes.h"
-
-namespace Sqrat
-{
-
-/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-/// Facilitates exposing a C++ class with no base class to Squirrel
-///
-/// \tparam C Class type to expose
-/// \tparam A An allocator to use when instantiating and destroying class instances of this type in Squirrel
-///
-/// \remarks
-/// DefaultAllocator is used if no allocator is specified. This should be sufficent for most classes,
-/// but if specific behavior is desired, it can be overridden. If the class should not be instantiated from
-/// Squirrel the NoConstructor allocator may be used. See NoCopy and CopyOnly too.
-///
-/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-template >
-class Class : public Object
-{
-private:
-
- static SQInteger cleanup_hook(SQUserPointer ptr, SQInteger size) {
- SQUNUSED(size);
- ClassData** ud = reinterpret_cast**>(ptr);
- delete *ud;
- return 0;
- }
-
-public:
-
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- /// Constructs the Class object
- ///
- /// A Class object doesnt do anything on its own.
- /// It must be told what methods and variables it contains.
- /// This is done using Class methods such as Class::Func and Class::Var.
- /// Then the Class must be exposed to Squirrel.
- /// This is usually done by calling TableBase::Bind on a RootTable with the Class.
- ///
- /// \param v Squirrel virtual machine to create the Class for
- /// \param className A necessarily unique name for the class that can appear in error messages
- /// \param createClass Should class type data be created? (almost always should be true - don't worry about it)
- ///
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- 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);
- if (SQ_FAILED(sq_rawget(v, -2))) {
- sq_newtable(v);
- sq_pushstring(v, _SC("__classes"), -1);
- sq_push(v, -2);
- sq_rawset(v, -4);
- }
- sq_pushstring(v, className.c_str(), -1);
- ClassData** ud = reinterpret_cast**>(sq_newuserdata(v, sizeof(ClassData*)));
- *ud = new ClassData;
- sq_setreleasehook(v, -1, &cleanup_hook);
- sq_rawset(v, -3);
- sq_pop(v, 2);
-
- ClassData* cd = *ud;
-
- if (ClassType::getStaticClassData().Expired()) {
- cd->staticData.Init(new StaticClassData);
- cd->staticData->copyFunc = &A::Copy;
- cd->staticData->className = string(className);
- cd->staticData->baseClass = NULL;
-
- ClassType::getStaticClassData() = cd->staticData;
- } else {
- cd->staticData = ClassType::getStaticClassData().Lock();
- }
-
- HSQOBJECT& classObj = cd->classObj;
- sq_resetobject(&classObj);
-
- sq_newclass(v, false);
- sq_getstackobj(v, -1, &classObj);
- sq_addref(v, &classObj); // must addref before the pop!
- sq_pop(v, 1);
- InitClass(cd);
- }
- }
-
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- /// Gets the Squirrel object for this Class (copy)
- ///
- /// \return Squirrel object representing the Squirrel class
- ///
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- virtual HSQOBJECT GetObject() const {
- return ClassType::getClassData(vm)->classObj;
- }
-
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- /// Gets the Squirrel object for this Class (reference)
- ///
- /// \return Squirrel object representing the Squirrel class
- ///
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- virtual HSQOBJECT& GetObject() {
- return ClassType::getClassData(vm)->classObj;
- }
-
-public:
-
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- /// Assigns a static class slot a value
- ///
- /// \param name Name of the static slot
- /// \param val Value to assign
- ///
- /// \tparam V Type of value (usually doesnt need to be defined explicitly)
- ///
- /// \return The Class itself so the call can be chained
- ///
- /// \remarks
- /// Static values are read-only in Squirrel.
- ///
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- template
- Class& SetStaticValue(const SQChar* name, const V& val) {
- BindValue(name, val, true);
- return *this;
- }
-
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- /// Assigns a class slot a value
- ///
- /// \param name Name of the slot
- /// \param val Value to assign
- ///
- /// \tparam V Type of value (usually doesnt need to be defined explicitly)
- ///
- /// \return The Class itself so the call can be chained
- ///
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- template
- Class& SetValue(const SQChar* name, const V& val) {
- BindValue(name, val, false);
- return *this;
- }
-
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- /// Binds a class variable
- ///
- /// \param name Name of the variable as it will appear in Squirrel
- /// \param var Variable to bind
- ///
- /// \tparam V Type of variable (usually doesnt need to be defined explicitly)
- ///
- /// \remarks
- /// If V is not a pointer or reference, then it must have a default constructor.
- /// See Sqrat::Class::Prop to work around this requirement
- ///
- /// \return The Class itself so the call can be chained
- ///
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- template
- Class& Var(const SQChar* name, V C::* var) {
- ClassData* cd = ClassType::getClassData(vm);
-
- // Add the getter
- BindAccessor(name, &var, sizeof(var), &sqDefaultGet, cd->getTable);
-
- // Add the setter
- BindAccessor(name, &var, sizeof(var), &sqDefaultSet, cd->setTable);
-
- return *this;
- }
-
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- /// Binds a class variable without a setter
- ///
- /// \param name Name of the variable as it will appear in Squirrel
- /// \param var Variable to bind
- ///
- /// \tparam V Type of variable (usually doesnt need to be defined explicitly)
- ///
- /// \remarks
- /// If V is not a pointer or reference, then it must have a default constructor.
- /// See Sqrat::Class::Prop to work around this requirement
- ///
- /// \return The Class itself so the call can be chained
- ///
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- template
- Class& ConstVar(const SQChar* name, V C::* var) {
- ClassData* cd = ClassType::getClassData(vm);
-
- // Add the getter
- BindAccessor(name, &var, sizeof(var), &sqDefaultGet, cd->getTable);
-
- return *this;
- }
-
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- /// Bind a class static variable
- ///
- /// \param name Name of the variable as it will appear in Squirrel
- /// \param var Variable to bind
- ///
- /// \tparam V Type of variable (usually doesnt need to be defined explicitly)
- ///
- /// \remarks
- /// If V is not a pointer or reference, then it must have a default constructor.
- /// See Sqrat::Class::Prop to work around this requirement
- ///
- /// \return The Class itself so the call can be chained
- ///
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- template
- Class& StaticVar(const SQChar* name, V* var) {
- ClassData* cd = ClassType::getClassData(vm);
-
- // Add the getter
- BindAccessor(name, &var, sizeof(var), &sqStaticGet, cd->getTable);
-
- // Add the setter
- BindAccessor(name, &var, sizeof(var), &sqStaticSet, cd->setTable);
-
- return *this;
- }
-
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- /// Binds a class property
- ///
- /// \param name Name of the variable as it will appear in Squirrel
- /// \param getMethod Getter for the variable
- /// \param setMethod Setter for the variable
- ///
- /// \tparam F1 Type of get function (usually doesnt need to be defined explicitly)
- /// \tparam F2 Type of set function (usually doesnt need to be defined explicitly)
- ///
- /// \return The Class itself so the call can be chained
- ///
- /// \remarks
- /// This method binds setter and getter functions in C++ to Squirrel as if they are a class variable.
- ///
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- template
- Class& Prop(const SQChar* name, F1 getMethod, F2 setMethod) {
- ClassData* cd = ClassType::getClassData(vm);
-
- if(getMethod != NULL) {
- // Add the getter
- BindAccessor(name, &getMethod, sizeof(getMethod), SqMemberOverloadedFunc(getMethod), cd->getTable);
- }
-
- if(setMethod != NULL) {
- // Add the setter
- BindAccessor(name, &setMethod, sizeof(setMethod), SqMemberOverloadedFunc(setMethod), cd->setTable);
- }
-
- return *this;
- }
-
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- /// Binds a Squirrel function as defined by the Squirrel documentation as a class property
- ///
- /// \param name Name of the variable as it will appear in Squirrel
- /// \param getter Getter for the variable
- /// \param setter Setter for the variable
- ///
- /// \return The Class itself so the call can be chained
- ///
- /// \remarks
- /// This method binds a squirrel setter and getter functions in C++ to Squirrel as if it is a class variable.
- /// Inside of the function, the class instance the function was called with will be at index 1 on the stack.
- ///
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- Class& SquirrelProp(const SQChar* name, SQFUNCTION getter, SQFUNCTION setter)
- {
- ClassData* cd = ClassType::getClassData(vm);
-
- if (getter != NULL) {
- // Add the getter
- sq_pushobject(vm, cd->getTable);
- sq_pushstring(vm, name, -1);
- sq_newclosure(vm, getter, 0);
- sq_newslot(vm, -3, false);
- sq_pop(vm, 1);
- }
-
- if (setter != NULL) {
- // Add the setter
- sq_pushobject(vm, cd->setTable);
- sq_pushstring(vm, name, -1);
- sq_newclosure(vm, setter, 0);
- sq_newslot(vm, -3, false);
- sq_pop(vm, 1);
- }
-
- return *this;
- }
-
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- /// Binds a class property (using global functions instead of member functions)
- ///
- /// \param name Name of the variable as it will appear in Squirrel
- /// \param getMethod Getter for the variable
- /// \param setMethod Setter for the variable
- ///
- /// \tparam F1 Type of get function (usually doesnt need to be defined explicitly)
- /// \tparam F2 Type of set function (usually doesnt need to be defined explicitly)
- ///
- /// \return The Class itself so the call can be chained
- ///
- /// \remarks
- /// This method binds setter and getter functions in C++ to Squirrel as if they are a class variable.
- ///
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- template
- Class& GlobalProp(const SQChar* name, F1 getMethod, F2 setMethod) {
- ClassData* cd = ClassType::getClassData(vm);
-
- if(getMethod != NULL) {
- // Add the getter
- BindAccessor(name, &getMethod, sizeof(getMethod), SqMemberGlobalOverloadedFunc(getMethod), cd->getTable);
- }
-
- if(setMethod != NULL) {
- // Add the setter
- BindAccessor(name, &setMethod, sizeof(setMethod), SqMemberGlobalOverloadedFunc(setMethod), cd->setTable);
- }
-
- return *this;
- }
-
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- /// Binds a read-only class property
- ///
- /// \param name Name of the variable as it will appear in Squirrel
- /// \param getMethod Getter for the variable
- ///
- /// \tparam F Type of get function (usually doesnt need to be defined explicitly)
- ///
- /// \return The Class itself so the call can be chained
- ///
- /// \remarks
- /// This method binds a getter function in C++ to Squirrel as if it is a class variable.
- ///
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- template
- Class& Prop(const SQChar* name, F getMethod) {
- // Add the getter
- BindAccessor(name, &getMethod, sizeof(getMethod), SqMemberOverloadedFunc(getMethod), ClassType::getClassData(vm)->getTable);
-
- return *this;
- }
-
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- /// Binds a Squirrel function as defined by the Squirrel documentation as a read-only class property
- ///
- /// \param name Name of the variable as it will appear in Squirrel
- /// \param getter Getter for the variable
- ///
- /// \return The Class itself so the call can be chained
- ///
- /// \remarks
- /// This method binds a squirrel getter function in C++ to Squirrel as if it is a class variable.
- /// Inside of the function, the class instance the function was called with will be at index 1 on the stack.
- ///
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- Class& SquirrelProp(const SQChar* name, SQFUNCTION getter)
- {
- sq_pushobject(vm, ClassType::getClassData(vm)->getTable);
- sq_pushstring(vm, name, -1);
- sq_newclosure(vm, getter, 0);
- sq_newslot(vm, -3, false);
- sq_pop(vm, 1);
-
- return *this;
- }
-
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- /// Binds a read-only class property (using a global function instead of a member function)
- ///
- /// \param name Name of the variable as it will appear in Squirrel
- /// \param getMethod Getter for the variable
- ///
- /// \tparam F Type of get function (usually doesnt need to be defined explicitly)
- ///
- /// \return The Class itself so the call can be chained
- ///
- /// \remarks
- /// This method binds a getter function in C++ to Squirrel as if it is a class variable.
- ///
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- template
- Class& GlobalProp(const SQChar* name, F getMethod) {
- // Add the getter
- BindAccessor(name, &getMethod, sizeof(getMethod), SqMemberGlobalOverloadedFunc(getMethod), ClassType::getClassData(vm)->getTable);
-
- return *this;
- }
-
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- /// Binds a class function
- ///
- /// \param name Name of the function as it will appear in Squirrel
- /// \param method Function to bind
- ///
- /// \tparam F Type of function (usually doesnt need to be defined explicitly)
- ///
- /// \return The Class itself so the call can be chained
- ///
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- template
- Class& Func(const SQChar* name, F method) {
- BindFunc(name, &method, sizeof(method), SqMemberFunc(method));
- return *this;
- }
-
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- /// Binds a class function with overloading enabled
- ///
- /// \param name Name of the function as it will appear in Squirrel
- /// \param method Function to bind
- ///
- /// \tparam F Type of function (usually doesnt need to be defined explicitly)
- ///
- /// \return The Class itself so the call can be chained
- ///
- /// \remarks
- /// Overloading in this context means to allow the function name to be used with functions
- /// of a different number of arguments. This definition differs from others (e.g. C++'s).
- ///
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- template
- Class& Overload(const SQChar* name, F method) {
- BindOverload(name, &method, sizeof(method), SqMemberOverloadedFunc(method), SqOverloadFunc(method), SqGetArgCount(method));
- return *this;
- }
-
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- /// Binds a global function as a class function
- ///
- /// \param name Name of the function as it will appear in Squirrel
- /// \param method Function to bind
- ///
- /// \tparam F Type of function (usually doesnt need to be defined explicitly)
- ///
- /// \return The Class itself so the call can be chained
- ///
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- template
- Class& GlobalFunc(const SQChar* name, F method) {
- BindFunc(name, &method, sizeof(method), SqMemberGlobalFunc(method));
- return *this;
- }
-
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- /// Binds a static class function
- ///
- /// \param name Name of the function as it will appear in Squirrel
- /// \param method Function to bind
- ///
- /// \tparam F Type of function (usually doesnt need to be defined explicitly)
- ///
- /// \return The Class itself so the call can be chained
- ///
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- template
- Class& StaticFunc(const SQChar* name, F method) {
- BindFunc(name, &method, sizeof(method), SqGlobalFunc(method));
- return *this;
- }
-
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- /// Binds a global function as a class function with overloading enabled
- ///
- /// \param name Name of the function as it will appear in Squirrel
- /// \param method Function to bind
- ///
- /// \tparam F Type of function (usually doesnt need to be defined explicitly)
- ///
- /// \return The Class itself so the call can be chained
- ///
- /// \remarks
- /// Overloading in this context means to allow the function name to be used with functions
- /// of a different number of arguments. This definition differs from others (e.g. C++'s).
- ///
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- template
- Class& GlobalOverload(const SQChar* name, F method) {
- BindOverload(name, &method, sizeof(method), SqMemberGlobalOverloadedFunc(method), SqOverloadFunc(method), SqGetArgCount(method) - 1);
- return *this;
- }
-
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- /// Binds a static class function with overloading enabled
- ///
- /// \param name Name of the function as it will appear in Squirrel
- /// \param method Function to bind
- ///
- /// \tparam F Type of function (usually doesnt need to be defined explicitly)
- ///
- /// \return The Class itself so the call can be chained
- ///
- /// \remarks
- /// Overloading in this context means to allow the function name to be used with functions
- /// of a different number of arguments. This definition differs from others (e.g. C++'s).
- ///
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- template
- Class& StaticOverload(const SQChar* name, F method) {
- BindOverload(name, &method, sizeof(method), SqGlobalOverloadedFunc(method), SqOverloadFunc(method), SqGetArgCount(method));
- return *this;
- }
-
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- /// Binds a Squirrel function as defined by the Squirrel documentation as a class function
- ///
- /// \param name Name of the function as it will appear in Squirrel
- /// \param func Function to bind
- /// \param nparamscheck The parameters count used in runtime arguments count checking (including hidden this parameter)
- /// \param type The type mask used in runtime parameters type checking
- ///
- /// \return The Class itself so the call can be chained
- ///
- /// \remarks
- /// Inside of the function, the class instance the function was called with will be at index 1 on the
- /// stack and all arguments will be after that index in the order they were given to the function.
- ///
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- Class& SquirrelFunc(const SQChar* name, SQFUNCTION func, SQInteger nparamscheck = 0, const SQChar* typemask = 0) {
- sq_pushobject(vm, ClassType::getClassData(vm)->classObj);
- sq_pushstring(vm, name, -1);
- sq_newclosure(vm, func, 0);
- sq_setparamscheck(vm, nparamscheck, typemask);
- sq_newslot(vm, -3, false);
- sq_pop(vm, 1); // pop table
-
- return *this;
- }
-
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- /// Gets a Function from a name in the Class
- ///
- /// \param name The name in the class that contains the Function
- ///
- /// \return Function found in the Class (null if failed)
- ///
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- Function GetFunction(const SQChar* name) {
- ClassData* cd = ClassType::getClassData(vm);
- HSQOBJECT funcObj;
- sq_pushobject(vm, cd->classObj);
- sq_pushstring(vm, name, -1);
-#if !defined (SCRAT_NO_ERROR_CHECKING)
- if(SQ_FAILED(sq_get(vm, -2))) {
- sq_pop(vm, 1);
- return Function();
- }
- SQObjectType value_type = sq_gettype(vm, -1);
- if (value_type != OT_CLOSURE && value_type != OT_NATIVECLOSURE) {
- sq_pop(vm, 2);
- return Function();
- }
-#else
- sq_get(vm, -2);
-#endif
- sq_getstackobj(vm, -1, &funcObj);
- Function ret(vm, cd->classObj, funcObj); // must addref before the pop!
- sq_pop(vm, 2);
- return ret;
- }
-
-protected:
-
-/// @cond DEV
-
- static SQInteger ClassWeakref(HSQUIRRELVM vm) {
- sq_weakref(vm, -1);
- return 1;
- }
-
- static SQInteger ClassTypeof(HSQUIRRELVM vm) {
- sq_pushstring(vm, ClassType::ClassName().c_str(), -1);
- return 1;
- }
-
- static SQInteger ClassCloned(HSQUIRRELVM vm) {
- SQTRY()
- Sqrat::Var other(vm, 2);
- SQCATCH_NOEXCEPT(vm) {
- SQCLEAR(vm);
- return SQ_ERROR;
- }
-#if !defined (SCRAT_NO_ERROR_CHECKING)
- return ClassType::CopyFunc()(vm, 1, other.value);
-#else
- ClassType::CopyFunc()(vm, 1, other.value);
- return 0;
-#endif
- SQCATCH(vm) {
-#if defined (SCRAT_USE_EXCEPTIONS)
- SQUNUSED(e); // this is to avoid a warning in MSVC
-#endif
- return SQ_ERROR;
- }
- }
-
- // Initialize the required data structure for the class
- void InitClass(ClassData* cd) {
- cd->instances.Init(new typename unordered_map::type);
-
- // push the class
- sq_pushobject(vm, cd->classObj);
-
- // set the typetag of the class
- sq_settypetag(vm, -1, cd->staticData.Get());
-
- // add the default constructor
- sq_pushstring(vm, _SC("constructor"), -1);
- sq_newclosure(vm, &A::New, 0);
- sq_newslot(vm, -3, false);
-
- // add the set table (static)
- HSQOBJECT& setTable = cd->setTable;
- sq_resetobject(&setTable);
- sq_pushstring(vm, _SC("__setTable"), -1);
- sq_newtable(vm);
- sq_getstackobj(vm, -1, &setTable);
- sq_addref(vm, &setTable);
- sq_newslot(vm, -3, true);
-
- // add the get table (static)
- HSQOBJECT& getTable = cd->getTable;
- sq_resetobject(&getTable);
- sq_pushstring(vm, _SC("__getTable"), -1);
- sq_newtable(vm);
- sq_getstackobj(vm, -1, &getTable);
- sq_addref(vm, &getTable);
- sq_newslot(vm, -3, true);
-
- // override _set
- sq_pushstring(vm, _SC("_set"), -1);
- sq_pushobject(vm, setTable); // Push the set table as a free variable
- sq_newclosure(vm, &sqVarSet, 1);
- sq_newslot(vm, -3, false);
-
- // override _get
- sq_pushstring(vm, _SC("_get"), -1);
- sq_pushobject(vm, getTable); // Push the get table as a free variable
- sq_newclosure(vm, &sqVarGet, 1);
- sq_newslot(vm, -3, false);
-
- // add weakref (apparently not provided by default)
- sq_pushstring(vm, _SC("weakref"), -1);
- sq_newclosure(vm, &Class::ClassWeakref, 0);
- sq_newslot(vm, -3, false);
-
- // add _typeof
- sq_pushstring(vm, _SC("_typeof"), -1);
- sq_newclosure(vm, &Class::ClassTypeof, 0);
- sq_newslot(vm, -3, false);
-
- // add _cloned
- sq_pushstring(vm, _SC("_cloned"), -1);
- sq_newclosure(vm, &Class::ClassCloned, 0);
- sq_newslot(vm, -3, false);
-
- // pop the class
- sq_pop(vm, 1);
- }
-
- // Helper function used to bind getters and setters
- inline void BindAccessor(const SQChar* name, void* var, size_t varSize, SQFUNCTION func, HSQOBJECT table) {
- // Push the get or set table
- sq_pushobject(vm, table);
- sq_pushstring(vm, name, -1);
-
- // Push the variable offset as a free variable
- SQUserPointer varPtr = sq_newuserdata(vm, static_cast(varSize));
- memcpy(varPtr, var, varSize);
-
- // Create the accessor function
- sq_newclosure(vm, func, 1);
-
- // Add the accessor to the table
- sq_newslot(vm, -3, false);
-
- // Pop get/set table
- sq_pop(vm, 1);
- }
-
- // constructor binding
- Class& BindConstructor(SQFUNCTION method, SQInteger nParams, const SQChar *name = 0) {
- SQFUNCTION overload = SqOverloadFunc(method);
- bool alternative_global = false;
- if (name == 0)
- name = _SC("constructor");
- else alternative_global = true;
- string overloadName = SqOverloadName::Get(name, nParams);
-
- if (!alternative_global )
- {
- // push the class
- sq_pushobject(vm, ClassType::getClassData(vm)->classObj);
- }
- else
- {
- // the containing environment is the root table??
- sq_pushroottable(vm);
- }
-
- // Bind overload handler
- sq_pushstring(vm, name, -1);
- sq_pushstring(vm, name, -1); // function name is passed as a free variable
- sq_newclosure(vm, overload, 1);
- sq_newslot(vm, -3, false);
-
- // Bind overloaded allocator function
- sq_pushstring(vm, overloadName.c_str(), -1);
- sq_newclosure(vm, method, 0);
- sq_setparamscheck(vm,nParams + 1,NULL);
- sq_newslot(vm, -3, false);
- sq_pop(vm, 1);
- return *this;
- }
-
-/// @endcond
-
-public:
-
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- /// Binds a constructor with no arguments (there can only be one constructor of this many arguments for a given name)
- ///
- /// \param name Name of the constructor as it will appear in Squirrel (default value creates a traditional constructor)
- ///
- /// \return The Class itself so the call can be chained
- ///
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- Class& Ctor(const SQChar *name = 0) {
- return BindConstructor(A::iNew, 0, name);
- }
-
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- /// Binds a constructor with 1 argument (there can only be one constructor of this many arguments for a given name)
- ///
- /// \param name Name of the constructor as it will appear in Squirrel (default value creates a traditional constructor)
- ///
- /// \tparam A1 Type of argument 1 of the constructor (must be defined explicitly)
- ///
- /// \return The Class itself so the call can be chained
- ///
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- template