Initial rework:

- removed squirrel & sqrat sources, added sqapi as git submodule dependency
- removed module api (it's now included from sqapi target)
- removed unnecessary boilerplate from CMakeLists.txt
This commit is contained in:
Patrix
2024-03-01 14:29:54 +01:00
parent 963f2b7fbf
commit 7a5f02f7f3
37 changed files with 8 additions and 20574 deletions

3
.gitmodules vendored Normal file
View File

@@ -0,0 +1,3 @@
[submodule "dependencies/sqapi"]
path = dependencies/sqapi
url = https://gitlab.com/GothicMultiplayerTeam/dependencies/sqapi.git

View File

@@ -2,11 +2,6 @@ cmake_minimum_required(VERSION 3.17)
project(squirrel-template) 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 file(GLOB SRC
"src/api/squirrel_api.h" "src/api/squirrel_api.h"
@@ -23,12 +18,6 @@ target_compile_definitions(squirrel-template
SCRAT_EXPORT SCRAT_EXPORT
) )
target_precompile_headers(squirrel-template
PRIVATE
"src/api/module_api.h"
"src/api/squirrel_api.h"
)
target_include_directories(squirrel-template target_include_directories(squirrel-template
INTERFACE INTERFACE
"include/" "include/"
@@ -45,33 +34,3 @@ if(DEFINED OUT_FILE_SUFFIX)
SUFFIX ".${OUT_FILE_SUFFIX}${CMAKE_SHARED_LIBRARY_SUFFIX}" SUFFIX ".${OUT_FILE_SUFFIX}${CMAKE_SHARED_LIBRARY_SUFFIX}"
) )
endif() 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()

View File

@@ -1,5 +1,3 @@
add_subdirectory(squirrel) add_subdirectory(sqapi)
add_subdirectory(sqrat)
target_link_libraries(squirrel-template PUBLIC Squirrel) target_link_libraries(squirrel-template PUBLIC sqapi)
target_link_libraries(squirrel-template PUBLIC SqRat)

1
dependencies/sqapi vendored Submodule

Submodule dependencies/sqapi added at af0918cc40

View File

@@ -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/"
)

View File

@@ -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_*/

View File

@@ -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?<br>
* 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 <squirrel.h>
#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

View File

@@ -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 <squirrel.h>
#include <string.h>
#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<int x>
class receive_size{};
template< class U >
static int sfinae( receive_size< sizeof U() > * );
template< class U >
static char sfinae( ... );
public:
enum { value = sizeof( sfinae<T>(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 C>
class DefaultAllocator {
template <class T, bool b>
struct NewC
{
T* p;
NewC()
{
p = new T();
}
};
template <class T>
struct NewC<T, false>
{
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<C>* cd = ClassType<C>::getClassData(vm);
sq_setinstanceup(vm, idx, new std::pair<C*, SharedPtr<typename unordered_map<C*, HSQOBJECT>::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<C, is_default_constructible<C>::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 <typename A1>
static SQInteger iNew(HSQUIRRELVM vm) {
SQTRY()
Var<A1> 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 <typename A1,typename A2>
static SQInteger iNew(HSQUIRRELVM vm) {
SQTRY()
Var<A1> a1(vm, 2);
Var<A2> 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 <typename A1,typename A2,typename A3>
static SQInteger iNew(HSQUIRRELVM vm) {
SQTRY()
Var<A1> a1(vm, 2);
Var<A2> a2(vm, 3);
Var<A3> 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 <typename A1,typename A2,typename A3,typename A4>
static SQInteger iNew(HSQUIRRELVM vm) {
SQTRY()
Var<A1> a1(vm, 2);
Var<A2> a2(vm, 3);
Var<A3> a3(vm, 4);
Var<A4> 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 <typename A1,typename A2,typename A3,typename A4,typename A5>
static SQInteger iNew(HSQUIRRELVM vm) {
SQTRY()
Var<A1> a1(vm, 2);
Var<A2> a2(vm, 3);
Var<A3> a3(vm, 4);
Var<A4> a4(vm, 5);
Var<A5> 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 <typename A1,typename A2,typename A3,typename A4,typename A5,typename A6>
static SQInteger iNew(HSQUIRRELVM vm) {
SQTRY()
Var<A1> a1(vm, 2);
Var<A2> a2(vm, 3);
Var<A3> a3(vm, 4);
Var<A4> a4(vm, 5);
Var<A5> a5(vm, 6);
Var<A6> 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 <typename A1,typename A2,typename A3,typename A4,typename A5,typename A6,typename A7>
static SQInteger iNew(HSQUIRRELVM vm) {
SQTRY()
Var<A1> a1(vm, 2);
Var<A2> a2(vm, 3);
Var<A3> a3(vm, 4);
Var<A4> a4(vm, 5);
Var<A5> a5(vm, 6);
Var<A6> a6(vm, 7);
Var<A7> 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 <typename A1,typename A2,typename A3,typename A4,typename A5,typename A6,typename A7,typename A8>
static SQInteger iNew(HSQUIRRELVM vm) {
SQTRY()
Var<A1> a1(vm, 2);
Var<A2> a2(vm, 3);
Var<A3> a3(vm, 4);
Var<A4> a4(vm, 5);
Var<A5> a5(vm, 6);
Var<A6> a6(vm, 7);
Var<A7> a7(vm, 8);
Var<A8> 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 <typename A1,typename A2,typename A3,typename A4,typename A5,typename A6,typename A7,typename A8,typename A9>
static SQInteger iNew(HSQUIRRELVM vm) {
SQTRY()
Var<A1> a1(vm, 2);
Var<A2> a2(vm, 3);
Var<A3> a3(vm, 4);
Var<A4> a4(vm, 5);
Var<A5> a5(vm, 6);
Var<A6> a6(vm, 7);
Var<A7> a7(vm, 8);
Var<A8> a8(vm, 9);
Var<A9> 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<const C*>(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<C*, SharedPtr<typename unordered_map<C*, HSQOBJECT>::type> >* instance = reinterpret_cast<std::pair<C*, SharedPtr<typename unordered_map<C*, HSQOBJECT>::type> >*>(ptr);
instance->second->erase(instance->first);
delete instance->first;
delete instance;
return 0;
}
};
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// NoConstructor is the allocator to use for Class that can NOT be constructed or copied
///
/// \tparam C Type of class
///
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
template<class C>
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<C>* cd = ClassType<C>::getClassData(vm);
sq_setinstanceup(vm, idx, new std::pair<C*, SharedPtr<typename unordered_map<C*, HSQOBJECT>::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<C>::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<C>::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<C*, SharedPtr<typename unordered_map<C*, HSQOBJECT>::type> >* instance = reinterpret_cast<std::pair<C*, SharedPtr<typename unordered_map<C*, HSQOBJECT>::type> >*>(ptr);
instance->second->erase(instance->first);
delete instance->first;
delete instance;
return 0;
}
};
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// CopyOnly is the allocator to use for Class that can be copied but not constructed
///
/// \tparam C Type of class
///
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
template<class C>
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<C>* cd = ClassType<C>::getClassData(vm);
sq_setinstanceup(vm, idx, new std::pair<C*, SharedPtr<typename unordered_map<C*, HSQOBJECT>::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<C>::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<const C*>(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<C*, SharedPtr<typename unordered_map<C*, HSQOBJECT>::type> >* instance = reinterpret_cast<std::pair<C*, SharedPtr<typename unordered_map<C*, HSQOBJECT>::type> >*>(ptr);
instance->second->erase(instance->first);
delete instance->first;
delete instance;
return 0;
}
};
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// 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 C>
class NoCopy {
template <class T, bool b>
struct NewC
{
T* p;
NewC()
{
p = new T();
}
};
template <class T>
struct NewC<T, false>
{
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<C>* cd = ClassType<C>::getClassData(vm);
sq_setinstanceup(vm, idx, new std::pair<C*, SharedPtr<typename unordered_map<C*, HSQOBJECT>::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<C, is_default_constructible<C>::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 <typename A1>
static SQInteger iNew(HSQUIRRELVM vm) {
SQTRY()
Var<A1> 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 <typename A1,typename A2>
static SQInteger iNew(HSQUIRRELVM vm) {
SQTRY()
Var<A1> a1(vm, 2);
Var<A2> 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 <typename A1,typename A2,typename A3>
static SQInteger iNew(HSQUIRRELVM vm) {
SQTRY()
Var<A1> a1(vm, 2);
Var<A2> a2(vm, 3);
Var<A3> 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 <typename A1,typename A2,typename A3,typename A4>
static SQInteger iNew(HSQUIRRELVM vm) {
SQTRY()
Var<A1> a1(vm, 2);
Var<A2> a2(vm, 3);
Var<A3> a3(vm, 4);
Var<A4> 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 <typename A1,typename A2,typename A3,typename A4,typename A5>
static SQInteger iNew(HSQUIRRELVM vm) {
SQTRY()
Var<A1> a1(vm, 2);
Var<A2> a2(vm, 3);
Var<A3> a3(vm, 4);
Var<A4> a4(vm, 5);
Var<A5> 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 <typename A1,typename A2,typename A3,typename A4,typename A5,typename A6>
static SQInteger iNew(HSQUIRRELVM vm) {
SQTRY()
Var<A1> a1(vm, 2);
Var<A2> a2(vm, 3);
Var<A3> a3(vm, 4);
Var<A4> a4(vm, 5);
Var<A5> a5(vm, 6);
Var<A6> 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 <typename A1,typename A2,typename A3,typename A4,typename A5,typename A6,typename A7>
static SQInteger iNew(HSQUIRRELVM vm) {
SQTRY()
Var<A1> a1(vm, 2);
Var<A2> a2(vm, 3);
Var<A3> a3(vm, 4);
Var<A4> a4(vm, 5);
Var<A5> a5(vm, 6);
Var<A6> a6(vm, 7);
Var<A7> 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 <typename A1,typename A2,typename A3,typename A4,typename A5,typename A6,typename A7,typename A8>
static SQInteger iNew(HSQUIRRELVM vm) {
SQTRY()
Var<A1> a1(vm, 2);
Var<A2> a2(vm, 3);
Var<A3> a3(vm, 4);
Var<A4> a4(vm, 5);
Var<A5> a5(vm, 6);
Var<A6> a6(vm, 7);
Var<A7> a7(vm, 8);
Var<A8> 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 <typename A1,typename A2,typename A3,typename A4,typename A5,typename A6,typename A7,typename A8,typename A9>
static SQInteger iNew(HSQUIRRELVM vm) {
SQTRY()
Var<A1> a1(vm, 2);
Var<A2> a2(vm, 3);
Var<A3> a3(vm, 4);
Var<A4> a4(vm, 5);
Var<A5> a5(vm, 6);
Var<A6> a6(vm, 7);
Var<A7> a7(vm, 8);
Var<A8> a8(vm, 9);
Var<A9> 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<C>::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<C*, SharedPtr<typename unordered_map<C*, HSQOBJECT>::type> >* instance = reinterpret_cast<std::pair<C*, SharedPtr<typename unordered_map<C*, HSQOBJECT>::type> >*>(ptr);
instance->second->erase(instance->first);
delete instance->first;
delete instance;
return 0;
}
};
}
#endif

View File

@@ -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 <squirrel.h>
#include <string.h>
#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<class V>
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<class V>
ArrayBase& SetInstance(const SQInteger index, V* val) {
BindInstance<V>(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<class F>
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 <typename T>
SharedPtr<T> 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<T>();
}
#else
sq_get(vm, -2);
#endif
SQTRY()
Var<SharedPtr<T> > element(vm, -1);
SQCATCH_NOEXCEPT(vm) {
sq_pop(vm, 2);
return SharedPtr<T>();
}
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<T>(); // 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 <typename T>
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<const T&> 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<class V>
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<class V>
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<class V>
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<class V>
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> {
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<Array&> : Var<Array> {Var(HSQUIRRELVM vm, SQInteger idx) : Var<Array>(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<const Array&> : Var<Array> {Var(HSQUIRRELVM vm, SQInteger idx) : Var<Array>(vm, idx) {}};
}
#endif

View File

@@ -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 <squirrel.h>
#include <stdlib.h>
#include <string.h>
namespace Sqrat {
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Helper class for managing Squirrel scripts bytecode
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
class Bytecode {
public:
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Default constructor
///
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Bytecode()
: m_data(0)
, m_size(0)
, m_readpos(0)
{
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Default destructor
///
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
~Bytecode() {
if (m_data) {
free(m_data);
}
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Returns pointer to bytecode
///
/// \returns Pointer to bytecode data
///
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
inline void * Data() const {
return m_data;
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Copies bytecode from provided buffer
///
/// \param data Pointer to buffer containing bytecode
/// \param size Size of buffer containing bytecode
/// \returns SQ_OK on success, SQ_ERROR on failure
///
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
SQRESULT SetData(const void * data, size_t size) {
if (m_data) {
free(m_data);
}
m_data = static_cast<char *>(malloc(size));
memcpy(m_data, data, size);
m_size = size;
m_readpos = 0;
return SQ_OK;
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Appends bytecode from provided buffer
///
/// \param data Pointer to buffer containing bytecode to append
/// \param size Size of buffer containing bytecode to append
/// \returns Number of bytes appended
///
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
SQInteger AppendData(const void * data, size_t size) {
if (!m_data) {
m_data = static_cast<char *>(malloc(size));
}
else {
m_data = static_cast<char *>(realloc(m_data, m_size + size));
}
memcpy(m_data + m_size, data, size);
m_size += size;
return static_cast<SQInteger>(size);
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Reads bytecode
///
/// \param data Pointer to receiving buffer
/// \param size Number of bytes to read
/// \returns Number of read bytes or -1 if error occurs or there is no more data available
///
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
SQInteger ReadData(void * data, size_t size) {
if (!m_data || m_size == 0 || m_readpos == m_size)
return -1;
size_t bytes_to_read = (m_readpos + size <= m_size) ? size : m_size - m_readpos;
memcpy(data, m_data + m_readpos, bytes_to_read);
m_readpos += bytes_to_read;
return static_cast<SQInteger>(bytes_to_read);
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Returns bytecode size
///
/// \returns Bytecode size in bytes
///
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
inline size_t Size() const {
return m_size;
}
private:
char * m_data; // Buffer holding bytecode
size_t m_size; // Bytecode size
size_t m_readpos; // Current bytecode ReadData() position
};
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Helper bytecode reader callback to use with sq_readclosure
///
/// \param user_data Pointer to \a Bytecode object to read from
/// \param data Pointer to receiving buffer
/// \param size Number of bytes to read
///
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
inline SQInteger BytecodeReader(SQUserPointer user_data, SQUserPointer data, SQInteger size) {
Bytecode * bytecode = reinterpret_cast<Bytecode *>(user_data);
return bytecode->ReadData(data, static_cast<size_t>(size));;
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Helper bytecode writer callback to use with sq_writeclosure
///
/// \param user_data Pointer to \a Bytecode object to write to
/// \param data Pointer to bytecode data
/// \param size Number of bytes to write
///
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
inline SQInteger BytecodeWriter(SQUserPointer user_data, SQUserPointer data, SQInteger size) {
Bytecode * bytecode = reinterpret_cast<Bytecode *>(user_data);
return bytecode->AppendData(data, static_cast<size_t>(size));
}
}
#endif //_SCRAT_BYTECODE_H_

File diff suppressed because it is too large Load Diff

View File

@@ -1,259 +0,0 @@
//
// SqratClassType: Type Translators
//
//
// 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_CLASSTYPE_H_)
#define _SCRAT_CLASSTYPE_H_
#include <squirrel.h>
#include <typeinfo>
#include "sqratUtil.h"
namespace Sqrat
{
/// @cond DEV
// The copy function for a class
typedef SQInteger (*COPYFUNC)(HSQUIRRELVM, SQInteger, const void*);
// Every Squirrel class instance made by Sqrat has its type tag set to a AbstractStaticClassData object that is unique per C++ class
struct AbstractStaticClassData {
AbstractStaticClassData() {}
virtual ~AbstractStaticClassData() {}
virtual SQUserPointer Cast(SQUserPointer ptr, SQUserPointer classType) = 0;
AbstractStaticClassData* baseClass;
string className;
COPYFUNC copyFunc;
};
// StaticClassData keeps track of the nearest base class B and the class associated with itself C in order to cast C++ pointers to the right base class
template<class C, class B>
struct StaticClassData : public AbstractStaticClassData {
virtual SQUserPointer Cast(SQUserPointer ptr, SQUserPointer classType) {
if (classType != this) {
ptr = baseClass->Cast(static_cast<B*>(static_cast<C*>(ptr)), classType);
}
return ptr;
}
};
// Every Squirrel class object created by Sqrat in every VM has its own unique ClassData object stored in the registry table of the VM
template<class C>
struct ClassData {
HSQOBJECT classObj;
HSQOBJECT getTable;
HSQOBJECT setTable;
SharedPtr<typename unordered_map<C*, HSQOBJECT>::type> instances;
SharedPtr<AbstractStaticClassData> staticData;
};
// Lookup static class data by type_info rather than a template because C++ cannot export generic templates
class _ClassType_helper {
public:
#if defined(SCRAT_IMPORT)
static SQRAT_API WeakPtr<AbstractStaticClassData>& _getStaticClassData(const std::type_info* type);
#else
struct compare_type_info {
bool operator ()(const std::type_info* left, const std::type_info* right) const {
return left->before(*right) != 0;
}
};
static SQRAT_API WeakPtr<AbstractStaticClassData>& _getStaticClassData(const std::type_info* type) {
static std::map<const std::type_info*, WeakPtr<AbstractStaticClassData>, compare_type_info> data;
return data[type];
}
#endif
};
// Internal helper class for managing classes
template<class C>
class ClassType {
public:
static inline ClassData<C>* getClassData(HSQUIRRELVM vm) {
sq_pushregistrytable(vm);
sq_pushstring(vm, _SC("__classes"), -1);
#ifndef NDEBUG
SQRESULT r = sq_rawget(vm, -2);
assert(SQ_SUCCEEDED(r)); // fails if getClassData is called when the data does not exist for the given VM yet (bind the class)
#else
sq_rawget(vm, -2);
#endif
sq_pushstring(vm, ClassName().c_str(), -1);
#ifndef NDEBUG
r = sq_rawget(vm, -2);
assert(SQ_SUCCEEDED(r)); // fails if getClassData is called when the data does not exist for the given VM yet (bind the class)
#else
sq_rawget(vm, -2);
#endif
ClassData<C>** ud;
sq_getuserdata(vm, -1, (SQUserPointer*)&ud, NULL);
sq_pop(vm, 3);
return *ud;
}
static WeakPtr<AbstractStaticClassData>& getStaticClassData() {
return _ClassType_helper::_getStaticClassData(&typeid(C));
}
static inline bool hasClassData(HSQUIRRELVM vm) {
if (!getStaticClassData().Expired()) {
sq_pushregistrytable(vm);
sq_pushstring(vm, _SC("__classes"), -1);
if (SQ_SUCCEEDED(sq_rawget(vm, -2))) {
sq_pushstring(vm, ClassName().c_str(), -1);
if (SQ_SUCCEEDED(sq_rawget(vm, -2))) {
sq_pop(vm, 3);
return true;
}
sq_pop(vm, 1);
}
sq_pop(vm, 1);
}
return false;
}
static inline AbstractStaticClassData*& BaseClass() {
assert(getStaticClassData().Expired() == false); // fails because called before a Sqrat::Class for this type exists
return getStaticClassData().Lock()->baseClass;
}
static inline string& ClassName() {
assert(getStaticClassData().Expired() == false); // fails because called before a Sqrat::Class for this type exists
return getStaticClassData().Lock()->className;
}
static inline COPYFUNC& CopyFunc() {
assert(getStaticClassData().Expired() == false); // fails because called before a Sqrat::Class for this type exists
return getStaticClassData().Lock()->copyFunc;
}
static SQInteger DeleteInstance(SQUserPointer ptr, SQInteger size) {
SQUNUSED(size);
std::pair<C*, SharedPtr<typename unordered_map<C*, HSQOBJECT>::type> >* instance = reinterpret_cast<std::pair<C*, SharedPtr<typename unordered_map<C*, HSQOBJECT>::type> >*>(ptr);
instance->second->erase(instance->first);
delete instance;
return 0;
}
static SQInteger DeleteInstanceFree(SQUserPointer ptr, SQInteger size) {
SQUNUSED(size);
std::pair<C*, SharedPtr<typename unordered_map<C*, HSQOBJECT>::type> >* instance = reinterpret_cast<std::pair<C*, SharedPtr<typename unordered_map<C*, HSQOBJECT>::type> >*>(ptr);
instance->second->erase(instance->first);
delete instance->first;
delete instance;
return 0;
}
static void PushInstance(HSQUIRRELVM vm, C* ptr, bool free = false) {
if (!ptr) {
sq_pushnull(vm);
return;
}
ClassData<C>* cd = getClassData(vm);
typename unordered_map<C*, HSQOBJECT>::type::iterator it = cd->instances->find(ptr);
if (it != cd->instances->end()) {
sq_pushobject(vm, it->second);
return;
}
sq_pushobject(vm, cd->classObj);
sq_createinstance(vm, -1);
sq_remove(vm, -2);
sq_setinstanceup(vm, -1, new std::pair<C*, SharedPtr<typename unordered_map<C*, HSQOBJECT>::type> >(ptr, cd->instances));
free ? sq_setreleasehook(vm, -1, &DeleteInstanceFree) : sq_setreleasehook(vm, -1, &DeleteInstance);
sq_getstackobj(vm, -1, &((*cd->instances)[ptr]));
}
static void PushInstanceCopy(HSQUIRRELVM vm, const C& value) {
sq_pushobject(vm, getClassData(vm)->classObj);
sq_createinstance(vm, -1);
sq_remove(vm, -2);
#ifndef NDEBUG
SQRESULT result = CopyFunc()(vm, -1, &value);
assert(SQ_SUCCEEDED(result)); // fails when trying to copy an object defined as non-copyable
#else
CopyFunc()(vm, -1, &value);
#endif
}
static C* GetInstance(HSQUIRRELVM vm, SQInteger idx, bool nullAllowed = false) {
AbstractStaticClassData* classType = NULL;
std::pair<C*, SharedPtr<typename unordered_map<C*, HSQOBJECT>::type> >* instance = NULL;
if (hasClassData(vm)) /* type checking only done if the value has type data else it may be enum */
{
if (nullAllowed && sq_gettype(vm, idx) == OT_NULL) {
return NULL;
}
classType = getStaticClassData().Lock().Get();
#if !defined (SCRAT_NO_ERROR_CHECKING)
if (SQ_FAILED(sq_getinstanceup(vm, idx, (SQUserPointer*)&instance, classType, SQTrue))) {
SQTHROW(vm, FormatTypeError(vm, idx, ClassName()));
return NULL;
}
if (instance == NULL) {
SQTHROW(vm, _SC("got unconstructed native class (call base.constructor in the constructor of Squirrel classes that extend native classes)"));
return NULL;
}
#else
sq_getinstanceup(vm, idx, (SQUserPointer*)&instance, 0);
#endif
}
else /* value is likely of integral type like enums, cannot return a pointer */
{
SQTHROW(vm, FormatTypeError(vm, idx, _SC("unknown")));
return NULL;
}
AbstractStaticClassData* actualType;
sq_gettypetag(vm, idx, (SQUserPointer*)&actualType);
if (actualType == NULL) {
SQInteger top = sq_gettop(vm);
sq_getclass(vm, idx);
while (actualType == NULL) {
sq_getbase(vm, -1);
sq_gettypetag(vm, -1, (SQUserPointer*)&actualType);
}
sq_settop(vm, top);
}
if (classType != actualType) {
return static_cast<C*>(actualType->Cast(instance->first, classType));
}
return static_cast<C*>(instance->first);
}
};
/// @endcond
}
#endif

View File

@@ -1,200 +0,0 @@
//
// SqratConst: Constant and Enumeration 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_CONST_H_)
#define _SCRAT_CONST_H_
#include <squirrel.h>
#include <string.h>
#include "sqratObject.h"
namespace Sqrat {
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Facilitates exposing a C++ enumeration to Squirrel
///
/// \remarks
/// The Enumeration class only facilitates binding C++ enumerations that contain only integers,
/// floats, and strings because the Squirrel constant table can only contain these types of
/// values. Other types of enumerations can be bound using Class::SetStaticValue instead.
///
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
class Enumeration : public Object {
public:
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Constructs the Enumeration object
///
/// An Enumeration object doesnt do anything on its own.
/// It must be told what constant values it contains.
/// This is done using Enumeration::Const.
/// Then the Enumeration must be exposed to Squirrel.
/// This is done by calling ConstTable::Enum with the Enumeration.
///
/// \param v Squirrel virtual machine to create the Enumeration for
/// \param createTable Whether the underlying table that values are bound to is created by the constructor
///
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Enumeration(HSQUIRRELVM v = DefaultVM::Get(), bool createTable = true) : Object(v, false) {
if(createTable) {
sq_newtable(vm);
sq_getstackobj(vm,-1,&obj);
sq_addref(vm, &obj);
sq_pop(vm,1);
}
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Binds an enumeration value
///
/// \param name Name of the value as it will appear in Squirrel
/// \param val Value to bind
///
/// \return The Enumeration itself so the call can be chained
///
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
virtual Enumeration& Const(const SQChar* name, const int val) {
BindValue<int>(name, val, false);
return *this;
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Binds an enumeration value
///
/// \param name Name of the value as it will appear in Squirrel
/// \param val Value to bind
///
/// \return The Enumeration itself so the call can be chained
///
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
virtual Enumeration& Const(const SQChar* name, const float val) {
BindValue<float>(name, val, false);
return *this;
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Binds an enumeration value
///
/// \param name Name of the value as it will appear in Squirrel
/// \param val Value to bind
///
/// \return The Enumeration itself so the call can be chained
///
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
virtual Enumeration& Const(const SQChar* name, const SQChar* val) {
BindValue<const SQChar*>(name, val, false);
return *this;
}
};
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Facilitates exposing a C++ constant to Squirrel
///
/// \remarks
/// The ConstTable class only facilitates binding C++ constants that are integers,
/// floats, and strings because the Squirrel constant table can only contain these types of
/// values. Other types of constants can be bound using Class::SetStaticValue instead.
///
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
class ConstTable : public Enumeration {
public:
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Constructs a ConstTable object to represent the given VM's const table
///
/// \param v VM to get the ConstTable for
///
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
ConstTable(HSQUIRRELVM v = DefaultVM::Get()) : Enumeration(v, false) {
sq_pushconsttable(vm);
sq_getstackobj(vm,-1, &obj);
sq_pop(v,1); // No addref needed, since the consttable is always around
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Binds a constant value
///
/// \param name Name of the value as it will appear in Squirrel
/// \param val Value to bind
///
/// \return The ConstTable itself so the call can be chained
///
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
virtual ConstTable& Const(const SQChar* name, const int val) {
Enumeration::Const(name, val);
return *this;
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Binds a constant value
///
/// \param name Name of the value as it will appear in Squirrel
/// \param val Value to bind
///
/// \return The ConstTable itself so the call can be chained
///
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
virtual ConstTable& Const(const SQChar* name, const float val) {
Enumeration::Const(name, val);
return *this;
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Binds a constant value
///
/// \param name Name of the value as it will appear in Squirrel
/// \param val Value to bind
///
/// \return The ConstTable itself so the call can be chained
///
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
virtual ConstTable& Const(const SQChar* name, const SQChar* val) {
Enumeration::Const(name, val);
return *this;
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Binds an Enumeration to the ConstTable
///
/// \param name Name of the enumeration as it will appear in Squirrel
/// \param en Enumeration to bind
///
/// \return The ConstTable itself so the call can be chained
///
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
ConstTable& Enum(const SQChar* name, Enumeration& en) {
sq_pushobject(vm, GetObject());
sq_pushstring(vm, name, -1);
sq_pushobject(vm, en.GetObject());
sq_newslot(vm, -3, false);
sq_pop(vm,1); // pop table
return *this;
}
};
}
#endif

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -1,601 +0,0 @@
//
// SqratObject: Referenced Squirrel Object Wrapper
//
//
// 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_OBJECT_H_)
#define _SCRAT_OBJECT_H_
#include <squirrel.h>
#include <string.h>
#include "sqratAllocator.h"
#include "sqratTypes.h"
#include "sqratOverloadMethods.h"
#include "sqratUtil.h"
#ifdef WIN32
// Windows defines fix
#undef GetObject
#endif
namespace Sqrat {
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// The base class for classes that represent Squirrel objects
///
/// \remarks
/// All Object and derived classes MUST be destroyed before calling sq_close or your application will crash when exiting.
///
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
class Object {
protected:
/// @cond DEV
HSQUIRRELVM vm;
HSQOBJECT obj;
bool release;
Object(HSQUIRRELVM v, bool releaseOnDestroy = true) : vm(v), release(releaseOnDestroy) {
sq_resetobject(&obj);
}
/// @endcond
public:
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Default constructor (null)
///
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Object() : vm(0), release(true) {
sq_resetobject(&obj);
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Copy constructor
///
/// \param so Object to copy
///
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Object(const Object& so) : vm(so.vm), obj(so.obj), release(so.release) {
sq_addref(vm, &obj);
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Constructs an Object from a Squirrel object
///
/// \param o Squirrel object
/// \param v VM that the object will exist in
///
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Object(HSQOBJECT o, HSQUIRRELVM v = DefaultVM::Get()) : vm(v), obj(o), release(true) {
sq_addref(vm, &obj);
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Constructs an Object from a C++ instance
///
/// \param instance Pointer to a C++ class instance that has been bound already
/// \param v VM that the object will exist in
///
/// \tparam T Type of instance
///
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
template<class T>
Object(T* instance, HSQUIRRELVM v = DefaultVM::Get(), bool free = false) : vm(v), release(true) {
ClassType<T>::PushInstance(vm, instance, free);
sq_getstackobj(vm, -1, &obj);
sq_addref(vm, &obj);
sq_pop(vm, 1);
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Destructor
///
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
virtual ~Object() {
if(release) {
Release();
release = false;
}
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Assignment operator
///
/// \param so Object to copy
///
/// \return The Object itself
///
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Object& operator=(const Object& so) {
if( this != &so ) {
if(release) {
Release();
}
vm = so.vm;
obj = so.obj;
sq_addref(vm, &GetObject());
}
return *this;
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Gets the Squirrel VM for this Object (reference)
///
/// \return Squirrel VM associated with the Object
///
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
HSQUIRRELVM& GetVM() {
return vm;
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Gets the Squirrel VM for this Object (copy)
///
/// \return Squirrel VM associated with the Object
///
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
HSQUIRRELVM GetVM() const {
return vm;
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Gets the type of the Object as defined by the Squirrel API
///
/// \return SQObjectType for the Object
///
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
SQObjectType GetType() const {
return GetObject()._type;
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Checks whether the Object is null
///
/// \return True if the Object currently has a null value, otherwise false
///
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
bool IsNull() const {
return sq_isnull(GetObject());
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Gets the Squirrel object for this Object (copy)
///
/// \return Squirrel object
///
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
virtual HSQOBJECT GetObject() const {
return obj;
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Gets the Squirrel object for this Object (reference)
///
/// \return Squirrel object
///
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
virtual HSQOBJECT& GetObject() {
return obj;
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Allows the Object to be inputted directly into places that expect a HSQOBJECT
///
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
operator HSQOBJECT&() {
return GetObject();
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Sets the Object to null (removing its references to underlying Squirrel objects)
///
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void Release() {
sq_release(vm, &obj);
sq_resetobject(&obj);
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Attempts to get the value of a slot from the object
///
/// \param slot Name of the slot
///
/// \return An Object representing the value of the slot (can be a null object if nothing was found)
///
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Object GetSlot(const SQChar* slot) const {
HSQOBJECT slotObj;
sq_pushobject(vm, GetObject());
sq_pushstring(vm, slot, -1);
#if !defined (SCRAT_NO_ERROR_CHECKING)
if(SQ_FAILED(sq_get(vm, -2))) {
sq_pop(vm, 1);
return Object(vm); // Return a NULL object
} else {
sq_getstackobj(vm, -1, &slotObj);
Object ret(slotObj, vm); // must addref before the pop!
sq_pop(vm, 2);
return ret;
}
#else
sq_get(vm, -2);
sq_getstackobj(vm, -1, &slotObj);
Object ret(slotObj, vm); // must addref before the pop!
sq_pop(vm, 2);
return ret;
#endif
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Attempts to get the value of an index from the object
///
/// \param index Index of the slot
///
/// \return An Object representing the value of the slot (can be a null object if nothing was found)
///
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Object GetSlot(SQInteger index) const {
HSQOBJECT slotObj;
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 Object(vm); // Return a NULL object
} else {
sq_getstackobj(vm, -1, &slotObj);
Object ret(slotObj, vm); // must addref before the pop!
sq_pop(vm, 2);
return ret;
}
#else
sq_get(vm, -2);
sq_getstackobj(vm, -1, &slotObj);
Object ret(slotObj, vm); // must addref before the pop!
sq_pop(vm, 2);
return ret;
#endif
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Checks if the object has a slot with a specified key
///
/// \param key Name of the key
///
/// \return True if the Object has a value associated with key, otherwise false
///
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
bool HasKey(const SQChar* key) const {
sq_pushobject(vm, GetObject());
sq_pushstring(vm, key, -1);
if (SQ_FAILED(sq_get(vm, -2))) {
sq_pop(vm, 1);
return false;
}
sq_pop(vm, 2);
return true;
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Checks if the object has a slot with a specified index
///
/// \param index Index to check
///
/// \return True if the Object has a value associated with index, otherwise false
///
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
bool HasKey(SQInteger index) const {
sq_pushobject(vm, GetObject());
sq_pushinteger(vm, index);
if (SQ_FAILED(sq_get(vm, -2))) {
sq_pop(vm, 1);
return false;
}
sq_pop(vm, 2);
return true;
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Casts the object to a certain C++ type
///
/// \tparam T Type to cast to
///
/// \return A copy of the value of the Object with the given type
///
/// \remarks
/// This function MUST have its Error handled if it occurred.
///
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
template <class T>
T Cast() const {
sq_pushobject(vm, GetObject());
T ret = Var<T>(vm, -1).value;
sq_pop(vm, 1);
return ret;
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Allows Object to be used like C++ arrays with the [] operator
///
/// \param slot The slot key
///
/// \tparam T Type of the slot key (usually doesnt need to be defined explicitly)
///
/// \return An Object representing the value of the slot (can be a null object if nothing was found)
///
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
template <class T>
inline Object operator[](T slot)
{
return GetSlot(slot);
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Returns the size of the Object
///
/// \return Size of Object
///
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
SQInteger GetSize() const {
sq_pushobject(vm, GetObject());
SQInteger ret = sq_getsize(vm, -1);
sq_pop(vm, 1);
return ret;
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Iterator for going over the slots in the object using Object::Next
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
struct iterator
{
/// @cond DEV
friend class Object;
/// @endcond
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Default constructor (null)
///
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
iterator()
{
Index = 0;
sq_resetobject(&Key);
sq_resetobject(&Value);
Key._type = OT_NULL;
Value._type = OT_NULL;
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Returns the string value of the key the iterator is on if possible
///
/// \return String or NULL
///
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
const SQChar* getName() { return sq_objtostring(&Key); }
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Gets the Squirrel object for the key the iterator is on
///
/// \return HSQOBJECT representing a key
///
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
HSQOBJECT getKey() { return Key; }
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Gets the Squirrel object for the value the iterator is on
///
/// \return HSQOBJECT representing a value
///
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
HSQOBJECT getValue() { return Value; }
private:
HSQOBJECT Key;
HSQOBJECT Value;
SQInteger Index;
};
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Used to go through all the slots in an Object (same limitations as sq_next)
///
/// \param iter An iterator being used for going through the slots
///
/// \return Whether there is a next slot
///
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
bool Next(iterator& iter) const
{
sq_pushobject(vm,obj);
sq_pushinteger(vm,iter.Index);
if(SQ_SUCCEEDED(sq_next(vm,-2)))
{
sq_getstackobj(vm,-1,&iter.Value);
sq_getstackobj(vm,-2,&iter.Key);
sq_getinteger(vm,-3,&iter.Index);
sq_pop(vm,4);
return true;
}
else
{
sq_pop(vm,2);
return false;
}
}
protected:
/// @cond DEV
// Bind a function and it's associated Squirrel closure to the object
inline void BindFunc(const SQChar* name, void* method, size_t methodSize, SQFUNCTION func, bool staticVar = false) {
sq_pushobject(vm, GetObject());
sq_pushstring(vm, name, -1);
SQUserPointer methodPtr = sq_newuserdata(vm, static_cast<SQUnsignedInteger>(methodSize));
memcpy(methodPtr, method, methodSize);
sq_newclosure(vm, func, 1);
sq_newslot(vm, -3, staticVar);
sq_pop(vm,1); // pop table
}
inline void BindFunc(const SQInteger index, void* method, size_t methodSize, SQFUNCTION func, bool staticVar = false) {
sq_pushobject(vm, GetObject());
sq_pushinteger(vm, index);
SQUserPointer methodPtr = sq_newuserdata(vm, static_cast<SQUnsignedInteger>(methodSize));
memcpy(methodPtr, method, methodSize);
sq_newclosure(vm, func, 1);
sq_newslot(vm, -3, staticVar);
sq_pop(vm,1); // pop table
}
// Bind a function and it's associated Squirrel closure to the object
inline void BindOverload(const SQChar* name, void* method, size_t methodSize, SQFUNCTION func, SQFUNCTION overload, int argCount, bool staticVar = false) {
string overloadName = SqOverloadName::Get(name, argCount);
sq_pushobject(vm, GetObject());
// 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, staticVar);
// Bind overloaded function
sq_pushstring(vm, overloadName.c_str(), -1);
SQUserPointer methodPtr = sq_newuserdata(vm, static_cast<SQUnsignedInteger>(methodSize));
memcpy(methodPtr, method, methodSize);
sq_newclosure(vm, func, 1);
sq_newslot(vm, -3, staticVar);
sq_pop(vm,1); // pop table
}
// Set the value of a variable on the object. Changes to values set this way are not reciprocated
template<class V>
inline void BindValue(const SQChar* name, const V& val, bool staticVar = false) {
sq_pushobject(vm, GetObject());
sq_pushstring(vm, name, -1);
PushVar(vm, val);
sq_newslot(vm, -3, staticVar);
sq_pop(vm,1); // pop table
}
template<class V>
inline void BindValue(const SQInteger index, const V& val, bool staticVar = false) {
sq_pushobject(vm, GetObject());
sq_pushinteger(vm, index);
PushVar(vm, val);
sq_newslot(vm, -3, staticVar);
sq_pop(vm,1); // pop table
}
// Set the value of an instance on the object. Changes to values set this way are reciprocated back to the source instance
template<class V>
inline void BindInstance(const SQChar* name, V* val, bool staticVar = false) {
sq_pushobject(vm, GetObject());
sq_pushstring(vm, name, -1);
PushVar(vm, val);
sq_newslot(vm, -3, staticVar);
sq_pop(vm,1); // pop table
}
template<class V>
inline void BindInstance(const SQInteger index, V* val, bool staticVar = false) {
sq_pushobject(vm, GetObject());
sq_pushinteger(vm, index);
PushVar(vm, val);
sq_newslot(vm, -3, staticVar);
sq_pop(vm,1); // pop table
}
/// @endcond
};
/// @cond DEV
template<>
inline void Object::BindValue<int>(const SQChar* name, const int & val, bool staticVar /* = false */) {
sq_pushobject(vm, GetObject());
sq_pushstring(vm, name, -1);
PushVar<int>(vm, val);
sq_newslot(vm, -3, staticVar);
sq_pop(vm,1); // pop table
}
/// @endcond
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Used to get and push Object instances to and from the stack as references (Object is always a reference)
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
template<>
struct Var<Object> {
Object value; ///< The actual value of get operations
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Attempts to get the value off the stack at idx as an Object
///
/// \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 sqValue;
sq_getstackobj(vm, idx, &sqValue);
value = Object(sqValue, vm);
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Called by Sqrat::PushVar to put an Object on the stack
///
/// \param vm Target VM
/// \param value Value to push on to the VM's stack
///
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
static void push(HSQUIRRELVM vm, const Object& value) {
sq_pushobject(vm, value.GetObject());
}
};
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Used to get and push Object instances to and from the stack as references (Object is always a reference)
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
template<>
struct Var<Object&> : Var<Object> {Var(HSQUIRRELVM vm, SQInteger idx) : Var<Object>(vm, idx) {}};
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Used to get and push Object instances to and from the stack as references (Object is always a reference)
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
template<>
struct Var<const Object&> : Var<Object> {Var(HSQUIRRELVM vm, SQInteger idx) : Var<Object>(vm, idx) {}};
}
#endif

File diff suppressed because it is too large Load Diff

View File

@@ -1,296 +0,0 @@
//
// SqratScript: Script Compilation and Execution
//
//
// 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_SCRIPT_H_)
#define _SCRAT_SCRIPT_H_
#include <squirrel.h>
#include <sqstdio.h>
#include <string.h>
#include "sqratObject.h"
#include "sqratBytecode.h"
namespace Sqrat {
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Helper class for managing Squirrel scripts
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
class Script : public Object {
public:
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Default constructor
///
/// \param v VM that the Script will be associated with
///
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Script(HSQUIRRELVM v = DefaultVM::Get()) : Object(v, true) {
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Sets up the Script using a string containing a Squirrel script
///
/// \param script String containing a file path to a Squirrel script
/// \param name Optional string containing the script's name (for errors)
///
/// \remarks
/// This function MUST have its Error handled if it occurred.
///
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void CompileString(const string& script, const string& name = _SC("")) {
if(!sq_isnull(obj)) {
sq_release(vm, &obj);
sq_resetobject(&obj);
}
#if !defined (SCRAT_NO_ERROR_CHECKING)
if(SQ_FAILED(sq_compilebuffer(vm, script.c_str(), static_cast<SQInteger>(script.size() /** sizeof(SQChar)*/), name.c_str(), true))) {
SQTHROW(vm, LastErrorString(vm));
return;
}
#else
sq_compilebuffer(vm, script.c_str(), static_cast<SQInteger>(script.size() /** sizeof(SQChar)*/), name.c_str(), true);
#endif
sq_getstackobj(vm,-1,&obj);
sq_addref(vm, &obj);
sq_pop(vm, 1);
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Sets up the Script using a string containing a Squirrel script
///
/// \param script String containing a file path to a Squirrel script
/// \param errMsg String that is filled with any errors that may occur
/// \param name Optional string containing the script's name (for errors)
///
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
bool CompileString(const string& script, string& errMsg, const string& name = _SC("")) {
if(!sq_isnull(obj)) {
sq_release(vm, &obj);
sq_resetobject(&obj);
}
#if !defined (SCRAT_NO_ERROR_CHECKING)
if(SQ_FAILED(sq_compilebuffer(vm, script.c_str(), static_cast<SQInteger>(script.size() /** sizeof(SQChar)*/), name.c_str(), true))) {
errMsg = LastErrorString(vm);
return false;
}
#else
sq_compilebuffer(vm, script.c_str(), static_cast<SQInteger>(script.size() /** sizeof(SQChar)*/), name.c_str(), true);
#endif
sq_getstackobj(vm,-1,&obj);
sq_addref(vm, &obj);
sq_pop(vm, 1);
return true;
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Sets up the Script using a file containing a Squirrel script
///
/// \param path File path containing a Squirrel script
///
/// \remarks
/// This function MUST have its Error handled if it occurred.
///
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void CompileFile(const string& path) {
if(!sq_isnull(obj)) {
sq_release(vm, &obj);
sq_resetobject(&obj);
}
#if !defined (SCRAT_NO_ERROR_CHECKING)
if(SQ_FAILED(sqstd_loadfile(vm, path.c_str(), true))) {
SQTHROW(vm, LastErrorString(vm));
return;
}
#else
sqstd_loadfile(vm, path.c_str(), true);
#endif
sq_getstackobj(vm,-1,&obj);
sq_addref(vm, &obj);
sq_pop(vm, 1);
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Sets up the Script using a file containing a Squirrel script
///
/// \param path File path containing a Squirrel script
/// \param errMsg String that is filled with any errors that may occur
///
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
bool CompileFile(const string& path, string& errMsg) {
if(!sq_isnull(obj)) {
sq_release(vm, &obj);
sq_resetobject(&obj);
}
#if !defined (SCRAT_NO_ERROR_CHECKING)
if(SQ_FAILED(sqstd_loadfile(vm, path.c_str(), true))) {
errMsg = LastErrorString(vm);
return false;
}
#else
sqstd_loadfile(vm, path.c_str(), true);
#endif
sq_getstackobj(vm,-1,&obj);
sq_addref(vm, &obj);
sq_pop(vm, 1);
return true;
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Runs the script
///
/// \remarks
/// This function MUST have its Error handled if it occurred.
///
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void Run() {
#if !defined (SCRAT_NO_ERROR_CHECKING)
if(!sq_isnull(obj)) {
SQRESULT result;
SQInteger top = sq_gettop(vm);
sq_pushobject(vm, obj);
sq_pushroottable(vm);
result = sq_call(vm, 1, false, true);
sq_settop(vm, top);
if(SQ_FAILED(result)) {
SQTHROW(vm, LastErrorString(vm));
return;
}
}
#else
SQInteger top = sq_gettop(vm);
sq_pushobject(vm, obj);
sq_pushroottable(vm);
sq_call(vm, 1, false, true);
sq_settop(vm, top);
#endif
}
#if !defined (SCRAT_NO_ERROR_CHECKING)
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Runs the script
///
/// \param errMsg String that is filled with any errors that may occur
///
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
bool Run(string& errMsg) {
if(!sq_isnull(obj)) {
SQRESULT result;
SQInteger top = sq_gettop(vm);
sq_pushobject(vm, obj);
sq_pushroottable(vm);
result = sq_call(vm, 1, false, true);
sq_settop(vm, top);
if(SQ_FAILED(result)) {
errMsg = LastErrorString(vm);
return false;
}
return true;
}
return false;
}
#endif
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Writes the byte code of the Script to a file
///
/// \param path File path to write to
///
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void WriteCompiledFile(const string& path) {
#if !defined (SCRAT_NO_ERROR_CHECKING)
if(!sq_isnull(obj)) {
sq_pushobject(vm, obj);
sqstd_writeclosuretofile(vm, path.c_str());
}
#else
sq_pushobject(vm, obj);
sqstd_writeclosuretofile(vm, path.c_str());
#endif
sq_pop(vm, 1); // needed?
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Saves script's bytecode to string
///
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
std::string SaveBytecode() {
Bytecode bytecode;
#if !defined (SCRAT_NO_ERROR_CHECKING)
if (!sq_isnull(obj)) {
sq_pushobject(vm, obj);
if (SQ_FAILED(sq_writeclosure(vm, BytecodeWriter, &bytecode))) {
SQTHROW(vm, LastErrorString(vm));
}
}
#else
sq_pushobject(vm, obj);
sq_writeclosure(vm, BytecodeWriter, &bytecode);
#endif
sq_pop(vm, 1); // needed?
return std::string(reinterpret_cast<char*>(bytecode.Data()), bytecode.Size());
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Loads script's bytecode from string
///
/// \param str String containing script's bytecode
///
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
bool LoadBytecode(const std::string& str) {
#if !defined (SCRAT_NO_ERROR_CHECKING)
if (str.empty()) {
return false;
}
#endif
if(!sq_isnull(obj)) {
sq_release(vm, &obj);
sq_resetobject(&obj);
}
Bytecode bytecode;
bytecode.SetData(str.c_str(), str.size());
#if !defined (SCRAT_NO_ERROR_CHECKING)
if (SQ_FAILED(sq_readclosure(vm, BytecodeReader, &bytecode))) {
return false;
}
#else
sq_readclosure(vm, BytecodeReader, &bytecode);
#endif
sq_getstackobj(vm,-1,&obj);
sq_addref(vm, &obj);
sq_pop(vm, 1);
return true;
}
};
}
#endif

View File

@@ -1,544 +0,0 @@
//
// SqratTable: Table 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_TABLE_H_)
#define _SCRAT_TABLE_H_
#include <squirrel.h>
#include <string.h>
#include "sqratObject.h"
#include "sqratFunction.h"
#include "sqratGlobalMethods.h"
namespace Sqrat {
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// The base class for Table that implements almost all of its functionality
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
class TableBase : public Object {
public:
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Default constructor (null)
///
/// \param v VM that the table will exist in
///
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
TableBase(HSQUIRRELVM v = DefaultVM::Get()) : Object(v, true) {
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Construct the TableBase from an Object that already exists
///
/// \param obj An Object that should already represent a Squirrel table
///
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
TableBase(const Object& obj) : Object(obj) {
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Construct the TableBase from a HSQOBJECT and HSQUIRRELVM that already exist
///
/// \param o Squirrel object that should already represent a Squirrel table
/// \param v Squirrel VM that contains the Squirrel object given
///
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
TableBase(HSQOBJECT o, HSQUIRRELVM v = DefaultVM::Get()) : Object(o, v) {
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Binds a Table or Class to the Table (can be used to facilitate namespaces)
///
/// \param name The key in the table being assigned a Table or Class
/// \param obj Table or Class that is being placed in the table
///
/// \remarks
/// Bind cannot be called "inline" like other functions because it introduces order-of-initialization bugs.
///
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void Bind(const SQChar* name, Object& obj) {
sq_pushobject(vm, GetObject());
sq_pushstring(vm, name, -1);
sq_pushobject(vm, obj.GetObject());
sq_newslot(vm, -3, false);
sq_pop(vm,1); // pop table
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Binds a raw Squirrel closure to the Table
///
/// \param name The key in the table being assigned a function
/// \param func Squirrel function that is being placed in the Table
/// \param nparamscheck The parameters count used in runtime arguments count checking (including hidden this parameter)
/// \param type The type mask used in runtime parameters type checking
///
/// \return The Table itself so the call can be chained
///
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
TableBase& SquirrelFunc(const SQChar* name, SQFUNCTION func, SQInteger nparamscheck = 0, const SQChar* typemask = 0) {
sq_pushobject(vm, GetObject());
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;
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Sets a key in the Table to a specific value
///
/// \param name The key in the table being assigned a value
/// \param val Value that is being placed in the Table
///
/// \tparam V Type of value (usually doesnt need to be defined explicitly)
///
/// \return The Table itself so the call can be chained
///
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
template<class V>
TableBase& SetValue(const SQChar* name, const V& val) {
BindValue<V>(name, val, false);
return *this;
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Sets an index in the Table to a specific value
///
/// \param index The index in the table being assigned a value
/// \param val Value that is being placed in the Table
///
/// \tparam V Type of value (usually doesnt need to be defined explicitly)
///
/// \return The Table itself so the call can be chained
///
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
template<class V>
TableBase& SetValue(const SQInteger index, const V& val) {
BindValue<V>(index, val, false);
return *this;
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Sets a key in the Table to a specific instance (like a reference)
///
/// \param name The key in the table being assigned a value
/// \param val Pointer to the instance that is being placed in the Table
///
/// \tparam V Type of instance (usually doesnt need to be defined explicitly)
///
/// \return The Table itself so the call can be chained
///
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
template<class V>
TableBase& SetInstance(const SQChar* name, V* val) {
BindInstance<V>(name, val, false);
return *this;
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Sets an index in the Table to a specific instance (like a reference)
///
/// \param index The index in the table being assigned a value
/// \param val Pointer to the instance that is being placed in the Table
///
/// \tparam V Type of instance (usually doesnt need to be defined explicitly)
///
/// \return The Table itself so the call can be chained
///
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
template<class V>
TableBase& SetInstance(const SQInteger index, V* val) {
BindInstance<V>(index, val, false);
return *this;
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Sets a key in the Table to a specific function
///
/// \param name The key in the table being assigned a value
/// \param method Function that is being placed in the Table
///
/// \tparam F Type of function (only define this if you need to choose a certain template specialization or overload)
///
/// \return The Table itself so the call can be chained
///
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
template<class F>
TableBase& Func(const SQChar* name, F method) {
BindFunc(name, &method, sizeof(method), SqGlobalFunc(method));
return *this;
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Sets a key in the Table to a specific function and allows the key to be overloaded with functions of a different amount of arguments
///
/// \param name The key in the table being assigned a value
/// \param method Function that is being placed in the Table
///
/// \tparam F Type of function (only define this if you need to choose a certain template specialization or overload)
///
/// \return The Table itself so the call can be chained
///
/// \remarks
/// Overloading in Sqrat does not work for functions with the same amount of arguments (just like in Squirrel).
///
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
template<class F>
TableBase& Overload(const SQChar* name, F method) {
BindOverload(name, &method, sizeof(method), SqGlobalOverloadedFunc(method), SqOverloadFunc(method), SqGetArgCount(method));
return *this;
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Checks if the given key exists in the table
///
/// \param name Key to check
///
/// \return True on success, otherwise false
///
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
bool HasKey(const SQChar* name)
{
sq_pushobject(vm, obj);
sq_pushstring(vm, name, -1);
if (SQ_FAILED(sq_get(vm, -2))) {
sq_pop(vm, 1);
return false;
}
sq_pop(vm, 2);
return true;
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Returns the value at a given key
///
/// \param name Key of the element
///
/// \tparam T Type of value (fails if value is not of this type)
///
/// \return SharedPtr containing the value (or null if failed)
///
/// \remarks
/// This function MUST have its Error handled if it occurred.
///
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
template <typename T>
SharedPtr<T> GetValue(const SQChar* name)
{
sq_pushobject(vm, obj);
sq_pushstring(vm, name, -1);
#if !defined (SCRAT_NO_ERROR_CHECKING)
if (SQ_FAILED(sq_get(vm, -2))) {
sq_pop(vm, 1);
SQTHROW(vm, _SC("illegal index"));
return SharedPtr<T>();
}
#else
sq_get(vm, -2);
#endif
SQTRY()
Var<SharedPtr<T> > entry(vm, -1);
SQCATCH_NOEXCEPT(vm) {
sq_pop(vm, 2);
return SharedPtr<T>();
}
sq_pop(vm, 2);
return entry.value;
SQCATCH(vm) {
#if defined (SCRAT_USE_EXCEPTIONS)
SQUNUSED(e); // avoid "unreferenced local variable" warning
#endif
sq_pop(vm, 2);
SQRETHROW(vm);
}
return SharedPtr<T>(); // avoid "not all control paths return a value" warning
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Returns the value at a given index
///
/// \param index Index of the element
///
/// \tparam T Type of value (fails if value is not of this type)
///
/// \return SharedPtr containing the value (or null if failed)
///
/// \remarks
/// This function MUST have its Error handled if it occurred.
///
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
template <typename T>
SharedPtr<T> 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<T>();
}
#else
sq_get(vm, -2);
#endif
SQTRY()
Var<SharedPtr<T> > entry(vm, -1);
SQCATCH_NOEXCEPT(vm) {
sq_pop(vm, 2);
return SharedPtr<T>();
}
sq_pop(vm, 2);
return entry.value;
SQCATCH(vm) {
#if defined (SCRAT_USE_EXCEPTIONS)
SQUNUSED(e); // avoid "unreferenced local variable" warning
#endif
sq_pop(vm, 2);
SQRETHROW(vm);
}
return SharedPtr<T>(); // avoid "not all control paths return a value" warning
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Gets a Function from a key in the Table
///
/// \param name The key in the table that contains the Function
///
/// \return Function found in the Table (null if failed)
///
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Function GetFunction(const SQChar* name) {
HSQOBJECT funcObj;
sq_pushobject(vm, GetObject());
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, GetObject(), funcObj); // must addref before the pop!
sq_pop(vm, 2);
return ret;
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Gets a Function from an index in the Table
///
/// \param index The index in the table that contains the Function
///
/// \return Function found in the Table (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;
}
};
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Represents a table in Squirrel
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
class Table : public TableBase {
public:
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Default constructor (null)
///
/// \remarks
/// The Table is invalid until it is given a VM to exist in.
///
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Table() {
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Constructs a Table
///
/// \param v VM to create the Table in
///
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Table(HSQUIRRELVM v) : TableBase(v) {
sq_newtable(vm);
sq_getstackobj(vm,-1,&obj);
sq_addref(vm, &obj);
sq_pop(vm,1);
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Construct the Table from an Object that already exists
///
/// \param obj An Object that should already represent a Squirrel table
///
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Table(const Object& obj) : TableBase(obj) {
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Construct the Table from a HSQOBJECT and HSQUIRRELVM that already exist
///
/// \param o Squirrel object that should already represent a Squirrel table
/// \param v Squirrel VM that contains the Squirrel object given
///
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Table(HSQOBJECT o, HSQUIRRELVM v = DefaultVM::Get()) : TableBase(o, v) {
}
};
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Table that is a reference to the Squirrel root table for a given VM
/// The Squirrel root table is usually where all globals are stored by the Squirrel language.
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
class RootTable : public TableBase {
public:
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Constructs a RootTable object to represent the given VM's root table
///
/// \param v VM to get the RootTable for
///
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
RootTable(HSQUIRRELVM v = DefaultVM::Get()) : TableBase(v) {
sq_pushroottable(vm);
sq_getstackobj(vm,-1,&obj);
sq_addref(vm, &obj);
sq_pop(v,1); // pop root table
}
};
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Table that is a reference to the Squirrel registry table for a given VM
/// The Squirrel registry table is where non-Squirrel code can store Squirrel objects without worrying about Squirrel code messing with them.
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
class RegistryTable : public TableBase {
public:
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Constructs a RegistryTable object to represent the given VM's registry table
///
/// \param v VM to get the RegistryTable for
///
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
RegistryTable(HSQUIRRELVM v = DefaultVM::Get()) : TableBase(v) {
sq_pushregistrytable(v);
sq_getstackobj(vm,-1,&obj);
sq_addref(vm, &obj);
sq_pop(v,1); // pop the registry table
}
};
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Used to get and push Table instances to and from the stack as references (tables are always references in Squirrel)
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
template<>
struct Var<Table> {
Table value; ///< The actual value of get operations
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Attempts to get the value off the stack at idx as a Table
///
/// \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 = Table(obj, vm);
#if !defined (SCRAT_NO_ERROR_CHECKING)
SQObjectType value_type = sq_gettype(vm, idx);
if (value_type != OT_TABLE) {
SQTHROW(vm, FormatTypeError(vm, idx, _SC("table")));
}
#endif
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Called by Sqrat::PushVar to put an Table 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 Table& value) {
HSQOBJECT obj;
sq_resetobject(&obj);
obj = value.GetObject();
sq_pushobject(vm,obj);
}
};
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Used to get and push Table instances to and from the stack as references (tables are always references in Squirrel)
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
template<>
struct Var<Table&> : Var<Table> {Var(HSQUIRRELVM vm, SQInteger idx) : Var<Table>(vm, idx) {}};
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Used to get and push Table instances to and from the stack as references (tables are always references in Squirrel)
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
template<>
struct Var<const Table&> : Var<Table> {Var(HSQUIRRELVM vm, SQInteger idx) : Var<Table>(vm, idx) {}};
}
#endif

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -1,352 +0,0 @@
//
// wrapper for the Squirrel VM under Sqrat
//
//
// Copyright (c) 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_VM_H_)
#define _SCRAT_VM_H_
#include <squirrel.h>
#include <sqrat.h>
#include <iostream>
#include <stdarg.h>
#include <stdio.h>
#include <sqstdio.h>
#include <sqstdblob.h>
#include <sqstdmath.h>
#include <sqstdsystem.h>
#include <sqstdstring.h>
namespace Sqrat
{
#ifdef SQUNICODE
#define scvprintf vwprintf
#else
#define scvprintf vprintf
#endif
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Helper class that wraps a Squirrel virtual machine in a C++ API
///
/// \remarks
/// This class is not currently thread-safe for the case of different VMs running in different threads (all others are)
///
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
class SqratVM
{
private:
HSQUIRRELVM m_vm;
Sqrat::RootTable* m_rootTable;
Sqrat::Script* m_script;
Sqrat::string m_lastErrorMsg;
static void s_addVM(HSQUIRRELVM vm, SqratVM* sqratvm)
{
// TODO for user: use mutex to lock ms_sqratVMs if necessary for your uses
ms_sqratVMs().insert(std::make_pair(vm, sqratvm));
}
static void s_deleteVM(HSQUIRRELVM vm)
{
// TODO for user: use mutex to lock ms_sqratVMs if necessary for your uses
ms_sqratVMs().erase(vm);
}
static SqratVM* s_getVM(HSQUIRRELVM vm)
{
// TODO for user: use mutex to lock ms_sqratVMs if necessary for your uses
return ms_sqratVMs()[vm];
}
private:
static SQRAT_API unordered_map<HSQUIRRELVM, SqratVM*>::type& ms_sqratVMs();
static void printFunc(HSQUIRRELVM /*v*/, const SQChar *s, ...)
{
va_list vl;
va_start(vl, s);
scvprintf(s, vl);
va_end(vl);
}
static SQInteger runtimeErrorHandler(HSQUIRRELVM v)
{
const SQChar *sErr = 0;
if(sq_gettop(v) >= 1)
{
Sqrat::string& errStr = s_getVM(v)->m_lastErrorMsg;
if(SQ_SUCCEEDED(sq_getstring(v, 2, &sErr)))
{
errStr = sErr;
}
else
{
errStr = _SC("an unknown runtime error has occured");
}
}
return 0;
}
static void compilerErrorHandler(HSQUIRRELVM v,
const SQChar* desc,
const SQChar* source,
SQInteger line,
SQInteger column)
{
SQChar buf[512];
#ifdef _MSC_VER
scsprintf(buf, 512, _SC("%s:%d:%d: %s"), source, (int) line, (int) column, desc);
#else
scsprintf(buf, _SC("%s:%d:%d: %s"), source, (int) line, (int) column, desc);
#endif
buf[sizeof(buf)/sizeof(SQChar) - 1] = 0;
s_getVM(v)->m_lastErrorMsg = buf;
}
public:
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Enumeration representing the different types of errors that may occur within a SqratVM
///
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
enum ERROR_STATE
{
SQRAT_NO_ERROR, ///< For when no error has occurred
SQRAT_COMPILE_ERROR, ///< For when a script compiling error has occurred
SQRAT_RUNTIME_ERROR ///< For when a script running error has occurred
};
static const unsigned char LIB_IO = 0x01; ///< Input/Output library
static const unsigned char LIB_BLOB = 0x02; ///< Blob library
static const unsigned char LIB_MATH = 0x04; ///< Math library
static const unsigned char LIB_SYST = 0x08; ///< System library
static const unsigned char LIB_STR = 0x10; ///< String library
static const unsigned char LIB_ALL = LIB_IO | LIB_BLOB | LIB_MATH | LIB_SYST | LIB_STR; ///< All libraries
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Default constructor
///
/// \param initialStackSize Initial size of the execution stack (if the stack is too small it will automatically grow)
/// \param libsToLoad Specifies what standard Squirrel libraries should be loaded
///
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
SqratVM(int initialStackSize = 1024, unsigned char libsToLoad = LIB_ALL): m_vm(sq_open(initialStackSize))
, m_rootTable(new Sqrat::RootTable(m_vm))
, m_script(new Sqrat::Script(m_vm))
, m_lastErrorMsg()
{
s_addVM(m_vm, this);
//register std libs
sq_pushroottable(m_vm);
if (libsToLoad & LIB_IO)
sqstd_register_iolib(m_vm);
if (libsToLoad & LIB_BLOB)
sqstd_register_bloblib(m_vm);
if (libsToLoad & LIB_MATH)
sqstd_register_mathlib(m_vm);
if (libsToLoad & LIB_SYST)
sqstd_register_systemlib(m_vm);
if (libsToLoad & LIB_STR)
sqstd_register_stringlib(m_vm);
sq_pop(m_vm, 1);
SetPrintFunc(printFunc, printFunc);
SetErrorHandler(runtimeErrorHandler, compilerErrorHandler);
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Destructor
///
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
~SqratVM()
{
s_deleteVM(m_vm);
delete m_script;
delete m_rootTable;
sq_close(m_vm);
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Gets the underlying Squirrel VM
///
/// \return Underlying Squirrel VM
///
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
HSQUIRRELVM GetVM()
{
return m_vm;
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Gets the root table for this VM
///
/// \return RootTable for the VM
///
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Sqrat::RootTable& GetRootTable()
{
return *m_rootTable;
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Gets the associated Script for this VM
///
/// \return Script for the VM
///
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Sqrat::Script& GetScript()
{
return *m_script;
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Gets the error message for the most recent Squirrel error with the VM
///
/// \return String containing a nice error message
///
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Sqrat::string GetLastErrorMsg()
{
return m_lastErrorMsg;
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Overwrites the most recent Squirrel error for this VM
///
/// \param str A nice error message
///
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void SetLastErrorMsg(const Sqrat::string& str)
{
m_lastErrorMsg = str;
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Sets the print function of the virtual machine (a default one is set in the constructor)
///
/// \param printFunc A pointer to the print func or NULL to disable the output
/// \param errFunc A pointer to the error func or NULL to disable the output
///
/// \remarks
/// The print function is used by the built-in Squirrel print function to output text.
///
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void SetPrintFunc(SQPRINTFUNCTION printFunc, SQPRINTFUNCTION errFunc)
{
sq_setprintfunc(m_vm, printFunc, errFunc);
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Sets the Squirrel error handlers (both are set to defaults in the constructor)
///
/// \param runErr A pointer to the runtime error handler func
/// \param comErr A pointer to the compile error handler func
///
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void SetErrorHandler(SQFUNCTION runErr, SQCOMPILERERROR comErr)
{
sq_newclosure(m_vm, runErr, 0);
sq_seterrorhandler(m_vm);
sq_setcompilererrorhandler(m_vm, comErr);
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Runs a string containing a Squirrel script
///
/// \param str String containing a Squirrel script
///
/// \return An ERROR_STATE representing what happened
///
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
ERROR_STATE DoString(const Sqrat::string& str)
{
Sqrat::string msg;
m_lastErrorMsg.clear();
if(!m_script->CompileString(str, msg))
{
if(m_lastErrorMsg.empty())
{
m_lastErrorMsg = msg;
}
return SQRAT_COMPILE_ERROR;
}
if(!m_script->Run(msg))
{
if(m_lastErrorMsg.empty())
{
m_lastErrorMsg = msg;
}
return SQRAT_RUNTIME_ERROR;
}
return SQRAT_NO_ERROR;
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Runs a file containing a Squirrel script
///
/// \param file File path containing a Squirrel script
///
/// \return An ERROR_STATE representing what happened
///
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
ERROR_STATE DoFile(const Sqrat::string& file)
{
Sqrat::string msg;
m_lastErrorMsg.clear();
if(!m_script->CompileFile(file, msg))
{
if(m_lastErrorMsg.empty())
{
m_lastErrorMsg = msg;
}
return SQRAT_COMPILE_ERROR;
}
if(!m_script->Run(msg))
{
if(m_lastErrorMsg.empty())
{
m_lastErrorMsg = msg;
}
return SQRAT_RUNTIME_ERROR;
}
return SQRAT_NO_ERROR;
}
};
#if !defined(SCRAT_IMPORT)
inline unordered_map<HSQUIRRELVM, SqratVM*>::type& SqratVM::ms_sqratVMs() {
static unordered_map<HSQUIRRELVM, SqratVM*>::type ms;
return ms;
}
#endif
}
#endif

View File

@@ -1,51 +0,0 @@
//
// SqImport: Supports importing of 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_IMPORT_H_)
#define _SQ_IMPORT_H_
#include <squirrel.h>
#ifdef __cplusplus
extern "C" {
#endif
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// To be documented...
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
SQUIRREL_API SQRESULT sqrat_import(HSQUIRRELVM v);
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// To be documented...
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
SQUIRREL_API SQRESULT sqrat_register_importlib(HSQUIRRELVM v);
#ifdef __cplusplus
} /*extern "C"*/
#endif
#endif /*_SQ_IMPORT_H_*/

View File

@@ -1,16 +0,0 @@
cmake_minimum_required(VERSION 3.17)
project(Squirrel)
file(GLOB_RECURSE SRC
"include/*.h"
)
add_library(Squirrel INTERFACE)
target_sources(Squirrel INTERFACE ${SRC})
target_include_directories(Squirrel
INTERFACE
"./"
"include/"
)

View File

@@ -1,146 +0,0 @@
#ifdef _SQ64
#ifdef _MSC_VER
typedef __int64 SQInteger;
typedef unsigned __int64 SQUnsignedInteger;
typedef unsigned __int64 SQHash; /*should be the same size of a pointer*/
#else
typedef long long SQInteger;
typedef unsigned long long SQUnsignedInteger;
typedef unsigned long long SQHash; /*should be the same size of a pointer*/
#endif
typedef int SQInt32;
typedef unsigned int SQUnsignedInteger32;
#else
typedef int SQInteger;
typedef int SQInt32; /*must be 32 bits(also on 64bits processors)*/
typedef unsigned int SQUnsignedInteger32; /*must be 32 bits(also on 64bits processors)*/
typedef unsigned int SQUnsignedInteger;
typedef unsigned int SQHash; /*should be the same size of a pointer*/
#endif
#ifdef SQUSEDOUBLE
typedef double SQFloat;
#else
typedef float SQFloat;
#endif
#if defined(SQUSEDOUBLE) && !defined(_SQ64) || !defined(SQUSEDOUBLE) && defined(_SQ64)
#ifdef _MSC_VER
typedef __int64 SQRawObjectVal; //must be 64bits
#else
typedef long long SQRawObjectVal; //must be 64bits
#endif
#define SQ_OBJECT_RAWINIT() { _unVal.raw = 0; }
#else
typedef SQUnsignedInteger SQRawObjectVal; //is 32 bits on 32 bits builds and 64 bits otherwise
#define SQ_OBJECT_RAWINIT()
#endif
#ifndef SQ_ALIGNMENT // SQ_ALIGNMENT shall be less than or equal to SQ_MALLOC alignments, and its value shall be power of 2.
#if defined(SQUSEDOUBLE) || defined(_SQ64)
#define SQ_ALIGNMENT 8
#else
#define SQ_ALIGNMENT 4
#endif
#endif
typedef void* SQUserPointer;
typedef SQUnsignedInteger SQBool;
typedef SQInteger SQRESULT;
#ifdef SQUNICODE
#include <wchar.h>
#include <wctype.h>
typedef wchar_t SQChar;
#define scstrcmp wcscmp
#ifdef _WIN32
#define scsprintf _snwprintf
#else
#define scsprintf swprintf
#endif
#define scstrlen wcslen
#define scstrtod wcstod
#ifdef _SQ64
#define scstrtol wcstoll
#else
#define scstrtol wcstol
#endif
#define scstrtoul wcstoul
#define scvsprintf vswprintf
#define scstrstr wcsstr
#define scprintf wprintf
#ifdef _WIN32
#define WCHAR_SIZE 2
#define WCHAR_SHIFT_MUL 1
#define MAX_CHAR 0xFFFF
#else
#define WCHAR_SIZE 4
#define WCHAR_SHIFT_MUL 2
#define MAX_CHAR 0xFFFFFFFF
#endif
#define _SC(a) L##a
#define scisspace iswspace
#define scisdigit iswdigit
#define scisprint iswprint
#define scisxdigit iswxdigit
#define scisalpha iswalpha
#define sciscntrl iswcntrl
#define scisalnum iswalnum
#define sq_rsl(l) ((l)<<WCHAR_SHIFT_MUL)
#else
typedef char SQChar;
#define _SC(a) a
#define scstrcmp strcmp
#ifdef _MSC_VER
#define scsprintf _snprintf
#else
#define scsprintf snprintf
#endif
#define scstrlen strlen
#define scstrtod strtod
#ifdef _SQ64
#ifdef _MSC_VER
#define scstrtol _strtoi64
#else
#define scstrtol strtoll
#endif
#else
#define scstrtol strtol
#endif
#define scstrtoul strtoul
#define scvsprintf vsnprintf
#define scstrstr strstr
#define scisspace isspace
#define scisdigit isdigit
#define scisprint isprint
#define scisxdigit isxdigit
#define sciscntrl iscntrl
#define scisalpha isalpha
#define scisalnum isalnum
#define scprintf printf
#define MAX_CHAR 0xFF
#define sq_rsl(l) (l)
#endif
#ifdef _SQ64
#define _PRINT_INT_PREC _SC("ll")
#define _PRINT_INT_FMT _SC("%lld")
#else
#define _PRINT_INT_FMT _SC("%d")
#endif

View File

@@ -1,16 +0,0 @@
/* see copyright notice in squirrel.h */
#ifndef _SQSTD_AUXLIB_H_
#define _SQSTD_AUXLIB_H_
#ifdef __cplusplus
extern "C" {
#endif
SQUIRREL_API void sqstd_seterrorhandlers(HSQUIRRELVM v);
SQUIRREL_API void sqstd_printcallstack(HSQUIRRELVM v);
#ifdef __cplusplus
} /*extern "C"*/
#endif
#endif /* _SQSTD_AUXLIB_H_ */

View File

@@ -1,20 +0,0 @@
/* see copyright notice in squirrel.h */
#ifndef _SQSTDBLOB_H_
#define _SQSTDBLOB_H_
#ifdef __cplusplus
extern "C" {
#endif
SQUIRREL_API SQUserPointer sqstd_createblob(HSQUIRRELVM v, SQInteger size);
SQUIRREL_API SQRESULT sqstd_getblob(HSQUIRRELVM v,SQInteger idx,SQUserPointer *ptr);
SQUIRREL_API SQInteger sqstd_getblobsize(HSQUIRRELVM v,SQInteger idx);
SQUIRREL_API SQRESULT sqstd_register_bloblib(HSQUIRRELVM v);
#ifdef __cplusplus
} /*extern "C"*/
#endif
#endif /*_SQSTDBLOB_H_*/

View File

@@ -1,53 +0,0 @@
/* see copyright notice in squirrel.h */
#ifndef _SQSTDIO_H_
#define _SQSTDIO_H_
#ifdef __cplusplus
#define SQSTD_STREAM_TYPE_TAG 0x80000000
struct SQStream {
virtual SQInteger Read(void *buffer, SQInteger size) = 0;
virtual SQInteger Write(void *buffer, SQInteger size) = 0;
virtual SQInteger Flush() = 0;
virtual SQInteger Tell() = 0;
virtual SQInteger Len() = 0;
virtual SQInteger Seek(SQInteger offset, SQInteger origin) = 0;
virtual bool IsValid() = 0;
virtual bool EOS() = 0;
};
extern "C" {
#endif
#define SQ_SEEK_CUR 0
#define SQ_SEEK_END 1
#define SQ_SEEK_SET 2
typedef void* SQFILE;
SQUIRREL_API SQFILE sqstd_fopen(const SQChar *,const SQChar *);
SQUIRREL_API SQInteger sqstd_fread(SQUserPointer, SQInteger, SQInteger, SQFILE);
SQUIRREL_API SQInteger sqstd_fwrite(const SQUserPointer, SQInteger, SQInteger, SQFILE);
SQUIRREL_API SQInteger sqstd_fseek(SQFILE , SQInteger , SQInteger);
SQUIRREL_API SQInteger sqstd_ftell(SQFILE);
SQUIRREL_API SQInteger sqstd_fflush(SQFILE);
SQUIRREL_API SQInteger sqstd_fclose(SQFILE);
SQUIRREL_API SQInteger sqstd_feof(SQFILE);
SQUIRREL_API SQRESULT sqstd_createfile(HSQUIRRELVM v, SQFILE file,SQBool own);
SQUIRREL_API SQRESULT sqstd_getfile(HSQUIRRELVM v, SQInteger idx, SQFILE *file);
//compiler helpers
SQUIRREL_API SQRESULT sqstd_loadfile(HSQUIRRELVM v,const SQChar *filename,SQBool printerror);
SQUIRREL_API SQRESULT sqstd_dofile(HSQUIRRELVM v,const SQChar *filename,SQBool retval,SQBool printerror);
SQUIRREL_API SQRESULT sqstd_writeclosuretofile(HSQUIRRELVM v,const SQChar *filename);
SQUIRREL_API SQRESULT sqstd_register_iolib(HSQUIRRELVM v);
#ifdef __cplusplus
} /*extern "C"*/
#endif
#endif /*_SQSTDIO_H_*/

View File

@@ -1,15 +0,0 @@
/* see copyright notice in squirrel.h */
#ifndef _SQSTD_MATH_H_
#define _SQSTD_MATH_H_
#ifdef __cplusplus
extern "C" {
#endif
SQUIRREL_API SQRESULT sqstd_register_mathlib(HSQUIRRELVM v);
#ifdef __cplusplus
} /*extern "C"*/
#endif
#endif /*_SQSTD_MATH_H_*/

View File

@@ -1,33 +0,0 @@
/* see copyright notice in squirrel.h */
#ifndef _SQSTD_STRING_H_
#define _SQSTD_STRING_H_
#ifdef __cplusplus
extern "C" {
#endif
typedef unsigned int SQRexBool;
typedef struct SQRex SQRex;
typedef struct {
const SQChar *begin;
SQInteger len;
} SQRexMatch;
SQUIRREL_API SQRex *sqstd_rex_compile(const SQChar *pattern,const SQChar **error);
SQUIRREL_API void sqstd_rex_free(SQRex *exp);
SQUIRREL_API SQBool sqstd_rex_match(SQRex* exp,const SQChar* text);
SQUIRREL_API SQBool sqstd_rex_search(SQRex* exp,const SQChar* text, const SQChar** out_begin, const SQChar** out_end);
SQUIRREL_API SQBool sqstd_rex_searchrange(SQRex* exp,const SQChar* text_begin,const SQChar* text_end,const SQChar** out_begin, const SQChar** out_end);
SQUIRREL_API SQInteger sqstd_rex_getsubexpcount(SQRex* exp);
SQUIRREL_API SQBool sqstd_rex_getsubexp(SQRex* exp, SQInteger n, SQRexMatch *subexp);
SQUIRREL_API SQRESULT sqstd_format(HSQUIRRELVM v,SQInteger nformatstringidx,SQInteger *outlen,SQChar **output);
SQUIRREL_API SQRESULT sqstd_register_stringlib(HSQUIRRELVM v);
#ifdef __cplusplus
} /*extern "C"*/
#endif
#endif /*_SQSTD_STRING_H_*/

View File

@@ -1,15 +0,0 @@
/* see copyright notice in squirrel.h */
#ifndef _SQSTD_SYSTEMLIB_H_
#define _SQSTD_SYSTEMLIB_H_
#ifdef __cplusplus
extern "C" {
#endif
SQUIRREL_API SQInteger sqstd_register_systemlib(HSQUIRRELVM v);
#ifdef __cplusplus
} /*extern "C"*/
#endif
#endif /* _SQSTD_SYSTEMLIB_H_ */

View File

@@ -1,405 +0,0 @@
/*
Copyright (c) 2003-2016 Alberto Demichelis
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
#ifndef _SQUIRREL_H_
#define _SQUIRREL_H_
#ifdef __cplusplus
extern "C" {
#endif
#ifndef SQUIRREL_API
#define SQUIRREL_API extern
#endif
#if (defined(_WIN64) || defined(_LP64))
#ifndef _SQ64
#define _SQ64
#endif
#endif
#define SQTrue (1)
#define SQFalse (0)
struct SQVM;
struct SQTable;
struct SQArray;
struct SQString;
struct SQClosure;
struct SQGenerator;
struct SQNativeClosure;
struct SQUserData;
struct SQFunctionProto;
struct SQRefCounted;
struct SQClass;
struct SQInstance;
struct SQDelegable;
struct SQOuter;
#ifdef _UNICODE
#define SQUNICODE
#endif
#include "sqconfig.h"
#define SQUIRREL_VERSION _SC("Squirrel 3.1 stable")
#define SQUIRREL_COPYRIGHT _SC("Copyright (C) 2003-2016 Alberto Demichelis")
#define SQUIRREL_AUTHOR _SC("Alberto Demichelis")
#define SQUIRREL_VERSION_NUMBER 310
#define SQ_VMSTATE_IDLE 0
#define SQ_VMSTATE_RUNNING 1
#define SQ_VMSTATE_SUSPENDED 2
#define SQUIRREL_EOB 0
#define SQ_BYTECODE_STREAM_TAG 0xFAFA
#define SQOBJECT_REF_COUNTED 0x08000000
#define SQOBJECT_NUMERIC 0x04000000
#define SQOBJECT_DELEGABLE 0x02000000
#define SQOBJECT_CANBEFALSE 0x01000000
#define SQ_MATCHTYPEMASKSTRING (-99999)
#define _RT_MASK 0x00FFFFFF
#define _RAW_TYPE(type) (type&_RT_MASK)
#define _RT_NULL 0x00000001
#define _RT_INTEGER 0x00000002
#define _RT_FLOAT 0x00000004
#define _RT_BOOL 0x00000008
#define _RT_STRING 0x00000010
#define _RT_TABLE 0x00000020
#define _RT_ARRAY 0x00000040
#define _RT_USERDATA 0x00000080
#define _RT_CLOSURE 0x00000100
#define _RT_NATIVECLOSURE 0x00000200
#define _RT_GENERATOR 0x00000400
#define _RT_USERPOINTER 0x00000800
#define _RT_THREAD 0x00001000
#define _RT_FUNCPROTO 0x00002000
#define _RT_CLASS 0x00004000
#define _RT_INSTANCE 0x00008000
#define _RT_WEAKREF 0x00010000
#define _RT_OUTER 0x00020000
typedef enum tagSQObjectType{
OT_NULL = (_RT_NULL|SQOBJECT_CANBEFALSE),
OT_INTEGER = (_RT_INTEGER|SQOBJECT_NUMERIC|SQOBJECT_CANBEFALSE),
OT_FLOAT = (_RT_FLOAT|SQOBJECT_NUMERIC|SQOBJECT_CANBEFALSE),
OT_BOOL = (_RT_BOOL|SQOBJECT_CANBEFALSE),
OT_STRING = (_RT_STRING|SQOBJECT_REF_COUNTED),
OT_TABLE = (_RT_TABLE|SQOBJECT_REF_COUNTED|SQOBJECT_DELEGABLE),
OT_ARRAY = (_RT_ARRAY|SQOBJECT_REF_COUNTED),
OT_USERDATA = (_RT_USERDATA|SQOBJECT_REF_COUNTED|SQOBJECT_DELEGABLE),
OT_CLOSURE = (_RT_CLOSURE|SQOBJECT_REF_COUNTED),
OT_NATIVECLOSURE = (_RT_NATIVECLOSURE|SQOBJECT_REF_COUNTED),
OT_GENERATOR = (_RT_GENERATOR|SQOBJECT_REF_COUNTED),
OT_USERPOINTER = _RT_USERPOINTER,
OT_THREAD = (_RT_THREAD|SQOBJECT_REF_COUNTED) ,
OT_FUNCPROTO = (_RT_FUNCPROTO|SQOBJECT_REF_COUNTED), //internal usage only
OT_CLASS = (_RT_CLASS|SQOBJECT_REF_COUNTED),
OT_INSTANCE = (_RT_INSTANCE|SQOBJECT_REF_COUNTED|SQOBJECT_DELEGABLE),
OT_WEAKREF = (_RT_WEAKREF|SQOBJECT_REF_COUNTED),
OT_OUTER = (_RT_OUTER|SQOBJECT_REF_COUNTED) //internal usage only
}SQObjectType;
#define ISREFCOUNTED(t) (t&SQOBJECT_REF_COUNTED)
typedef union tagSQObjectValue
{
struct SQTable *pTable;
struct SQArray *pArray;
struct SQClosure *pClosure;
struct SQOuter *pOuter;
struct SQGenerator *pGenerator;
struct SQNativeClosure *pNativeClosure;
struct SQString *pString;
struct SQUserData *pUserData;
SQInteger nInteger;
SQFloat fFloat;
SQUserPointer pUserPointer;
struct SQFunctionProto *pFunctionProto;
struct SQRefCounted *pRefCounted;
struct SQDelegable *pDelegable;
struct SQVM *pThread;
struct SQClass *pClass;
struct SQInstance *pInstance;
struct SQWeakRef *pWeakRef;
SQRawObjectVal raw;
}SQObjectValue;
typedef struct tagSQObject
{
SQObjectType _type;
SQObjectValue _unVal;
}SQObject;
typedef struct tagSQMemberHandle{
SQBool _static;
SQInteger _index;
}SQMemberHandle;
typedef struct tagSQStackInfos{
const SQChar* funcname;
const SQChar* source;
SQInteger line;
}SQStackInfos;
typedef struct SQVM* HSQUIRRELVM;
typedef SQObject HSQOBJECT;
typedef SQMemberHandle HSQMEMBERHANDLE;
typedef SQInteger (*SQFUNCTION)(HSQUIRRELVM);
typedef SQInteger (*SQRELEASEHOOK)(SQUserPointer,SQInteger size);
typedef void (*SQCOMPILERERROR)(HSQUIRRELVM,const SQChar * /*desc*/,const SQChar * /*source*/,SQInteger /*line*/,SQInteger /*column*/);
typedef void (*SQPRINTFUNCTION)(HSQUIRRELVM,const SQChar * ,...);
typedef void (*SQDEBUGHOOK)(HSQUIRRELVM /*v*/, SQInteger /*type*/, const SQChar * /*sourcename*/, SQInteger /*line*/, const SQChar * /*funcname*/);
typedef SQInteger (*SQWRITEFUNC)(SQUserPointer,SQUserPointer,SQInteger);
typedef SQInteger (*SQREADFUNC)(SQUserPointer,SQUserPointer,SQInteger);
typedef SQInteger (*SQLEXREADFUNC)(SQUserPointer);
typedef struct tagSQRegFunction{
const SQChar *name;
SQFUNCTION f;
SQInteger nparamscheck;
const SQChar *typemask;
}SQRegFunction;
typedef struct tagSQFunctionInfo {
SQUserPointer funcid;
const SQChar *name;
const SQChar *source;
SQInteger line;
}SQFunctionInfo;
/*vm*/
SQUIRREL_API HSQUIRRELVM sq_open(SQInteger initialstacksize);
SQUIRREL_API HSQUIRRELVM sq_newthread(HSQUIRRELVM friendvm, SQInteger initialstacksize);
SQUIRREL_API void sq_seterrorhandler(HSQUIRRELVM v);
SQUIRREL_API void sq_close(HSQUIRRELVM v);
SQUIRREL_API void sq_setforeignptr(HSQUIRRELVM v,SQUserPointer p);
SQUIRREL_API SQUserPointer sq_getforeignptr(HSQUIRRELVM v);
SQUIRREL_API void sq_setsharedforeignptr(HSQUIRRELVM v,SQUserPointer p);
SQUIRREL_API SQUserPointer sq_getsharedforeignptr(HSQUIRRELVM v);
SQUIRREL_API void sq_setvmreleasehook(HSQUIRRELVM v,SQRELEASEHOOK hook);
SQUIRREL_API SQRELEASEHOOK sq_getvmreleasehook(HSQUIRRELVM v);
SQUIRREL_API void sq_setsharedreleasehook(HSQUIRRELVM v,SQRELEASEHOOK hook);
SQUIRREL_API SQRELEASEHOOK sq_getsharedreleasehook(HSQUIRRELVM v);
SQUIRREL_API void sq_setprintfunc(HSQUIRRELVM v, SQPRINTFUNCTION printfunc,SQPRINTFUNCTION errfunc);
SQUIRREL_API SQPRINTFUNCTION sq_getprintfunc(HSQUIRRELVM v);
SQUIRREL_API SQPRINTFUNCTION sq_geterrorfunc(HSQUIRRELVM v);
SQUIRREL_API SQRESULT sq_suspendvm(HSQUIRRELVM v);
SQUIRREL_API SQRESULT sq_wakeupvm(HSQUIRRELVM v,SQBool resumedret,SQBool retval,SQBool raiseerror,SQBool throwerror);
SQUIRREL_API SQInteger sq_getvmstate(HSQUIRRELVM v);
SQUIRREL_API SQInteger sq_getversion();
/*compiler*/
SQUIRREL_API SQRESULT sq_compile(HSQUIRRELVM v,SQLEXREADFUNC read,SQUserPointer p,const SQChar *sourcename,SQBool raiseerror);
SQUIRREL_API SQRESULT sq_compilebuffer(HSQUIRRELVM v,const SQChar *s,SQInteger size,const SQChar *sourcename,SQBool raiseerror);
SQUIRREL_API void sq_enabledebuginfo(HSQUIRRELVM v, SQBool enable);
SQUIRREL_API void sq_notifyallexceptions(HSQUIRRELVM v, SQBool enable);
SQUIRREL_API void sq_setcompilererrorhandler(HSQUIRRELVM v,SQCOMPILERERROR f);
/*stack operations*/
SQUIRREL_API void sq_push(HSQUIRRELVM v,SQInteger idx);
SQUIRREL_API void sq_pop(HSQUIRRELVM v,SQInteger nelemstopop);
SQUIRREL_API void sq_poptop(HSQUIRRELVM v);
SQUIRREL_API void sq_remove(HSQUIRRELVM v,SQInteger idx);
SQUIRREL_API SQInteger sq_gettop(HSQUIRRELVM v);
SQUIRREL_API void sq_settop(HSQUIRRELVM v,SQInteger newtop);
SQUIRREL_API SQRESULT sq_reservestack(HSQUIRRELVM v,SQInteger nsize);
SQUIRREL_API SQInteger sq_cmp(HSQUIRRELVM v);
SQUIRREL_API void sq_move(HSQUIRRELVM dest,HSQUIRRELVM src,SQInteger idx);
/*object creation handling*/
SQUIRREL_API SQUserPointer sq_newuserdata(HSQUIRRELVM v,SQUnsignedInteger size);
SQUIRREL_API void sq_newtable(HSQUIRRELVM v);
SQUIRREL_API void sq_newtableex(HSQUIRRELVM v,SQInteger initialcapacity);
SQUIRREL_API void sq_newarray(HSQUIRRELVM v,SQInteger size);
SQUIRREL_API void sq_newclosure(HSQUIRRELVM v,SQFUNCTION func,SQUnsignedInteger nfreevars);
SQUIRREL_API SQRESULT sq_setparamscheck(HSQUIRRELVM v,SQInteger nparamscheck,const SQChar *typemask);
SQUIRREL_API SQRESULT sq_bindenv(HSQUIRRELVM v,SQInteger idx);
SQUIRREL_API SQRESULT sq_setclosureroot(HSQUIRRELVM v,SQInteger idx);
SQUIRREL_API SQRESULT sq_getclosureroot(HSQUIRRELVM v,SQInteger idx);
SQUIRREL_API void sq_pushstring(HSQUIRRELVM v,const SQChar *s,SQInteger len);
SQUIRREL_API void sq_pushfloat(HSQUIRRELVM v,SQFloat f);
SQUIRREL_API void sq_pushinteger(HSQUIRRELVM v,SQInteger n);
SQUIRREL_API void sq_pushbool(HSQUIRRELVM v,SQBool b);
SQUIRREL_API void sq_pushuserpointer(HSQUIRRELVM v,SQUserPointer p);
SQUIRREL_API void sq_pushnull(HSQUIRRELVM v);
SQUIRREL_API void sq_pushthread(HSQUIRRELVM v, HSQUIRRELVM thread);
SQUIRREL_API SQObjectType sq_gettype(HSQUIRRELVM v,SQInteger idx);
SQUIRREL_API SQRESULT sq_typeof(HSQUIRRELVM v,SQInteger idx);
SQUIRREL_API SQInteger sq_getsize(HSQUIRRELVM v,SQInteger idx);
SQUIRREL_API SQHash sq_gethash(HSQUIRRELVM v, SQInteger idx);
SQUIRREL_API SQRESULT sq_getbase(HSQUIRRELVM v,SQInteger idx);
SQUIRREL_API SQBool sq_instanceof(HSQUIRRELVM v);
SQUIRREL_API SQRESULT sq_tostring(HSQUIRRELVM v,SQInteger idx);
SQUIRREL_API void sq_tobool(HSQUIRRELVM v, SQInteger idx, SQBool *b);
SQUIRREL_API SQRESULT sq_getstring(HSQUIRRELVM v,SQInteger idx,const SQChar **c);
SQUIRREL_API SQRESULT sq_getinteger(HSQUIRRELVM v,SQInteger idx,SQInteger *i);
SQUIRREL_API SQRESULT sq_getfloat(HSQUIRRELVM v,SQInteger idx,SQFloat *f);
SQUIRREL_API SQRESULT sq_getbool(HSQUIRRELVM v,SQInteger idx,SQBool *b);
SQUIRREL_API SQRESULT sq_getthread(HSQUIRRELVM v,SQInteger idx,HSQUIRRELVM *thread);
SQUIRREL_API SQRESULT sq_getuserpointer(HSQUIRRELVM v,SQInteger idx,SQUserPointer *p);
SQUIRREL_API SQRESULT sq_getuserdata(HSQUIRRELVM v,SQInteger idx,SQUserPointer *p,SQUserPointer *typetag);
SQUIRREL_API SQRESULT sq_settypetag(HSQUIRRELVM v,SQInteger idx,SQUserPointer typetag);
SQUIRREL_API SQRESULT sq_gettypetag(HSQUIRRELVM v,SQInteger idx,SQUserPointer *typetag);
SQUIRREL_API void sq_setreleasehook(HSQUIRRELVM v,SQInteger idx,SQRELEASEHOOK hook);
SQUIRREL_API SQRELEASEHOOK sq_getreleasehook(HSQUIRRELVM v,SQInteger idx);
SQUIRREL_API SQChar *sq_getscratchpad(HSQUIRRELVM v,SQInteger minsize);
SQUIRREL_API SQRESULT sq_getfunctioninfo(HSQUIRRELVM v,SQInteger level,SQFunctionInfo *fi);
SQUIRREL_API SQRESULT sq_getclosureinfo(HSQUIRRELVM v,SQInteger idx,SQUnsignedInteger *nparams,SQUnsignedInteger *nfreevars);
SQUIRREL_API SQRESULT sq_getclosurename(HSQUIRRELVM v,SQInteger idx);
SQUIRREL_API SQRESULT sq_setnativeclosurename(HSQUIRRELVM v,SQInteger idx,const SQChar *name);
SQUIRREL_API SQRESULT sq_setinstanceup(HSQUIRRELVM v, SQInteger idx, SQUserPointer p);
SQUIRREL_API SQRESULT sq_getinstanceup(HSQUIRRELVM v, SQInteger idx, SQUserPointer *p,SQUserPointer typetag);
SQUIRREL_API SQRESULT sq_setclassudsize(HSQUIRRELVM v, SQInteger idx, SQInteger udsize);
SQUIRREL_API SQRESULT sq_newclass(HSQUIRRELVM v,SQBool hasbase);
SQUIRREL_API SQRESULT sq_createinstance(HSQUIRRELVM v,SQInteger idx);
SQUIRREL_API SQRESULT sq_setattributes(HSQUIRRELVM v,SQInteger idx);
SQUIRREL_API SQRESULT sq_getattributes(HSQUIRRELVM v,SQInteger idx);
SQUIRREL_API SQRESULT sq_getclass(HSQUIRRELVM v,SQInteger idx);
SQUIRREL_API void sq_weakref(HSQUIRRELVM v,SQInteger idx);
SQUIRREL_API SQRESULT sq_getdefaultdelegate(HSQUIRRELVM v,SQObjectType t);
SQUIRREL_API SQRESULT sq_getmemberhandle(HSQUIRRELVM v,SQInteger idx,HSQMEMBERHANDLE *handle);
SQUIRREL_API SQRESULT sq_getbyhandle(HSQUIRRELVM v,SQInteger idx,const HSQMEMBERHANDLE *handle);
SQUIRREL_API SQRESULT sq_setbyhandle(HSQUIRRELVM v,SQInteger idx,const HSQMEMBERHANDLE *handle);
/*object manipulation*/
SQUIRREL_API void sq_pushroottable(HSQUIRRELVM v);
SQUIRREL_API void sq_pushregistrytable(HSQUIRRELVM v);
SQUIRREL_API void sq_pushconsttable(HSQUIRRELVM v);
SQUIRREL_API SQRESULT sq_setroottable(HSQUIRRELVM v);
SQUIRREL_API SQRESULT sq_setconsttable(HSQUIRRELVM v);
SQUIRREL_API SQRESULT sq_newslot(HSQUIRRELVM v, SQInteger idx, SQBool bstatic);
SQUIRREL_API SQRESULT sq_deleteslot(HSQUIRRELVM v,SQInteger idx,SQBool pushval);
SQUIRREL_API SQRESULT sq_set(HSQUIRRELVM v,SQInteger idx);
SQUIRREL_API SQRESULT sq_get(HSQUIRRELVM v,SQInteger idx);
SQUIRREL_API SQRESULT sq_rawget(HSQUIRRELVM v,SQInteger idx);
SQUIRREL_API SQRESULT sq_rawset(HSQUIRRELVM v,SQInteger idx);
SQUIRREL_API SQRESULT sq_rawdeleteslot(HSQUIRRELVM v,SQInteger idx,SQBool pushval);
SQUIRREL_API SQRESULT sq_newmember(HSQUIRRELVM v,SQInteger idx,SQBool bstatic);
SQUIRREL_API SQRESULT sq_rawnewmember(HSQUIRRELVM v,SQInteger idx,SQBool bstatic);
SQUIRREL_API SQRESULT sq_arrayappend(HSQUIRRELVM v,SQInteger idx);
SQUIRREL_API SQRESULT sq_arraypop(HSQUIRRELVM v,SQInteger idx,SQBool pushval);
SQUIRREL_API SQRESULT sq_arrayresize(HSQUIRRELVM v,SQInteger idx,SQInteger newsize);
SQUIRREL_API SQRESULT sq_arrayreverse(HSQUIRRELVM v,SQInteger idx);
SQUIRREL_API SQRESULT sq_arrayremove(HSQUIRRELVM v,SQInteger idx,SQInteger itemidx);
SQUIRREL_API SQRESULT sq_arrayinsert(HSQUIRRELVM v,SQInteger idx,SQInteger destpos);
SQUIRREL_API SQRESULT sq_setdelegate(HSQUIRRELVM v,SQInteger idx);
SQUIRREL_API SQRESULT sq_getdelegate(HSQUIRRELVM v,SQInteger idx);
SQUIRREL_API SQRESULT sq_clone(HSQUIRRELVM v,SQInteger idx);
SQUIRREL_API SQRESULT sq_setfreevariable(HSQUIRRELVM v,SQInteger idx,SQUnsignedInteger nval);
SQUIRREL_API SQRESULT sq_next(HSQUIRRELVM v,SQInteger idx);
SQUIRREL_API SQRESULT sq_getweakrefval(HSQUIRRELVM v,SQInteger idx);
SQUIRREL_API SQRESULT sq_clear(HSQUIRRELVM v,SQInteger idx);
/*calls*/
SQUIRREL_API SQRESULT sq_call(HSQUIRRELVM v,SQInteger params,SQBool retval,SQBool raiseerror);
SQUIRREL_API SQRESULT sq_resume(HSQUIRRELVM v,SQBool retval,SQBool raiseerror);
SQUIRREL_API const SQChar *sq_getlocal(HSQUIRRELVM v,SQUnsignedInteger level,SQUnsignedInteger idx);
SQUIRREL_API SQRESULT sq_getcallee(HSQUIRRELVM v);
SQUIRREL_API const SQChar *sq_getfreevariable(HSQUIRRELVM v,SQInteger idx,SQUnsignedInteger nval);
SQUIRREL_API SQRESULT sq_throwerror(HSQUIRRELVM v,const SQChar *err);
SQUIRREL_API SQRESULT sq_throwobject(HSQUIRRELVM v);
SQUIRREL_API void sq_reseterror(HSQUIRRELVM v);
SQUIRREL_API void sq_getlasterror(HSQUIRRELVM v);
/*raw object handling*/
SQUIRREL_API SQRESULT sq_getstackobj(HSQUIRRELVM v,SQInteger idx,HSQOBJECT *po);
SQUIRREL_API void sq_pushobject(HSQUIRRELVM v,HSQOBJECT obj);
SQUIRREL_API void sq_addref(HSQUIRRELVM v,HSQOBJECT *po);
SQUIRREL_API SQBool sq_release(HSQUIRRELVM v,HSQOBJECT *po);
SQUIRREL_API SQUnsignedInteger sq_getrefcount(HSQUIRRELVM v,HSQOBJECT *po);
SQUIRREL_API void sq_resetobject(HSQOBJECT *po);
SQUIRREL_API const SQChar *sq_objtostring(const HSQOBJECT *o);
SQUIRREL_API SQBool sq_objtobool(const HSQOBJECT *o);
SQUIRREL_API SQInteger sq_objtointeger(const HSQOBJECT *o);
SQUIRREL_API SQFloat sq_objtofloat(const HSQOBJECT *o);
SQUIRREL_API SQUserPointer sq_objtouserpointer(const HSQOBJECT *o);
SQUIRREL_API SQRESULT sq_getobjtypetag(const HSQOBJECT *o,SQUserPointer * typetag);
SQUIRREL_API SQUnsignedInteger sq_getvmrefcount(HSQUIRRELVM v, const HSQOBJECT *po);
/*GC*/
SQUIRREL_API SQInteger sq_collectgarbage(HSQUIRRELVM v);
SQUIRREL_API SQRESULT sq_resurrectunreachable(HSQUIRRELVM v);
/*serialization*/
SQUIRREL_API SQRESULT sq_writeclosure(HSQUIRRELVM vm,SQWRITEFUNC writef,SQUserPointer up);
SQUIRREL_API SQRESULT sq_readclosure(HSQUIRRELVM vm,SQREADFUNC readf,SQUserPointer up);
/*mem allocation*/
SQUIRREL_API void *sq_malloc(SQUnsignedInteger size);
SQUIRREL_API void *sq_realloc(void* p,SQUnsignedInteger oldsize,SQUnsignedInteger newsize);
SQUIRREL_API void sq_free(void *p,SQUnsignedInteger size);
/*debug*/
SQUIRREL_API SQRESULT sq_stackinfos(HSQUIRRELVM v,SQInteger level,SQStackInfos *si);
SQUIRREL_API void sq_setdebughook(HSQUIRRELVM v);
SQUIRREL_API void sq_setnativedebughook(HSQUIRRELVM v,SQDEBUGHOOK hook);
/*UTILITY MACRO*/
#define sq_isnumeric(o) ((o)._type&SQOBJECT_NUMERIC)
#define sq_istable(o) ((o)._type==OT_TABLE)
#define sq_isarray(o) ((o)._type==OT_ARRAY)
#define sq_isfunction(o) ((o)._type==OT_FUNCPROTO)
#define sq_isclosure(o) ((o)._type==OT_CLOSURE)
#define sq_isgenerator(o) ((o)._type==OT_GENERATOR)
#define sq_isnativeclosure(o) ((o)._type==OT_NATIVECLOSURE)
#define sq_isstring(o) ((o)._type==OT_STRING)
#define sq_isinteger(o) ((o)._type==OT_INTEGER)
#define sq_isfloat(o) ((o)._type==OT_FLOAT)
#define sq_isuserpointer(o) ((o)._type==OT_USERPOINTER)
#define sq_isuserdata(o) ((o)._type==OT_USERDATA)
#define sq_isthread(o) ((o)._type==OT_THREAD)
#define sq_isnull(o) ((o)._type==OT_NULL)
#define sq_isclass(o) ((o)._type==OT_CLASS)
#define sq_isinstance(o) ((o)._type==OT_INSTANCE)
#define sq_isbool(o) ((o)._type==OT_BOOL)
#define sq_isweakref(o) ((o)._type==OT_WEAKREF)
#define sq_type(o) ((o)._type)
/* deprecated */
#define sq_createslot(v,n) sq_newslot(v,n,SQFalse)
#define SQ_OK (0)
#define SQ_ERROR (-1)
#define SQ_FAILED(res) (res<0)
#define SQ_SUCCEEDED(res) (res>=0)
#ifdef __GNUC__
# define SQ_UNUSED_ARG(x) __attribute__((unused)) x
#else
# define SQ_UNUSED_ARG(x) x
#endif
#ifdef __cplusplus
} /*extern "C"*/
#endif
#endif /*_SQUIRREL_H_*/

View File

@@ -1,22 +0,0 @@
#include "module_api.h"
namespace SqModule
{
HSQUIRRELVM vm;
HSQAPI api;
void Initialize(HSQUIRRELVM vm, HSQAPI api) {
SqModule::vm = vm;
SqModule::api = api;
}
void Print(const SQChar* msg) {
const SQPRINTFUNCTION print = sq_getprintfunc(vm);
print(vm, msg);
}
void Error(const SQChar* msg) {
const SQPRINTFUNCTION error = sq_geterrorfunc(vm);
error(vm, msg);
}
}

View File

@@ -1,16 +0,0 @@
#ifndef _MODULE_API_H
#define _MODULE_API_H
#include <sqmodule.h>
namespace SqModule
{
extern HSQUIRRELVM vm;
extern HSQAPI api;
void Initialize(HSQUIRRELVM vm, HSQAPI api);
void Print(const SQChar* msg);
void Error(const SQChar* msg);
}
#endif

View File

@@ -1,171 +0,0 @@
#ifndef _SQUIRREL_API_H
#define _SQUIRREL_API_H
/*vm*/
#define sq_open SqModule::api->open
#define sq_newthread SqModule::api->newthread
#define sq_seterrorhandler SqModule::api->seterrorhandler
#define sq_close SqModule::api->close
#define sq_setforeignptr SqModule::api->setforeignptr
#define sq_getforeignptr SqModule::api->getforeignptr
#define sq_setsharedforeignptr SqModule::api->setsharedforeignptr
#define sq_getsharedforeignptr SqModule::api->getsharedforeignptr
#define sq_setvmreleasehook SqModule::api->setvmreleasehook
#define sq_getvmreleasehook SqModule::api->getvmreleasehook
#define sq_setsharedreleasehook SqModule::api->setsharedreleasehook
#define sq_getsharedreleasehook SqModule::api->getsharedreleasehook
#define sq_setprintfunc SqModule::api->setprintfunc
#define sq_getprintfunc SqModule::api->getprintfunc
#define sq_geterrorfunc SqModule::api->geterrorfunc
#define sq_suspendvm SqModule::api->suspendvm
#define sq_wakeupvm SqModule::api->wakeupvm
#define sq_getvmstate SqModule::api->getvmstate
#define sq_getversion SqModule::api->getversion
/*compiler*/
#define sq_compile SqModule::api->compile
#define sq_compilebuffer SqModule::api->compilebuffer
#define sq_enabledebuginfo SqModule::api->enabledebuginfo
#define sq_notifyallexceptions SqModule::api->notifyallexceptions
#define sq_setcompilererrorhandler SqModule::api->setcompilererrorhandler
/*stack operations*/
#define sq_push SqModule::api->push
#define sq_pop SqModule::api->pop
#define sq_poptop SqModule::api->poptop
#define sq_remove SqModule::api->remove
#define sq_gettop SqModule::api->gettop
#define sq_settop SqModule::api->settop
#define sq_reservestack SqModule::api->reservestack
#define sq_cmp SqModule::api->cmp
#define sq_move SqModule::api->move
/*object creation handling*/
#define sq_newuserdata SqModule::api->newuserdata
#define sq_newtable SqModule::api->newtable
#define sq_newtableex SqModule::api->newtableex
#define sq_newarray SqModule::api->newarray
#define sq_newclosure SqModule::api->newclosure
#define sq_setparamscheck SqModule::api->setparamscheck
#define sq_bindenv SqModule::api->bindenv
#define sq_setclosureroot SqModule::api->setclosureroot
#define sq_getclosureroot SqModule::api->getclosureroot
#define sq_pushstring SqModule::api->pushstring
#define sq_pushfloat SqModule::api->pushfloat
#define sq_pushinteger SqModule::api->pushinteger
#define sq_pushbool SqModule::api->pushbool
#define sq_pushuserpointer SqModule::api->pushuserpointer
#define sq_pushnull SqModule::api->pushnull
#define sq_pushthread SqModule::api->pushthread
#define sq_gettype SqModule::api->gettype
#define sq_typeof SqModule::api->type_of
#define sq_getsize SqModule::api->getsize
#define sq_gethash SqModule::api->gethash
#define sq_getbase SqModule::api->getbase
#define sq_instanceof SqModule::api->instanceof
#define sq_tostring SqModule::api->tostring
#define sq_tobool SqModule::api->tobool
#define sq_getstring SqModule::api->getstring
#define sq_getinteger SqModule::api->getinteger
#define sq_getfloat SqModule::api->getfloat
#define sq_getbool SqModule::api->getbool
#define sq_getthread SqModule::api->getthread
#define sq_getuserpointer SqModule::api->getuserpointer
#define sq_getuserdata SqModule::api->getuserdata
#define sq_settypetag SqModule::api->settypetag
#define sq_gettypetag SqModule::api->gettypetag
#define sq_setreleasehook SqModule::api->setreleasehook
#define sq_getreleasehook SqModule::api->getreleasehook
#define sq_getscratchpad SqModule::api->getscratchpad
#define sq_getfunctioninfo SqModule::api->getfunctioninfo
#define sq_getclosureinfo SqModule::api->getclosureinfo
#define sq_getclosurename SqModule::api->getclosurename
#define sq_setnativeclosurename SqModule::api->setnativeclosurename
#define sq_setinstanceup SqModule::api->setinstanceup
#define sq_getinstanceup SqModule::api->getinstanceup
#define sq_setclassudsize SqModule::api->setclassudsize
#define sq_newclass SqModule::api->newclass
#define sq_createinstance SqModule::api->createinstance
#define sq_setattributes SqModule::api->setattributes
#define sq_getattributes SqModule::api->getattributes
#define sq_getclass SqModule::api->getclass
#define sq_weakref SqModule::api->weakref
#define sq_getdefaultdelegate SqModule::api->getdefaultdelegate
#define sq_getmemberhandle SqModule::api->getmemberhandle
#define sq_getbyhandle SqModule::api->getbyhandle
#define sq_setbyhandle SqModule::api->setbyhandle
/*object manipulation*/
#define sq_pushroottable SqModule::api->pushroottable
#define sq_pushregistrytable SqModule::api->pushregistrytable
#define sq_pushconsttable SqModule::api->pushconsttable
#define sq_setroottable SqModule::api->setroottable
#define sq_setconsttable SqModule::api->setconsttable
#define sq_newslot SqModule::api->newslot
#define sq_deleteslot SqModule::api->deleteslot
#define sq_set SqModule::api->set
#define sq_get SqModule::api->get
#define sq_rawset SqModule::api->rawset
#define sq_rawget SqModule::api->rawget
#define sq_rawdeleteslot SqModule::api->rawdeleteslot
#define sq_newmember SqModule::api->newmember
#define sq_rawnewmember SqModule::api->rawnewmember
#define sq_arrayappend SqModule::api->arrayappend
#define sq_arraypop SqModule::api->arraypop
#define sq_arrayresize SqModule::api->arrayresize
#define sq_arrayreverse SqModule::api->arrayreverse
#define sq_arrayremove SqModule::api->arrayremove
#define sq_arrayinsert SqModule::api->arrayinsert
#define sq_setdelegate SqModule::api->setdelegate
#define sq_getdelegate SqModule::api->getdelegate
#define sq_clone SqModule::api->clone
#define sq_setfreevariable SqModule::api->setfreevariable
#define sq_next SqModule::api->next
#define sq_getweakrefval SqModule::api->getweakrefval
#define sq_clear SqModule::api->clear
/*calls*/
#define sq_call SqModule::api->call
#define sq_resume SqModule::api->resume
#define sq_getlocal SqModule::api->getlocal
#define sq_getcallee SqModule::api->getcallee
#define sq_getfreevariable SqModule::api->getfreevariable
#define sq_throwerror SqModule::api->throwerror
#define sq_throwobject SqModule::api->throwobject
#define sq_reseterror SqModule::api->reseterror
#define sq_getlasterror SqModule::api->getlasterror
/*raw object handling*/
#define sq_getstackobj SqModule::api->getstackobj
#define sq_pushobject SqModule::api->pushobject
#define sq_addref SqModule::api->addref
#define sq_release SqModule::api->release
#define sq_getrefcount SqModule::api->getrefcount
#define sq_resetobject SqModule::api->resetobject
#define sq_objtostring SqModule::api->objtostring
#define sq_objtobool SqModule::api->objtobool
#define sq_objtointeger SqModule::api->objtointeger
#define sq_objtofloat SqModule::api->objtofloat
#define sq_objtouserpointer SqModule::api->objtouserpointer
#define sq_getobjtypetag SqModule::api->getobjtypetag
#define sq_getvmrefcount SqModule::api->getvmrefcount
/*GC*/
#define sq_collectgarbage SqModule::api->collectgarbage
#define sq_resurrectunreachable SqModule::api->resurrectunreachable
/*serialization*/
#define sq_writeclosure SqModule::api->writeclosure
#define sq_readclosure SqModule::api->readclosure
/*mem allocation*/
#define sq_malloc SqModule::api->malloc
#define sq_realloc SqModule::api->realloc
#define sq_free SqModule::api->free
/*debug*/
#define sq_stackinfos SqModule::api->stackinfos
#define sq_setdebughook SqModule::api->setdebughook
#define sq_setnativedebughook SqModule::api->setnativedebughook
#endif

View File

@@ -1,3 +1,4 @@
#include <module_api.h>
#include <sqrat.h> #include <sqrat.h>
extern "C" SQRESULT SQRAT_API sqmodule_load(HSQUIRRELVM vm, HSQAPI api) extern "C" SQRESULT SQRAT_API sqmodule_load(HSQUIRRELVM vm, HSQAPI api)