1
0
mirror of https://github.com/VCMP-SqMod/SqMod.git synced 2025-07-10 02:47:11 +02:00

Implemented the module system.

This commit is contained in:
Sandu Liviu Catalin
2016-02-23 17:48:30 +02:00
parent 48406020f8
commit fa12692490
38 changed files with 4017 additions and 1613 deletions

@ -1,199 +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
/* HSQAPI */
/*
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,SQUnsignedInteger *nparams,SQUnsignedInteger *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);
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);
} sq_api;
typedef sq_api* HSQAPI;
#ifdef __cplusplus
} /*extern "C"*/
#endif
#endif /*_SQ_MODULE_H_*/

@ -1,200 +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,SQUnsignedInteger *nparams,SQUnsignedInteger *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);
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);
} sq_api;
typedef sq_api* HSQAPI;
/// @endcond
#ifdef __cplusplus
} /*extern "C"*/
#endif
#endif /*_SQ_MODULE_H_*/

@ -56,7 +56,11 @@
#if !defined(_SCRAT_MAIN_H_)
#define _SCRAT_MAIN_H_
#include <squirrel.h>
#ifdef SQMOD_PLUGIN_API
#include <sq_api.h>
#else
#include <squirrel.h>
#endif // SQMOD_PLUGIN_API
#include "sqrat/sqratTable.h"
#include "sqrat/sqratClass.h"

@ -28,7 +28,12 @@
#if !defined(_SCRAT_ALLOCATOR_H_)
#define _SCRAT_ALLOCATOR_H_
#include <squirrel.h>
#ifdef SQMOD_PLUGIN_API
#include <sq_api.h>
#else
#include <squirrel.h>
#endif // SQMOD_PLUGIN_API
#include <string.h>
#include "sqratObject.h"

@ -28,7 +28,12 @@
#if !defined(_SCRAT_ARRAY_H_)
#define _SCRAT_ARRAY_H_
#include <squirrel.h>
#ifdef SQMOD_PLUGIN_API
#include <sq_api.h>
#else
#include <squirrel.h>
#endif // SQMOD_PLUGIN_API
#include <string.h>
#include "sqratObject.h"

@ -28,9 +28,14 @@
#if !defined(_SCRAT_CLASS_H_)
#define _SCRAT_CLASS_H_
#ifdef SQMOD_PLUGIN_API
#include <sq_api.h>
#else
#include <squirrel.h>
#endif // SQMOD_PLUGIN_API
#include <typeinfo>
#include <squirrel.h>
#include <string.h>
#include "sqratObject.h"
#include "sqratClassType.h"

@ -28,7 +28,12 @@
#if !defined(_SCRAT_CLASSTYPE_H_)
#define _SCRAT_CLASSTYPE_H_
#include <squirrel.h>
#ifdef SQMOD_PLUGIN_API
#include <sq_api.h>
#else
#include <squirrel.h>
#endif // SQMOD_PLUGIN_API
#include <typeinfo>
#include "sqratUtil.h"

@ -28,7 +28,12 @@
#if !defined(_SCRAT_CONST_H_)
#define _SCRAT_CONST_H_
#include <squirrel.h>
#ifdef SQMOD_PLUGIN_API
#include <sq_api.h>
#else
#include <squirrel.h>
#endif // SQMOD_PLUGIN_API
#include <string.h>
#include "sqratObject.h"

@ -29,7 +29,12 @@
#if !defined(_SCRAT_SQFUNC_H_)
#define _SCRAT_SQFUNC_H_
#include <squirrel.h>
#ifdef SQMOD_PLUGIN_API
#include <sq_api.h>
#else
#include <squirrel.h>
#endif // SQMOD_PLUGIN_API
#include "sqratObject.h"
namespace Sqrat {

@ -29,7 +29,12 @@
#if !defined(_SCRAT_GLOBAL_METHODS_H_)
#define _SCRAT_GLOBAL_METHODS_H_
#include <squirrel.h>
#ifdef SQMOD_PLUGIN_API
#include <sq_api.h>
#else
#include <squirrel.h>
#endif // SQMOD_PLUGIN_API
#include "sqratTypes.h"
namespace Sqrat {

@ -29,7 +29,12 @@
#if !defined(_SCRAT_MEMBER_METHODS_H_)
#define _SCRAT_MEMBER_METHODS_H_
#include <squirrel.h>
#ifdef SQMOD_PLUGIN_API
#include <sq_api.h>
#else
#include <squirrel.h>
#endif // SQMOD_PLUGIN_API
#include "sqratTypes.h"
namespace Sqrat {

@ -28,7 +28,12 @@
#if !defined(_SCRAT_OBJECT_H_)
#define _SCRAT_OBJECT_H_
#include <squirrel.h>
#ifdef SQMOD_PLUGIN_API
#include <sq_api.h>
#else
#include <squirrel.h>
#endif // SQMOD_PLUGIN_API
#include <string.h>
#include "sqratAllocator.h"

@ -28,8 +28,12 @@
#if !defined(_SQRAT_OVERLOAD_METHODS_H_)
#define _SQRAT_OVERLOAD_METHODS_H_
#include <squirrel.h>
#include <sqstdaux.h>
#ifdef SQMOD_PLUGIN_API
#include <sq_api.h>
#else
#include <squirrel.h>
#endif // SQMOD_PLUGIN_API
#include <sstream>
#include "sqratTypes.h"
#include "sqratUtil.h"

@ -28,8 +28,13 @@
#if !defined(_SCRAT_SCRIPT_H_)
#define _SCRAT_SCRIPT_H_
#include <squirrel.h>
#include <sqstdio.h>
#ifdef SQMOD_PLUGIN_API
#include <sq_api.h>
#else
#include <squirrel.h>
#include <sqstdio.h>
#endif // SQMOD_PLUGIN_API
#include <string.h>
#include "sqratObject.h"

@ -28,7 +28,12 @@
#if !defined(_SCRAT_TABLE_H_)
#define _SCRAT_TABLE_H_
#include <squirrel.h>
#ifdef SQMOD_PLUGIN_API
#include <sq_api.h>
#else
#include <squirrel.h>
#endif // SQMOD_PLUGIN_API
#include <string.h>
#include "sqratObject.h"

@ -1,43 +0,0 @@
//
// SqratThread: Sqrat threading module
//
//
// 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(_SQRAT_THREAD_H_)
#define _SQRAT_THREAD_H_
#include "sqmodule.h"
#ifdef __cplusplus
extern "C" {
#endif
__declspec(dllexport) SQRESULT sqmodule_load(HSQUIRRELVM v, HSQAPI api);
#ifdef __cplusplus
} /*extern "C"*/
#endif
#endif /*_SQRAT_THREAD_H_*/

@ -33,7 +33,12 @@
#include <cstring>
#endif
#include <squirrel.h>
#ifdef SQMOD_PLUGIN_API
#include <sq_api.h>
#else
#include <squirrel.h>
#endif // SQMOD_PLUGIN_API
#include <string>
#include "sqratClassType.h"

@ -28,9 +28,14 @@
#if !defined(_SCRAT_UTIL_H_)
#define _SCRAT_UTIL_H_
#ifdef SQMOD_PLUGIN_API
#include <sq_api.h>
#else
#include <squirrel.h>
#endif // SQMOD_PLUGIN_API
#include <cassert>
#include <map>
#include <squirrel.h>
#include <string.h>
#if defined(SCRAT_USE_CXX11_OPTIMIZATIONS)

@ -1,348 +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];
scsprintf(buf, 512, _SC("%s:%d:%d: %s"), source, (int) line, (int) column, desc);
buf[sizeof(buf) - 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

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

@ -194,6 +194,7 @@ typedef struct tagSQFunctionInfo {
SQInteger line;
}SQFunctionInfo;
#ifndef SQMOD_PLUGIN_API
/*vm*/
SQUIRREL_API HSQUIRRELVM sq_open(SQInteger initialstacksize);
SQUIRREL_API HSQUIRRELVM sq_newthread(HSQUIRRELVM friendvm, SQInteger initialstacksize);
@ -361,6 +362,7 @@ SQUIRREL_API void sq_free(void *p,SQUnsignedInteger size);
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);
#endif // SQMOD_PLUGIN_API
/*UTILITY MACRO*/
#define sq_isnumeric(o) ((o)._type&SQOBJECT_NUMERIC)