1
0
mirror of https://github.com/VCMP-SqMod/SqMod.git synced 2024-11-08 00:37:15 +01: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

View File

@ -263,6 +263,7 @@
<Unit filename="../source/Entity/Textdraw.hpp" />
<Unit filename="../source/Entity/Vehicle.cpp" />
<Unit filename="../source/Entity/Vehicle.hpp" />
<Unit filename="../source/Exports.cpp" />
<Unit filename="../source/Library/Datetime.cpp" />
<Unit filename="../source/Library/Datetime.hpp" />
<Unit filename="../source/Library/FileIO.cpp" />

199
cbp/Sample.cbp Normal file
View File

@ -0,0 +1,199 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<CodeBlocks_project_file>
<FileVersion major="1" minor="6" />
<Project>
<Option title="Sample" />
<Option pch_mode="2" />
<Option compiler="gcc" />
<Build>
<Target title="Win32 Debug Dynamic">
<Option output="../bin/win32-d/sample32" imp_lib="$(TARGET_OUTPUT_DIR)$(TARGET_OUTPUT_BASENAME).a" def_file="$(TARGET_OUTPUT_DIR)$(TARGET_OUTPUT_BASENAME).def" prefix_auto="0" extension_auto="1" />
<Option working_dir="../bin/win32-d/" />
<Option object_output="../obj/mingw32-d/" />
<Option type="3" />
<Option compiler="gcc" />
<Compiler>
<Add option="-m32" />
<Add option="-g" />
<Add option="-D_DEBUG" />
<Add directory="../config/mingw32" />
</Compiler>
<Linker>
<Add option="-m32" />
<Add option="-static" />
<Add directory="../lib/mingw32-d" />
</Linker>
<ExtraCommands>
<Add after='cmd /c copy /Y &quot;$(PROJECT_DIR)$(TARGET_OUTPUT_FILE)&quot; &quot;$(PROJECT_DIR)..\bin\plugins\$(TARGET_OUTPUT_BASENAME).dll&quot;' />
</ExtraCommands>
</Target>
<Target title="Win32 Release Dynamic">
<Option output="../bin/win32/sample32" imp_lib="$(TARGET_OUTPUT_DIR)$(TARGET_OUTPUT_BASENAME).a" def_file="$(TARGET_OUTPUT_DIR)$(TARGET_OUTPUT_BASENAME).def" prefix_auto="0" extension_auto="1" />
<Option working_dir="../bin/win32/" />
<Option object_output="../obj/mingw32/" />
<Option type="3" />
<Option compiler="gcc" />
<Compiler>
<Add option="-O3" />
<Add option="-m32" />
<Add option="-DNDEBUG" />
<Add directory="../config/mingw32" />
</Compiler>
<Linker>
<Add option="-s" />
<Add option="-m32" />
<Add option="-static" />
<Add directory="../lib/mingw32" />
</Linker>
<ExtraCommands>
<Add after='cmd /c copy /Y &quot;$(PROJECT_DIR)$(TARGET_OUTPUT_FILE)&quot; &quot;$(PROJECT_DIR)..\bin\plugins\$(TARGET_OUTPUT_BASENAME).dll&quot;' />
</ExtraCommands>
</Target>
<Target title="Win64 Debug Dynamic">
<Option output="../bin/win64-d/sample64" imp_lib="$(TARGET_OUTPUT_DIR)$(TARGET_OUTPUT_BASENAME).a" def_file="$(TARGET_OUTPUT_DIR)$(TARGET_OUTPUT_BASENAME).def" prefix_auto="0" extension_auto="1" />
<Option working_dir="../bin/win64-d/" />
<Option object_output="../obj/mingw64-d/" />
<Option type="3" />
<Option compiler="gcc" />
<Compiler>
<Add option="-m64" />
<Add option="-g" />
<Add option="-D_DEBUG" />
<Add option="-D_SQ64" />
<Add directory="../config/mingw64" />
</Compiler>
<Linker>
<Add option="-m64" />
<Add option="-static" />
<Add directory="../lib/mingw64-d" />
</Linker>
<ExtraCommands>
<Add after='cmd /c copy /Y &quot;$(PROJECT_DIR)$(TARGET_OUTPUT_FILE)&quot; &quot;$(PROJECT_DIR)..\bin\plugins\$(TARGET_OUTPUT_BASENAME).dll&quot;' />
</ExtraCommands>
</Target>
<Target title="Win64 Release Dynamic">
<Option output="../bin/win64/sample64" imp_lib="$(TARGET_OUTPUT_DIR)$(TARGET_OUTPUT_BASENAME).a" def_file="$(TARGET_OUTPUT_DIR)$(TARGET_OUTPUT_BASENAME).def" prefix_auto="0" extension_auto="1" />
<Option working_dir="../bin/win64/" />
<Option object_output="../obj/mingw64/" />
<Option type="3" />
<Option compiler="gcc" />
<Compiler>
<Add option="-O3" />
<Add option="-m64" />
<Add option="-DNDEBUG" />
<Add option="-D_SQ64" />
<Add directory="../config/mingw64" />
</Compiler>
<Linker>
<Add option="-s" />
<Add option="-m64" />
<Add option="-static" />
<Add directory="../lib/mingw64" />
</Linker>
<ExtraCommands>
<Add after='cmd /c copy /Y &quot;$(PROJECT_DIR)$(TARGET_OUTPUT_FILE)&quot; &quot;$(PROJECT_DIR)..\bin\plugins\$(TARGET_OUTPUT_BASENAME).dll&quot;' />
</ExtraCommands>
</Target>
<Target title="Linux32 Debug Dynamic">
<Option output="../bin/linux32-d/sample32" imp_lib="$(TARGET_OUTPUT_DIR)$(TARGET_OUTPUT_BASENAME).a" def_file="$(TARGET_OUTPUT_DIR)$(TARGET_OUTPUT_BASENAME).def" prefix_auto="0" extension_auto="1" />
<Option working_dir="../bin/linux32-d/" />
<Option object_output="../obj/gcc32-d/" />
<Option type="3" />
<Option compiler="gcc" />
<Compiler>
<Add option="-m32" />
<Add option="-g" />
<Add option="-fPIC" />
<Add option="-D_DEBUG" />
<Add directory="../config/gcc32" />
</Compiler>
<Linker>
<Add option="-m32" />
<Add option="-Bstatic" />
<Add directory="../lib/gcc32-d" />
</Linker>
</Target>
<Target title="Linux32 Release Dynamic">
<Option output="../bin/linux32/sample32" imp_lib="$(TARGET_OUTPUT_DIR)$(TARGET_OUTPUT_BASENAME).a" def_file="$(TARGET_OUTPUT_DIR)$(TARGET_OUTPUT_BASENAME).def" prefix_auto="0" extension_auto="1" />
<Option working_dir="../bin/linux32/" />
<Option object_output="../obj/gcc32/" />
<Option type="3" />
<Option compiler="gcc" />
<Compiler>
<Add option="-O3" />
<Add option="-m32" />
<Add option="-fPIC" />
<Add option="-DNDEBUG" />
<Add directory="../config/gcc32" />
</Compiler>
<Linker>
<Add option="-s" />
<Add option="-m32" />
<Add option="-Bstatic" />
<Add directory="../lib/gcc32" />
</Linker>
</Target>
<Target title="Linux64 Debug Dynamic">
<Option output="../bin/linux64-d/sample64" imp_lib="$(TARGET_OUTPUT_DIR)$(TARGET_OUTPUT_BASENAME).a" def_file="$(TARGET_OUTPUT_DIR)$(TARGET_OUTPUT_BASENAME).def" prefix_auto="0" extension_auto="1" />
<Option working_dir="../bin/linux64-d/" />
<Option object_output="../obj/gcc64-d/" />
<Option type="3" />
<Option compiler="gcc" />
<Compiler>
<Add option="-m64" />
<Add option="-g" />
<Add option="-fPIC" />
<Add option="-D_DEBUG" />
<Add option="-D_SQ64" />
<Add directory="../config/gcc64" />
</Compiler>
<Linker>
<Add option="-m64" />
<Add option="-Bstatic" />
<Add directory="../lib/gcc64-d" />
</Linker>
</Target>
<Target title="Linux64 Release Dynamic">
<Option output="../bin/linux64/sample64" imp_lib="$(TARGET_OUTPUT_DIR)$(TARGET_OUTPUT_BASENAME).a" def_file="$(TARGET_OUTPUT_DIR)$(TARGET_OUTPUT_BASENAME).def" prefix_auto="0" extension_auto="1" />
<Option working_dir="../bin/linux64/" />
<Option object_output="../obj/gcc64/" />
<Option type="3" />
<Option compiler="gcc" />
<Compiler>
<Add option="-O3" />
<Add option="-m64" />
<Add option="-fPIC" />
<Add option="-DNDEBUG" />
<Add option="-D_SQ64" />
<Add directory="../config/gcc64" />
</Compiler>
<Linker>
<Add option="-s" />
<Add option="-m64" />
<Add option="-Bstatic" />
<Add directory="../lib/gcc64" />
</Linker>
</Target>
</Build>
<Compiler>
<Add option="-Wall" />
<Add option="-static-libgcc" />
<Add option="-static-libstdc++" />
<Add option="-enable-static" />
<Add option="-DSQMOD_PLUGIN_API" />
<Add directory="../sample" />
<Add directory="../shared" />
<Add directory="../include" />
<Add directory="../config/common" />
</Compiler>
<Unit filename="../sample/Module.cpp" />
<Unit filename="../sample/Module.hpp" />
<Unit filename="../shared/sq_mod.cpp" />
<Extensions>
<code_completion />
<envvars />
<debugger />
<lib_finder disable_auto="1" />
</Extensions>
</Project>
</CodeBlocks_project_file>

View File

@ -5,6 +5,7 @@
<Project filename="Sandbox.cbp" />
<Project filename="Squirrel.cbp" />
<Project filename="SQLite.cbp" />
<Project filename="Hash.cbp" />
<Project filename="LibIRC.cbp" />
<Project filename="Sample.cbp" />
</Workspace>
</CodeBlocks_workspace_file>

View File

@ -1,373 +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.
//
//#include "sqratlib/sqratBase.h"
#include "sqratThread.h"
#include <time.h>
#include <string.h>
static HSQAPI sq;
//
// Thread lib utility functions (not visible externally)
//
static SQFloat sqrat_clock() {
return ((SQFloat)clock())/(SQFloat)CLOCKS_PER_SEC;
}
static SQInteger sqrat_strlen(const SQChar* str) {
#if defined(_UNICODE)
return static_cast<SQInteger>(wcslen(str) * sizeof(SQChar));
#else
return static_cast<SQInteger>(strlen(str) * sizeof(SQChar));
#endif
}
static void sqrat_pushtaskarray(HSQUIRRELVM v) {
HSQOBJECT taskarray;
sq->pushroottable(v);
sq->pushstring(v,_SC("__sqrat_taskarray__"),-1);
if(SQ_FAILED(sq->get(v, -2))) {
// Not found, create a new namespace
sq->pushstring(v,_SC("__sqrat_taskarray__"),-1);
sq->newarray(v, 0);
sq->getstackobj(v,-1,&taskarray); // Save namespace for later use
sq->newslot(v, -3, 0);
sq->pop(v, 1); // pop root table
sq->pushobject(v, taskarray); // push the newly bound array
} else {
sq->remove(v, -2); // pop sqrat table
}
}
static SQRESULT sqrat_pushclosure(HSQUIRRELVM v, const SQChar* script) {
if(SQ_FAILED(sq->compilebuffer(v, script, sqrat_strlen(script), _SC(""), true))) {
return SQ_ERROR;
}
sq->pushroottable(v);
if(SQ_FAILED(sq->call(v, 1, 0, 1))) {
sq->remove(v, -1); // remove compiled closure
return SQ_ERROR;
}
sq->remove(v, -2); // remove compiled closure
return SQ_OK;
}
static SQInteger sqrat_schedule_argcall(HSQUIRRELVM v) {
SQInteger nparams = sq->gettop(v) - 2; // Get the number of parameters provided
// The task table is the last argument (free variable), so we can operate on immediately
sq->pushstring(v, _SC("args"), -1);
sq->newarray(v, 0); // Create the array for the arguments
// Loop through all arguments and push them into the arg array
for(SQInteger i = 0; i < nparams; ++i) {
sq->push(v, i+2);
sq->arrayappend(v, -2);
}
sq->newslot(v, -3, 0); // Push the arg array into the task table
return 0;
}
// This is a horrid way to get this functionality in there, but I can't find any alternatives right now.
static SQRESULT sqrat_pushsleep(HSQUIRRELVM v) {
SQChar* sleep_script = _SC(" \
__sqratsleep__ <- function(timeout) { \
local begin = clock(); \
local now; \
do { \
::suspend(); \
now = clock(); \
} while( (now - begin) < timeout ); \
} \
");
if(SQ_FAILED(sq->compilebuffer(v, sleep_script, sqrat_strlen(sleep_script), _SC(""), true))) {
return SQ_ERROR;
}
sq->pushroottable(v);
if(SQ_FAILED(sq->call(v, 1, 0, 1))) {
sq->remove(v, -1); // remove compiled closure
return SQ_ERROR;
}
sq->remove(v, -1); // remove compiled closure
sq->pushroottable(v);
sq->pushstring(v, _SC("__sqratsleep__"), -1);
SQRESULT res = sq->get(v, -2);
sq->remove(v, -2); // remove root table
return res;
}
//
// Thread lib main functions
//
static SQRESULT sqrat_sleep(HSQUIRRELVM v, SQFloat timeout) {
return sq->suspendvm(v);
// Get "::suspend"
/*HSQOBJECT suspend;
sq->pushroottable(v);
sq->pushstring(v, _SC("suspend"), -1);
if(SQ_FAILED(sq->get(v, -2))) {
return SQ_ERROR;
}
sq->getstackobj(v, -1, &suspend);
sq->pop(v, 2);
// Loop ::suspend until the appropriate time has passed
SQFloat timeStart = sqrat_clock();
SQFloat timeNow = 0;
while(timeNow - timeStart < timeout) {
sq->pushobject(v, suspend);
sq->pushroottable(v);
if(SQ_FAILED(sq->call(v, 1, 0, 1))) {
return SQ_ERROR;
}
timeNow = sqrat_clock();
}
return SQ_OK;*/
}
static void sqrat_schedule(HSQUIRRELVM v, SQInteger idx) {
HSQOBJECT thread;
HSQOBJECT func;
HSQOBJECT task;
sq->getstackobj(v, idx, &func);
SQInteger stksize = 256; // TODO: Allow initial stack size to be configurable
sqrat_pushtaskarray(v); // Push the task array
// Create the task
sq->newtable(v);
sq->getstackobj(v, -1, &task);
// Create the thread and add it to the task table
sq->pushstring(v, _SC("thread"), -1);
sq->newthread(v, stksize);
sq->getstackobj(v, -1, &thread);
sq->newslot(v, -3, 0);
// Push the function to be called onto the thread stack
sq->pushobject(v, func);
sq->move(thread._unVal.pThread, v, -1);
sq->pop(v, 1);
// Args will be pushed later, in the closure
sq->arrayappend(v, -2); // Add the task to the task array
sq->pushobject(v, task); // Push the task object as a free variable for the temporary closure
sq->newclosure(v, sqrat_schedule_argcall, 1); // push a temporary closure used to retrieve call args
}
// Wow... this has to be one of the ugliest functions I've ever writter. Ever.
// Building complex logic with the squirrel stack really sucks.
static void sqrat_run(HSQUIRRELVM v) {
HSQOBJECT taskArray;
HSQOBJECT thread;
HSQUIRRELVM threadVm;
SQInteger nparams; // Number of parameters to pass to a function
SQInteger arrayidx; //Cached index of the task array
// Push the tasklist
sqrat_pushtaskarray(v); // Push the task array to the stack
sq->getstackobj(v, -1, &taskArray);
arrayidx = sq->gettop(v); // Cache the stack location of the task array
SQInteger tasklistSize = sq->getsize(v, arrayidx); // Query the initial size of the task array
do {
SQInteger i = 0;
// This outer while is to allow us to pick up any new tasks that are added during the loop,
// but still give us an opportunity to sleep after running through the initial tasks
while(i < tasklistSize) {
for(; i < tasklistSize; ++i) {
sq->pushinteger(v, i);
if(SQ_FAILED(sq->get(v, -2))) { // Get the task
sq->arrayremove(v, -2, i);
sq->pop(v, 1);
--tasklistSize;
--i;
continue;
}
// Now that we have the task, get the thread
sq->pushstring(v, _SC("thread"), -1);
if(SQ_FAILED(sq->get(v, -2))) {
sq->arrayremove(v, -3, i);
sq->pop(v, 1);
--tasklistSize;
--i;
continue;
}
sq->getstackobj(v, -1, &thread);
sq->pop(v, 1);
threadVm = thread._unVal.pThread;
if(sq->getvmstate(threadVm) == SQ_VMSTATE_IDLE) { // New thread? If so we need to call it
// Function to be called is already pushed to the thread (happens in schedule)
sq->pushroottable(threadVm); // Pus the threads root table
sq->pushstring(v, _SC("args"), -1);
if(SQ_FAILED(sq->get(v, -2))) { // Check to see if we have arguments for this thread
nparams = 0; // No arguments
} else {
nparams = sq->getsize(v, -1); // Get the number of args in the arg array
// Push the arguments onto the thread stack
for(SQInteger a = 0; a < nparams; ++a) {
sq->pushinteger(v, a);
if(SQ_FAILED(sq->get(v, -2))) {
sq->pushnull(threadVm); // Is this the best way to handle this?
} else {
sq->move(threadVm, v, -1);
sq->pop(v, 1);
}
}
sq->pop(v, 1); // Pop the arg array
}
sq->call(threadVm, nparams+1, 0, 1); // Call the thread
} else {
// If the thread is suspended, wake it up.
// This function changed in Squirrel 2.2.3,
// removing the last parameter makes it compatible with 2.2.2 and earlier
sq->wakeupvm(threadVm, 0, 0, 1, 0);
}
if(sq->getvmstate(threadVm) == SQ_VMSTATE_IDLE) { // Check to see if the thread is finished (idle again)
sq->arrayremove(v, -2, i); // Remove the task from the task array
--tasklistSize; // Adjust the for variables to account for the removal
--i;
}
sq->pop(v, 1); // Pop off the task
}
// Yield to system if needed
tasklistSize = sq->getsize(v, arrayidx); // Get the task
}
} while(tasklistSize > 0); // Loop until we have no more pending tasks
}
//
// Script interface functions
//
static SQInteger sqratbase_sleep(HSQUIRRELVM v) {
SQFloat timeout;
sq->getfloat(v, -1, &timeout);
sqrat_sleep(v, timeout);
return 0;
}
static SQInteger sqratbase_schedule(HSQUIRRELVM v) {
sqrat_schedule(v, -1);
return 1;
}
static SQInteger sqratbase_run(HSQUIRRELVM v) {
sqrat_run(v);
return 0;
}
// This is a squirrel only function, since there's really no need to
// expose a native api for it. Just use the VM that you would have passed
// in anyway!
static SQInteger sqratbase_getthread(HSQUIRRELVM v) {
// For the record, this way of doing things really sucks.
// I would love a better way of retrieving this object!
HSQOBJECT threadObj;
threadObj._type = OT_THREAD;
threadObj._unVal.pThread = v;
sq->pushobject(v, threadObj);
sq->weakref(v, -1);
sq->remove(v, -2);
return 1;
}
//
// Module registration
//
SQRESULT sqmodule_load(HSQUIRRELVM v, HSQAPI api) {
sq = api;
sq->pushstring(v, _SC("schedule"), -1);
sq->newclosure(v, &sqratbase_schedule, 0);
sq->newslot(v, -3, 0);
sq->pushstring(v, _SC("run"), -1);
sq->newclosure(v, &sqratbase_run, 0);
sq->newslot(v, -3, 0);
sq->pushstring(v, _SC("getthread"), -1);
sq->newclosure(v, &sqratbase_getthread, 0);
sq->newslot(v, -3, 0);
// Would rather do this...
/*sq->pushstring(v, _SC("sleep"), -1);
sq->newclosure(v, &sqratbase_sleep, 0);
sq->newslot(v, -3, 0);*/
// Than this...
sq->pushstring(v, _SC("sleep"), -1);
if(SQ_FAILED(sqrat_pushsleep(v))) {
sq->pop(v, 1);
} else {
sq->newslot(v, -3, 0);
}
return SQ_OK;
}

View File

@ -1,308 +0,0 @@
//
// SqratImport: 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.
//
#include "sqratimport.h"
#include "sqmodule.h"
//#include "sqratlib/sqratBase.h"
#include <sqstdio.h>
#include <string>
#if defined(_WIN32)
#include <windows.h>
#elif defined(__unix)
#include <dlfcn.h>
#endif
typedef SQRESULT (*SQMODULELOAD)(HSQUIRRELVM v, HSQAPI sq);
static HSQAPI sqapi = NULL;
// Create and populate the HSQAPI structure with function pointers
// If new functions are added to the Squirrel API, they should be added here too
static HSQAPI sqrat_newapi() {
HSQAPI sq = (HSQAPI)sq_malloc(sizeof(sq_api));
/*vm*/
sq->open = sq_open;
sq->newthread = sq_newthread;
sq->seterrorhandler = sq_seterrorhandler;
sq->close = sq_close;
sq->setforeignptr = sq_setforeignptr;
sq->getforeignptr = sq_getforeignptr;
sq->setprintfunc = sq_setprintfunc;
sq->getprintfunc = sq_getprintfunc;
sq->suspendvm = sq_suspendvm;
sq->wakeupvm = sq_wakeupvm;
sq->getvmstate = sq_getvmstate;
/*compiler*/
sq->compile = sq_compile;
sq->compilebuffer = sq_compilebuffer;
sq->enabledebuginfo = sq_enabledebuginfo;
sq->notifyallexceptions = sq_notifyallexceptions;
sq->setcompilererrorhandler = sq_setcompilererrorhandler;
/*stack operations*/
sq->push = sq_push;
sq->pop = sq_pop;
sq->poptop = sq_poptop;
sq->remove = sq_remove;
sq->gettop = sq_gettop;
sq->settop = sq_settop;
sq->reservestack = sq_reservestack;
sq->cmp = sq_cmp;
sq->move = sq_move;
/*object creation handling*/
sq->newuserdata = sq_newuserdata;
sq->newtable = sq_newtable;
sq->newarray = sq_newarray;
sq->newclosure = sq_newclosure;
sq->setparamscheck = sq_setparamscheck;
sq->bindenv = sq_bindenv;
sq->pushstring = sq_pushstring;
sq->pushfloat = sq_pushfloat;
sq->pushinteger = sq_pushinteger;
sq->pushbool = sq_pushbool;
sq->pushuserpointer = sq_pushuserpointer;
sq->pushnull = sq_pushnull;
sq->gettype = sq_gettype;
sq->getsize = sq_getsize;
sq->getbase = sq_getbase;
sq->instanceof = sq_instanceof;
sq->tostring = sq_tostring;
sq->tobool = sq_tobool;
sq->getstring = sq_getstring;
sq->getinteger = sq_getinteger;
sq->getthread = sq_getthread;
sq->getbool = sq_getbool;
sq->getuserpointer = sq_getuserpointer;
sq->getuserdata = sq_getuserdata;
sq->settypetag = sq_settypetag;
sq->gettypetag = sq_gettypetag;
sq->setreleasehook = sq_setreleasehook;
sq->getscratchpad = sq_getscratchpad;
sq->getclosureinfo = sq_getclosureinfo;
sq->setnativeclosurename = sq_setnativeclosurename;
sq->setinstanceup = sq_setinstanceup;
sq->getinstanceup = sq_getinstanceup;
sq->setclassudsize = sq_setclassudsize;
sq->newclass = sq_newclass;
sq->createinstance = sq_createinstance;
sq->setattributes = sq_setattributes;
sq->getattributes = sq_getattributes;
sq->getclass = sq_getclass;
sq->weakref = sq_weakref;
sq->getdefaultdelegate = sq_getdefaultdelegate;
/*object manipulation*/
sq->pushroottable = sq_pushroottable;
sq->pushregistrytable = sq_pushregistrytable;
sq->pushconsttable = sq_pushconsttable;
sq->setroottable = sq_setroottable;
sq->setconsttable = sq_setconsttable;
sq->newslot = sq_newslot;
sq->deleteslot = sq_deleteslot;
sq->set = sq_set;
sq->get = sq_get;
sq->rawset = sq_rawset;
sq->rawget = sq_rawget;
sq->rawdeleteslot = sq_rawdeleteslot;
sq->arrayappend = sq_arrayappend;
sq->arraypop = sq_arraypop;
sq->arrayresize = sq_arrayresize;
sq->arrayreverse = sq_arrayreverse;
sq->arrayremove = sq_arrayremove;
sq->arrayinsert = sq_arrayinsert;
sq->setdelegate = sq_setdelegate;
sq->getdelegate = sq_getdelegate;
sq->clone = sq_clone;
sq->setfreevariable = sq_setfreevariable;
sq->next = sq_next;
sq->getweakrefval = sq_getweakrefval;
sq->clear = sq_clear;
/*calls*/
sq->call = sq_call;
sq->resume = sq_resume;
sq->getlocal = sq_getlocal;
sq->getfreevariable = sq_getfreevariable;
sq->throwerror = sq_throwerror;
sq->reseterror = sq_reseterror;
sq->getlasterror = sq_getlasterror;
/*raw object handling*/
sq->getstackobj = sq_getstackobj;
sq->pushobject = sq_pushobject;
sq->addref = sq_addref;
sq->release = sq_release;
sq->resetobject = sq_resetobject;
sq->objtostring = sq_objtostring;
sq->objtobool = sq_objtobool;
sq->objtointeger = sq_objtointeger;
sq->objtofloat = sq_objtofloat;
sq->getobjtypetag = sq_getobjtypetag;
/*GC*/
sq->collectgarbage = sq_collectgarbage;
/*serialization*/
sq->writeclosure = sq_writeclosure;
sq->readclosure = sq_readclosure;
/*mem allocation*/
sq->malloc = sq_malloc;
sq->realloc = sq_realloc;
sq->free = sq_free;
/*debug*/
sq->stackinfos = sq_stackinfos;
sq->setdebughook = sq_setdebughook;
return sq;
}
static SQRESULT sqrat_importscript(HSQUIRRELVM v, const SQChar* moduleName) {
std::basic_string<SQChar> filename(moduleName);
filename += _SC(".nut");
if(SQ_FAILED(sqstd_loadfile(v, moduleName, true))) {
if(SQ_FAILED(sqstd_loadfile(v, filename.c_str(), true))) {
return SQ_ERROR;
}
}
sq_push(v, -2);
sq_call(v, 1, false, true);
return SQ_OK;
}
static SQRESULT sqrat_importbin(HSQUIRRELVM v, const SQChar* moduleName) {
#ifdef SQUNICODE
#warning sqrat_importbin() Not Implemented
return SQ_ERROR;
#else
SQMODULELOAD modLoad = 0;
#if defined(_WIN32)
HMODULE mod;
mod = GetModuleHandle(moduleName);
if(mod == NULL) {
mod = LoadLibrary(moduleName);
if(mod == NULL) {
return SQ_ERROR;
}
}
modLoad = (SQMODULELOAD)GetProcAddress(mod, "sqmodule_load");
if(modLoad == NULL) {
FreeLibrary(mod);
return SQ_ERROR;
}
#elif defined(__unix)
/* adding .so to moduleName? */
void *mod = dlopen(moduleName, RTLD_NOW | RTLD_LOCAL | RTLD_NOLOAD); //RTLD_NOLOAD flag is not specified in POSIX.1-2001..so not the best solution :(
if (mod == NULL) {
mod = dlopen(moduleName, RTLD_NOW | RTLD_LOCAL);
if (mod == NULL)
return SQ_ERROR;
}
modLoad = (SQMODULELOAD) dlsym(mod, "sqmodule_load");
if (modLoad == NULL) {
dlclose(mod);
return SQ_ERROR;
}
#endif
if(sqapi == NULL) {
sqapi = sqrat_newapi(); // Caching this for multiple imports is probably a very good idea
}
SQRESULT res = modLoad(v, sqapi);
return res;
#endif
}
SQRESULT sqrat_import(HSQUIRRELVM v) {
const SQChar* moduleName;
HSQOBJECT table;
SQRESULT res = SQ_OK;
sq_getstring(v, -2, &moduleName);
sq_getstackobj(v, -1, &table);
sq_addref(v, &table);
sq_settop(v, 0); // Clear Stack
sq_pushobject(v, table); // Push the target table onto the stack
if(SQ_FAILED(sqrat_importscript(v, moduleName))) {
res = sqrat_importbin(v, moduleName);
}
sq_settop(v, 0); // Clean up the stack (just in case the module load leaves it messy)
sq_pushobject(v, table); // return the target table
sq_release(v, &table);
return res;
}
static SQInteger sqratbase_import(HSQUIRRELVM v) {
SQInteger args = sq_gettop(v);
switch(args) {
case 2:
sq_pushroottable(v);
break;
case 3:
// should already have the desired table pushed onto the stack
break;
default:
// Error, unexpected number of arguments
break;
}
sqrat_import(v);
return 1;
}
SQRESULT sqrat_register_importlib(HSQUIRRELVM v) {
sq_pushroottable(v);
sq_pushstring(v, _SC("import"), -1);
sq_newclosure(v, &sqratbase_import, 0);
sq_newslot(v, -3, 0);
sq_pop(v, 1); // pop sqrat table
return SQ_OK;
}

View File

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

View File

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

View File

@ -56,7 +56,11 @@
#if !defined(_SCRAT_MAIN_H_)
#define _SCRAT_MAIN_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"

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -28,8 +28,13 @@
#if !defined(_SCRAT_SCRIPT_H_)
#define _SCRAT_SCRIPT_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"

View File

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

View File

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

View File

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

View File

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

View File

@ -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

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

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

229
sample/Module.cpp Normal file
View File

@ -0,0 +1,229 @@
// --------------------------------------------------------------------------------------------
#include "Module.hpp"
#include "sq_mod.h"
// --------------------------------------------------------------------------------------------
#include <sqrat.h>
// --------------------------------------------------------------------------------------------
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
// --------------------------------------------------------------------------------------------
#if defined(WIN32) || defined(_WIN32)
#include <Windows.h>
#endif
// --------------------------------------------------------------------------------------------
PluginFuncs* _Func = NULL;
PluginCallbacks* _Clbk = NULL;
PluginInfo* _Info = NULL;
// --------------------------------------------------------------------------------------------
HSQAPI _SqAPI = NULL;
HSQUIRRELVM _SqVm = NULL;
// ------------------------------------------------------------------------------------------------
void BindCallbacks();
void UnbindCallbacks();
// --------------------------------------------------------------------------------------------
void RegisterAPI(HSQUIRRELVM vm);
// --------------------------------------------------------------------------------------------
void OnSquirrelInitialize()
{
HSQEXPORTS exp = sq_api_import(_Func);
// Did we failed to obtain the plugin exports?
if(!exp)
OutputMessage("Failed to attach to %s", SQMOD_HOST_NAME);
else
{
// Obtain the Squirrel API and VM
_SqAPI = exp->GetSquirrelAPI();
_SqVm = exp->GetSquirrelVM();
// Expand the API into global functions
sq_api_expand(_SqAPI);
// Register functions
RegisterAPI(_SqVm);
}
}
// --------------------------------------------------------------------------------------------
void OnSquirrelTerminate()
{
OutputMessage("Terminating sample plugin...");
// The server may still send callbacks
UnbindCallbacks();
// Release squirrel resources...
}
// --------------------------------------------------------------------------------------------
int OnInternalCommand(unsigned int type, const char * text)
{
switch(type)
{
case SQMOD_INITIALIZE_CMD:
OnSquirrelInitialize();
break;
case SQMOD_TERMINATE_CMD:
OnSquirrelTerminate();
break;
default: break;
}
return 1;
}
// --------------------------------------------------------------------------------------------
int OnInitServer()
{
puts("");
OutputMessage("Loaded Sample Squirrel Plugin");
return 1;
}
// --------------------------------------------------------------------------------------------
SQMOD_API_EXPORT unsigned int VcmpPluginInit(PluginFuncs* functions, PluginCallbacks* callbacks, PluginInfo* info)
{
// Store server proxies
_Func = functions;
_Clbk = callbacks;
_Info = info;
// Assign plugin information
_Info->uPluginVer = 0x1000; // 1.0.00
strcpy(_Info->szName, "SampleSquirrelPlugin");
// Expand the API into global functions
vc_api_expand(_Func);
// Bind callbacks
BindCallbacks();
// Done!
return 1;
}
// ------------------------------------------------------------------------------------------------
void BindCallbacks()
{
_Clbk->OnInitServer = OnInitServer;
_Clbk->OnInternalCommand = OnInternalCommand;
}
// ------------------------------------------------------------------------------------------------
void UnbindCallbacks()
{
_Clbk->OnInitServer = NULL;
_Clbk->OnInternalCommand = NULL;
}
// --------------------------------------------------------------------------------------------
void OutputMessageImpl(const char * msg, va_list args)
{
#if defined(WIN32) || defined(_WIN32)
HANDLE hstdout = GetStdHandle(STD_OUTPUT_HANDLE);
CONSOLE_SCREEN_BUFFER_INFO csb_before;
GetConsoleScreenBufferInfo( hstdout, &csb_before);
SetConsoleTextAttribute(hstdout, FOREGROUND_GREEN);
printf("[MODULE] ");
SetConsoleTextAttribute(hstdout, FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_RED | FOREGROUND_INTENSITY);
vprintf(msg, args);
puts("");
SetConsoleTextAttribute(hstdout, csb_before.wAttributes);
#else
printf("%c[0;32m[MODULE]%c[0;37m", 27, 27, msg);
vprintf(msg, args);
puts("");
#endif
}
// --------------------------------------------------------------------------------------------
void OutputDebug(const char * msg, ...)
{
#ifdef _DEBUG
// Initialize the arguments list
va_list args;
va_start(args, msg);
// Call the output function
OutputMessageImpl(msg, args);
// Finalize the arguments list
va_end(args);
#endif
}
// --------------------------------------------------------------------------------------------
void OutputMessage(const char * msg, ...)
{
// Initialize the arguments list
va_list args;
va_start(args, msg);
// Call the output function
OutputMessageImpl(msg, args);
// Finalize the arguments list
va_end(args);
}
/* --------------------------------------------------------------------------------------------
* Sample Plugin API
*/
int SampleFunction()
{
OutputMessage("Hello from the sample plugin function!");
return rand();
}
class SampleType
{
private:
int m_MyVal;
public:
int mMyNum;
SampleType()
: m_MyVal(0), mMyNum(0)
{
}
SampleType(int num)
: m_MyVal(num * 2), mMyNum(num)
{
}
int GetMyVal() const
{
return m_MyVal;
}
void SetMyVal(int val)
{
m_MyVal = val;
}
void SampleMethod() const
{
OutputMessage("I have the values %d and %d", m_MyVal, mMyNum);
}
};
// --------------------------------------------------------------------------------------------
void RegisterAPI(HSQUIRRELVM vm)
{
using namespace Sqrat;
RootTable(vm).Bind(_SC("SampleType"), Class< SampleType >(vm, _SC("SampleType"))
.Ctor()
.Ctor< int >()
.Var(_SC("MyNum"), &SampleType::mMyNum)
.Prop(_SC("MyVal"), &SampleType::GetMyVal, &SampleType::SetMyVal)
.Func(_SC("SampleMethod"), &SampleType::SampleMethod)
);
RootTable(vm).Func(_SC("SampleFunction"), &SampleFunction);
}

31
sample/Module.hpp Normal file
View File

@ -0,0 +1,31 @@
#ifndef _SQMOD_MODULE_HPP_
#define _SQMOD_MODULE_HPP_
// ------------------------------------------------------------------------------------------------
#include "sq_api.h"
#include "vcmp.h"
/* ------------------------------------------------------------------------------------------------
* Proxies to comunicate with the server.
*/
extern PluginFuncs* _Func;
extern PluginCallbacks* _Clbk;
extern PluginInfo* _Info;
/* ------------------------------------------------------------------------------------------------
* Proxies to comunicate with the Squirrel plugin.
*/
extern HSQAPI _SqAPI;
extern HSQUIRRELVM _SqVm;
/* ------------------------------------------------------------------------------------------------
* Output a message only if the _DEBUG was defined.
*/
void OutputDebug(const char * msg, ...);
/* ------------------------------------------------------------------------------------------------
* Output a formatted message to the console.
*/
void OutputMessage(const char * msg, ...);
#endif // _SQMOD_MODULE_HPP_

594
shared/sq_api.h Normal file
View File

@ -0,0 +1,594 @@
//
// SqModule: API used to communicate with and register squirrel modules
//
//
// Copyright (c) 2015 Sandu Liviu Catalin
//
// 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_API_H_)
#define _SQ_API_H_
#include "squirrel.h"
#ifdef __cplusplus
extern "C" {
#endif
/*vm*/
typedef HSQUIRRELVM (*sqapi_open)(SQInteger initialstacksize);
typedef HSQUIRRELVM (*sqapi_newthread)(HSQUIRRELVM friendvm, SQInteger initialstacksize);
typedef void (*sqapi_seterrorhandler)(HSQUIRRELVM v);
typedef void (*sqapi_close)(HSQUIRRELVM v);
typedef void (*sqapi_setforeignptr)(HSQUIRRELVM v,SQUserPointer p);
typedef SQUserPointer (*sqapi_getforeignptr)(HSQUIRRELVM v);
typedef void (*sqapi_setsharedforeignptr)(HSQUIRRELVM v,SQUserPointer p);
typedef SQUserPointer (*sqapi_getsharedforeignptr)(HSQUIRRELVM v);
typedef void (*sqapi_setvmreleasehook)(HSQUIRRELVM v,SQRELEASEHOOK hook);
typedef SQRELEASEHOOK (*sqapi_getvmreleasehook)(HSQUIRRELVM v);
typedef void (*sqapi_setsharedreleasehook)(HSQUIRRELVM v,SQRELEASEHOOK hook);
typedef SQRELEASEHOOK (*sqapi_getsharedreleasehook)(HSQUIRRELVM v);
typedef void (*sqapi_setprintfunc)(HSQUIRRELVM v, SQPRINTFUNCTION printfunc,SQPRINTFUNCTION errfunc);
typedef SQPRINTFUNCTION (*sqapi_getprintfunc)(HSQUIRRELVM v);
typedef SQPRINTFUNCTION (*sqapi_geterrorfunc)(HSQUIRRELVM v);
typedef SQRESULT (*sqapi_suspendvm)(HSQUIRRELVM v);
typedef SQRESULT (*sqapi_wakeupvm)(HSQUIRRELVM v,SQBool resumedret,SQBool retval,SQBool raiseerror,SQBool throwerror);
typedef SQInteger (*sqapi_getvmstate)(HSQUIRRELVM v);
typedef SQInteger (*sqapi_getversion)();
/*compiler*/
typedef SQRESULT (*sqapi_compile)(HSQUIRRELVM v,SQLEXREADFUNC read,SQUserPointer p,const SQChar *sourcename,SQBool raiseerror);
typedef SQRESULT (*sqapi_compilebuffer)(HSQUIRRELVM v,const SQChar *s,SQInteger size,const SQChar *sourcename,SQBool raiseerror);
typedef void (*sqapi_enabledebuginfo)(HSQUIRRELVM v, SQBool enable);
typedef void (*sqapi_notifyallexceptions)(HSQUIRRELVM v, SQBool enable);
typedef void (*sqapi_setcompilererrorhandler)(HSQUIRRELVM v,SQCOMPILERERROR f);
/*stack operations*/
typedef void (*sqapi_push)(HSQUIRRELVM v,SQInteger idx);
typedef void (*sqapi_pop)(HSQUIRRELVM v,SQInteger nelemstopop);
typedef void (*sqapi_poptop)(HSQUIRRELVM v);
typedef void (*sqapi_remove)(HSQUIRRELVM v,SQInteger idx);
typedef SQInteger (*sqapi_gettop)(HSQUIRRELVM v);
typedef void (*sqapi_settop)(HSQUIRRELVM v,SQInteger newtop);
typedef SQRESULT (*sqapi_reservestack)(HSQUIRRELVM v,SQInteger nsize);
typedef SQInteger (*sqapi_cmp)(HSQUIRRELVM v);
typedef void (*sqapi_move)(HSQUIRRELVM dest,HSQUIRRELVM src,SQInteger idx);
/*object creation handling*/
typedef SQUserPointer (*sqapi_newuserdata)(HSQUIRRELVM v,SQUnsignedInteger size);
typedef void (*sqapi_newtable)(HSQUIRRELVM v);
typedef void (*sqapi_newtableex)(HSQUIRRELVM v,SQInteger initialcapacity);
typedef void (*sqapi_newarray)(HSQUIRRELVM v,SQInteger size);
typedef void (*sqapi_newclosure)(HSQUIRRELVM v,SQFUNCTION func,SQUnsignedInteger nfreevars);
typedef SQRESULT (*sqapi_setparamscheck)(HSQUIRRELVM v,SQInteger nparamscheck,const SQChar *typemask);
typedef SQRESULT (*sqapi_bindenv)(HSQUIRRELVM v,SQInteger idx);
typedef SQRESULT (*sqapi_setclosureroot)(HSQUIRRELVM v,SQInteger idx);
typedef SQRESULT (*sqapi_getclosureroot)(HSQUIRRELVM v,SQInteger idx);
typedef void (*sqapi_pushstring)(HSQUIRRELVM v,const SQChar *s,SQInteger len);
typedef void (*sqapi_pushfloat)(HSQUIRRELVM v,SQFloat f);
typedef void (*sqapi_pushinteger)(HSQUIRRELVM v,SQInteger n);
typedef void (*sqapi_pushbool)(HSQUIRRELVM v,SQBool b);
typedef void (*sqapi_pushuserpointer)(HSQUIRRELVM v,SQUserPointer p);
typedef void (*sqapi_pushnull)(HSQUIRRELVM v);
typedef void (*sqapi_pushthread)(HSQUIRRELVM v, HSQUIRRELVM thread);
typedef SQObjectType (*sqapi_gettype)(HSQUIRRELVM v,SQInteger idx);
typedef SQRESULT (*sqapi_typeof)(HSQUIRRELVM v,SQInteger idx);
typedef SQInteger (*sqapi_getsize)(HSQUIRRELVM v,SQInteger idx);
typedef SQHash (*sqapi_gethash)(HSQUIRRELVM v, SQInteger idx);
typedef SQRESULT (*sqapi_getbase)(HSQUIRRELVM v,SQInteger idx);
typedef SQBool (*sqapi_instanceof)(HSQUIRRELVM v);
typedef SQRESULT (*sqapi_tostring)(HSQUIRRELVM v,SQInteger idx);
typedef void (*sqapi_tobool)(HSQUIRRELVM v, SQInteger idx, SQBool *b);
typedef SQRESULT (*sqapi_getstring)(HSQUIRRELVM v,SQInteger idx,const SQChar **c);
typedef SQRESULT (*sqapi_getinteger)(HSQUIRRELVM v,SQInteger idx,SQInteger *i);
typedef SQRESULT (*sqapi_getfloat)(HSQUIRRELVM v,SQInteger idx,SQFloat *f);
typedef SQRESULT (*sqapi_getbool)(HSQUIRRELVM v,SQInteger idx,SQBool *b);
typedef SQRESULT (*sqapi_getthread)(HSQUIRRELVM v,SQInteger idx,HSQUIRRELVM *thread);
typedef SQRESULT (*sqapi_getuserpointer)(HSQUIRRELVM v,SQInteger idx,SQUserPointer *p);
typedef SQRESULT (*sqapi_getuserdata)(HSQUIRRELVM v,SQInteger idx,SQUserPointer *p,SQUserPointer *typetag);
typedef SQRESULT (*sqapi_settypetag)(HSQUIRRELVM v,SQInteger idx,SQUserPointer typetag);
typedef SQRESULT (*sqapi_gettypetag)(HSQUIRRELVM v,SQInteger idx,SQUserPointer *typetag);
typedef void (*sqapi_setreleasehook)(HSQUIRRELVM v,SQInteger idx,SQRELEASEHOOK hook);
typedef SQRELEASEHOOK (*sqapi_getreleasehook)(HSQUIRRELVM v,SQInteger idx);
typedef SQChar* (*sqapi_getscratchpad)(HSQUIRRELVM v,SQInteger minsize);
typedef SQRESULT (*sqapi_getfunctioninfo)(HSQUIRRELVM v,SQInteger level,SQFunctionInfo *fi);
typedef SQRESULT (*sqapi_getclosureinfo)(HSQUIRRELVM v,SQInteger idx,SQUnsignedInteger *nparams,SQUnsignedInteger *nfreevars);
typedef SQRESULT (*sqapi_getclosurename)(HSQUIRRELVM v,SQInteger idx);
typedef SQRESULT (*sqapi_setnativeclosurename)(HSQUIRRELVM v,SQInteger idx,const SQChar *name);
typedef SQRESULT (*sqapi_setinstanceup)(HSQUIRRELVM v, SQInteger idx, SQUserPointer p);
typedef SQRESULT (*sqapi_getinstanceup)(HSQUIRRELVM v, SQInteger idx, SQUserPointer *p,SQUserPointer typetag);
typedef SQRESULT (*sqapi_setclassudsize)(HSQUIRRELVM v, SQInteger idx, SQInteger udsize);
typedef SQRESULT (*sqapi_newclass)(HSQUIRRELVM v,SQBool hasbase);
typedef SQRESULT (*sqapi_createinstance)(HSQUIRRELVM v,SQInteger idx);
typedef SQRESULT (*sqapi_setattributes)(HSQUIRRELVM v,SQInteger idx);
typedef SQRESULT (*sqapi_getattributes)(HSQUIRRELVM v,SQInteger idx);
typedef SQRESULT (*sqapi_getclass)(HSQUIRRELVM v,SQInteger idx);
typedef void (*sqapi_weakref)(HSQUIRRELVM v,SQInteger idx);
typedef SQRESULT (*sqapi_getdefaultdelegate)(HSQUIRRELVM v,SQObjectType t);
typedef SQRESULT (*sqapi_getmemberhandle)(HSQUIRRELVM v,SQInteger idx,HSQMEMBERHANDLE *handle);
typedef SQRESULT (*sqapi_getbyhandle)(HSQUIRRELVM v,SQInteger idx,const HSQMEMBERHANDLE *handle);
typedef SQRESULT (*sqapi_setbyhandle)(HSQUIRRELVM v,SQInteger idx,const HSQMEMBERHANDLE *handle);
/*object manipulation*/
typedef void (*sqapi_pushroottable)(HSQUIRRELVM v);
typedef void (*sqapi_pushregistrytable)(HSQUIRRELVM v);
typedef void (*sqapi_pushconsttable)(HSQUIRRELVM v);
typedef SQRESULT (*sqapi_setroottable)(HSQUIRRELVM v);
typedef SQRESULT (*sqapi_setconsttable)(HSQUIRRELVM v);
typedef SQRESULT (*sqapi_newslot)(HSQUIRRELVM v, SQInteger idx, SQBool bstatic);
typedef SQRESULT (*sqapi_deleteslot)(HSQUIRRELVM v,SQInteger idx,SQBool pushval);
typedef SQRESULT (*sqapi_set)(HSQUIRRELVM v,SQInteger idx);
typedef SQRESULT (*sqapi_get)(HSQUIRRELVM v,SQInteger idx);
typedef SQRESULT (*sqapi_rawget)(HSQUIRRELVM v,SQInteger idx);
typedef SQRESULT (*sqapi_rawset)(HSQUIRRELVM v,SQInteger idx);
typedef SQRESULT (*sqapi_rawdeleteslot)(HSQUIRRELVM v,SQInteger idx,SQBool pushval);
typedef SQRESULT (*sqapi_newmember)(HSQUIRRELVM v,SQInteger idx,SQBool bstatic);
typedef SQRESULT (*sqapi_rawnewmember)(HSQUIRRELVM v,SQInteger idx,SQBool bstatic);
typedef SQRESULT (*sqapi_arrayappend)(HSQUIRRELVM v,SQInteger idx);
typedef SQRESULT (*sqapi_arraypop)(HSQUIRRELVM v,SQInteger idx,SQBool pushval);
typedef SQRESULT (*sqapi_arrayresize)(HSQUIRRELVM v,SQInteger idx,SQInteger newsize);
typedef SQRESULT (*sqapi_arrayreverse)(HSQUIRRELVM v,SQInteger idx);
typedef SQRESULT (*sqapi_arrayremove)(HSQUIRRELVM v,SQInteger idx,SQInteger itemidx);
typedef SQRESULT (*sqapi_arrayinsert)(HSQUIRRELVM v,SQInteger idx,SQInteger destpos);
typedef SQRESULT (*sqapi_setdelegate)(HSQUIRRELVM v,SQInteger idx);
typedef SQRESULT (*sqapi_getdelegate)(HSQUIRRELVM v,SQInteger idx);
typedef SQRESULT (*sqapi_clone)(HSQUIRRELVM v,SQInteger idx);
typedef SQRESULT (*sqapi_setfreevariable)(HSQUIRRELVM v,SQInteger idx,SQUnsignedInteger nval);
typedef SQRESULT (*sqapi_next)(HSQUIRRELVM v,SQInteger idx);
typedef SQRESULT (*sqapi_getweakrefval)(HSQUIRRELVM v,SQInteger idx);
typedef SQRESULT (*sqapi_clear)(HSQUIRRELVM v,SQInteger idx);
/*calls*/
typedef SQRESULT (*sqapi_call)(HSQUIRRELVM v,SQInteger params,SQBool retval,SQBool raiseerror);
typedef SQRESULT (*sqapi_resume)(HSQUIRRELVM v,SQBool retval,SQBool raiseerror);
typedef const SQChar* (*sqapi_getlocal)(HSQUIRRELVM v,SQUnsignedInteger level,SQUnsignedInteger idx);
typedef SQRESULT (*sqapi_getcallee)(HSQUIRRELVM v);
typedef const SQChar* (*sqapi_getfreevariable)(HSQUIRRELVM v,SQInteger idx,SQUnsignedInteger nval);
typedef SQRESULT (*sqapi_throwerror)(HSQUIRRELVM v,const SQChar *err);
typedef SQRESULT (*sqapi_throwobject)(HSQUIRRELVM v);
typedef void (*sqapi_reseterror)(HSQUIRRELVM v);
typedef void (*sqapi_getlasterror)(HSQUIRRELVM v);
/*raw object handling*/
typedef SQRESULT (*sqapi_getstackobj)(HSQUIRRELVM v,SQInteger idx,HSQOBJECT *po);
typedef void (*sqapi_pushobject)(HSQUIRRELVM v,HSQOBJECT obj);
typedef void (*sqapi_addref)(HSQUIRRELVM v,HSQOBJECT *po);
typedef SQBool (*sqapi_release)(HSQUIRRELVM v,HSQOBJECT *po);
typedef SQUnsignedInteger (*sqapi_getrefcount)(HSQUIRRELVM v,HSQOBJECT *po);
typedef void (*sqapi_resetobject)(HSQOBJECT *po);
typedef const SQChar* (*sqapi_objtostring)(const HSQOBJECT *o);
typedef SQBool (*sqapi_objtobool)(const HSQOBJECT *o);
typedef SQInteger (*sqapi_objtointeger)(const HSQOBJECT *o);
typedef SQFloat (*sqapi_objtofloat)(const HSQOBJECT *o);
typedef SQUserPointer (*sqapi_objtouserpointer)(const HSQOBJECT *o);
typedef SQRESULT (*sqapi_getobjtypetag)(const HSQOBJECT *o,SQUserPointer * typetag);
typedef SQUnsignedInteger (*sqapi_getvmrefcount)(HSQUIRRELVM v, const HSQOBJECT *po);
/*GC*/
typedef SQInteger (*sqapi_collectgarbage)(HSQUIRRELVM v);
typedef SQRESULT (*sqapi_resurrectunreachable)(HSQUIRRELVM v);
/*serialization*/
typedef SQRESULT (*sqapi_writeclosure)(HSQUIRRELVM vm,SQWRITEFUNC writef,SQUserPointer up);
typedef SQRESULT (*sqapi_readclosure)(HSQUIRRELVM vm,SQREADFUNC readf,SQUserPointer up);
/*mem allocation*/
typedef void* (*sqapi_malloc)(SQUnsignedInteger size);
typedef void* (*sqapi_realloc)(void* p,SQUnsignedInteger oldsize,SQUnsignedInteger newsize);
typedef void (*sqapi_free)(void *p,SQUnsignedInteger size);
/*debug*/
typedef SQRESULT (*sqapi_stackinfos)(HSQUIRRELVM v,SQInteger level,SQStackInfos *si);
typedef void (*sqapi_setdebughook)(HSQUIRRELVM v);
typedef void (*sqapi_setnativedebughook)(HSQUIRRELVM v,SQDEBUGHOOK hook);
/*compiler helpers*/
typedef SQRESULT (*sqapi_loadfile)(HSQUIRRELVM v,const SQChar *filename,SQBool printerror);
typedef SQRESULT (*sqapi_dofile)(HSQUIRRELVM v,const SQChar *filename,SQBool retval,SQBool printerror);
typedef SQRESULT (*sqapi_writeclosuretofile)(HSQUIRRELVM v,const SQChar *filename);
/*blob*/
typedef SQUserPointer (*sqapi_createblob)(HSQUIRRELVM v, SQInteger size);
typedef SQRESULT (*sqapi_getblob)(HSQUIRRELVM v,SQInteger idx,SQUserPointer *ptr);
typedef SQInteger (*sqapi_getblobsize)(HSQUIRRELVM v,SQInteger idx);
/*string*/
typedef SQRESULT (*sqapi_format)(HSQUIRRELVM v,SQInteger nformatstringidx,SQInteger *outlen,SQChar **output);
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// @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*/
sqapi_open open;
sqapi_newthread newthread;
sqapi_seterrorhandler seterrorhandler;
sqapi_close close;
sqapi_setforeignptr setforeignptr;
sqapi_getforeignptr getforeignptr;
sqapi_setsharedforeignptr setsharedforeignptr;
sqapi_getsharedforeignptr getsharedforeignptr;
sqapi_setvmreleasehook setvmreleasehook;
sqapi_getvmreleasehook getvmreleasehook;
sqapi_setsharedreleasehook setsharedreleasehook;
sqapi_getsharedreleasehook getsharedreleasehook;
sqapi_setprintfunc setprintfunc;
sqapi_getprintfunc getprintfunc;
sqapi_geterrorfunc geterrorfunc;
sqapi_suspendvm suspendvm;
sqapi_wakeupvm wakeupvm;
sqapi_getvmstate getvmstate;
sqapi_getversion getversion;
/*compiler*/
sqapi_compile compile;
sqapi_compilebuffer compilebuffer;
sqapi_enabledebuginfo enabledebuginfo;
sqapi_notifyallexceptions notifyallexceptions;
sqapi_setcompilererrorhandler setcompilererrorhandler;
/*stack operations*/
sqapi_push push;
sqapi_pop pop;
sqapi_poptop poptop;
sqapi_remove remove;
sqapi_gettop gettop;
sqapi_settop settop;
sqapi_reservestack reservestack;
sqapi_cmp cmp;
sqapi_move move;
/*object creation handling*/
sqapi_newuserdata newuserdata;
sqapi_newtable newtable;
sqapi_newtableex newtableex;
sqapi_newarray newarray;
sqapi_newclosure newclosure;
sqapi_setparamscheck setparamscheck;
sqapi_bindenv bindenv;
sqapi_setclosureroot setclosureroot;
sqapi_getclosureroot getclosureroot;
sqapi_pushstring pushstring;
sqapi_pushfloat pushfloat;
sqapi_pushinteger pushinteger;
sqapi_pushbool pushbool;
sqapi_pushuserpointer pushuserpointer;
sqapi_pushnull pushnull;
sqapi_pushthread pushthread;
sqapi_gettype gettype;
sqapi_typeof typeof_;
sqapi_getsize getsize;
sqapi_gethash gethash;
sqapi_getbase getbase;
sqapi_instanceof instanceof;
sqapi_tostring tostring;
sqapi_tobool tobool;
sqapi_getstring getstring;
sqapi_getinteger getinteger;
sqapi_getfloat getfloat;
sqapi_getbool getbool;
sqapi_getthread getthread;
sqapi_getuserpointer getuserpointer;
sqapi_getuserdata getuserdata;
sqapi_settypetag settypetag;
sqapi_gettypetag gettypetag;
sqapi_setreleasehook setreleasehook;
sqapi_getreleasehook getreleasehook;
sqapi_getscratchpad getscratchpad;
sqapi_getfunctioninfo getfunctioninfo;
sqapi_getclosureinfo getclosureinfo;
sqapi_getclosurename getclosurename;
sqapi_setnativeclosurename setnativeclosurename;
sqapi_setinstanceup setinstanceup;
sqapi_getinstanceup getinstanceup;
sqapi_setclassudsize setclassudsize;
sqapi_newclass newclass;
sqapi_createinstance createinstance;
sqapi_setattributes setattributes;
sqapi_getattributes getattributes;
sqapi_getclass getclass;
sqapi_weakref weakref;
sqapi_getdefaultdelegate getdefaultdelegate;
sqapi_getmemberhandle getmemberhandle;
sqapi_getbyhandle getbyhandle;
sqapi_setbyhandle setbyhandle;
/*object manipulation*/
sqapi_pushroottable pushroottable;
sqapi_pushregistrytable pushregistrytable;
sqapi_pushconsttable pushconsttable;
sqapi_setroottable setroottable;
sqapi_setconsttable setconsttable;
sqapi_newslot newslot;
sqapi_deleteslot deleteslot;
sqapi_set set;
sqapi_get get;
sqapi_rawget rawget;
sqapi_rawset rawset;
sqapi_rawdeleteslot rawdeleteslot;
sqapi_newmember newmember;
sqapi_rawnewmember rawnewmember;
sqapi_arrayappend arrayappend;
sqapi_arraypop arraypop;
sqapi_arrayresize arrayresize;
sqapi_arrayreverse arrayreverse;
sqapi_arrayremove arrayremove;
sqapi_arrayinsert arrayinsert;
sqapi_setdelegate setdelegate;
sqapi_getdelegate getdelegate;
sqapi_clone clone;
sqapi_setfreevariable setfreevariable;
sqapi_next next;
sqapi_getweakrefval getweakrefval;
sqapi_clear clear;
/*calls*/
sqapi_call call;
sqapi_resume resume;
sqapi_getlocal getlocal;
sqapi_getcallee getcallee;
sqapi_getfreevariable getfreevariable;
sqapi_throwerror throwerror;
sqapi_throwobject throwobject;
sqapi_reseterror reseterror;
sqapi_getlasterror getlasterror;
/*raw object handling*/
sqapi_getstackobj getstackobj;
sqapi_pushobject pushobject;
sqapi_addref addref;
sqapi_release release;
sqapi_getrefcount getrefcount;
sqapi_resetobject resetobject;
sqapi_objtostring objtostring;
sqapi_objtobool objtobool;
sqapi_objtointeger objtointeger;
sqapi_objtofloat objtofloat;
sqapi_objtouserpointer objtouserpointer;
sqapi_getobjtypetag getobjtypetag;
sqapi_getvmrefcount getvmrefcount;
/*GC*/
sqapi_collectgarbage collectgarbage;
sqapi_resurrectunreachable resurrectunreachable;
/*serialization*/
sqapi_writeclosure writeclosure;
sqapi_readclosure readclosure;
/*mem allocation*/
sqapi_malloc malloc;
sqapi_realloc realloc;
sqapi_free free;
/*debug*/
sqapi_stackinfos stackinfos;
sqapi_setdebughook setdebughook;
sqapi_setnativedebughook setnativedebughook;
/*compiler helpers*/
sqapi_loadfile loadfile;
sqapi_dofile dofile;
sqapi_writeclosuretofile writeclosuretofile;
/*blob*/
sqapi_createblob createblob;
sqapi_getblob getblob;
sqapi_getblobsize getblobsize;
/*string*/
sqapi_format format;
} sq_api, SQAPI, *HSQAPI;
/// @endcond
#ifdef SQMOD_PLUGIN_API
/*vm*/
extern sqapi_open sq_open;
extern sqapi_newthread sq_newthread;
extern sqapi_seterrorhandler sq_seterrorhandler;
extern sqapi_close sq_close;
extern sqapi_setforeignptr sq_setforeignptr;
extern sqapi_getforeignptr sq_getforeignptr;
extern sqapi_setsharedforeignptr sq_setsharedforeignptr;
extern sqapi_getsharedforeignptr sq_getsharedforeignptr;
extern sqapi_setvmreleasehook sq_setvmreleasehook;
extern sqapi_getvmreleasehook sq_getvmreleasehook;
extern sqapi_setsharedreleasehook sq_setsharedreleasehook;
extern sqapi_getsharedreleasehook sq_getsharedreleasehook;
extern sqapi_setprintfunc sq_setprintfunc;
extern sqapi_getprintfunc sq_getprintfunc;
extern sqapi_geterrorfunc sq_geterrorfunc;
extern sqapi_suspendvm sq_suspendvm;
extern sqapi_wakeupvm sq_wakeupvm;
extern sqapi_getvmstate sq_getvmstate;
extern sqapi_getversion sq_getversion;
/*compiler*/
extern sqapi_compile sq_compile;
extern sqapi_compilebuffer sq_compilebuffer;
extern sqapi_enabledebuginfo sq_enabledebuginfo;
extern sqapi_notifyallexceptions sq_notifyallexceptions;
extern sqapi_setcompilererrorhandler sq_setcompilererrorhandler;
/*stack operations*/
extern sqapi_push sq_push;
extern sqapi_pop sq_pop;
extern sqapi_poptop sq_poptop;
extern sqapi_remove sq_remove;
extern sqapi_gettop sq_gettop;
extern sqapi_settop sq_settop;
extern sqapi_reservestack sq_reservestack;
extern sqapi_cmp sq_cmp;
extern sqapi_move sq_move;
/*object creation handling*/
extern sqapi_newuserdata sq_newuserdata;
extern sqapi_newtable sq_newtable;
extern sqapi_newtableex sq_newtableex;
extern sqapi_newarray sq_newarray;
extern sqapi_newclosure sq_newclosure;
extern sqapi_setparamscheck sq_setparamscheck;
extern sqapi_bindenv sq_bindenv;
extern sqapi_setclosureroot sq_setclosureroot;
extern sqapi_getclosureroot sq_getclosureroot;
extern sqapi_pushstring sq_pushstring;
extern sqapi_pushfloat sq_pushfloat;
extern sqapi_pushinteger sq_pushinteger;
extern sqapi_pushbool sq_pushbool;
extern sqapi_pushuserpointer sq_pushuserpointer;
extern sqapi_pushnull sq_pushnull;
extern sqapi_pushthread sq_pushthread;
extern sqapi_gettype sq_gettype;
extern sqapi_typeof sq_typeof;
extern sqapi_getsize sq_getsize;
extern sqapi_gethash sq_gethash;
extern sqapi_getbase sq_getbase;
extern sqapi_instanceof sq_instanceof;
extern sqapi_tostring sq_tostring;
extern sqapi_tobool sq_tobool;
extern sqapi_getstring sq_getstring;
extern sqapi_getinteger sq_getinteger;
extern sqapi_getfloat sq_getfloat;
extern sqapi_getbool sq_getbool;
extern sqapi_getthread sq_getthread;
extern sqapi_getuserpointer sq_getuserpointer;
extern sqapi_getuserdata sq_getuserdata;
extern sqapi_settypetag sq_settypetag;
extern sqapi_gettypetag sq_gettypetag;
extern sqapi_setreleasehook sq_setreleasehook;
extern sqapi_getreleasehook sq_getreleasehook;
extern sqapi_getscratchpad sq_getscratchpad;
extern sqapi_getfunctioninfo sq_getfunctioninfo;
extern sqapi_getclosureinfo sq_getclosureinfo;
extern sqapi_getclosurename sq_getclosurename;
extern sqapi_setnativeclosurename sq_setnativeclosurename;
extern sqapi_setinstanceup sq_setinstanceup;
extern sqapi_getinstanceup sq_getinstanceup;
extern sqapi_setclassudsize sq_setclassudsize;
extern sqapi_newclass sq_newclass;
extern sqapi_createinstance sq_createinstance;
extern sqapi_setattributes sq_setattributes;
extern sqapi_getattributes sq_getattributes;
extern sqapi_getclass sq_getclass;
extern sqapi_weakref sq_weakref;
extern sqapi_getdefaultdelegate sq_getdefaultdelegate;
extern sqapi_getmemberhandle sq_getmemberhandle;
extern sqapi_getbyhandle sq_getbyhandle;
extern sqapi_setbyhandle sq_setbyhandle;
/*object manipulation*/
extern sqapi_pushroottable sq_pushroottable;
extern sqapi_pushregistrytable sq_pushregistrytable;
extern sqapi_pushconsttable sq_pushconsttable;
extern sqapi_setroottable sq_setroottable;
extern sqapi_setconsttable sq_setconsttable;
extern sqapi_newslot sq_newslot;
extern sqapi_deleteslot sq_deleteslot;
extern sqapi_set sq_set;
extern sqapi_get sq_get;
extern sqapi_rawget sq_rawget;
extern sqapi_rawset sq_rawset;
extern sqapi_rawdeleteslot sq_rawdeleteslot;
extern sqapi_newmember sq_newmember;
extern sqapi_rawnewmember sq_rawnewmember;
extern sqapi_arrayappend sq_arrayappend;
extern sqapi_arraypop sq_arraypop;
extern sqapi_arrayresize sq_arrayresize;
extern sqapi_arrayreverse sq_arrayreverse;
extern sqapi_arrayremove sq_arrayremove;
extern sqapi_arrayinsert sq_arrayinsert;
extern sqapi_setdelegate sq_setdelegate;
extern sqapi_getdelegate sq_getdelegate;
extern sqapi_clone sq_clone;
extern sqapi_setfreevariable sq_setfreevariable;
extern sqapi_next sq_next;
extern sqapi_getweakrefval sq_getweakrefval;
extern sqapi_clear sq_clear;
/*calls*/
extern sqapi_call sq_call;
extern sqapi_resume sq_resume;
extern sqapi_getlocal sq_getlocal;
extern sqapi_getcallee sq_getcallee;
extern sqapi_getfreevariable sq_getfreevariable;
extern sqapi_throwerror sq_throwerror;
extern sqapi_throwobject sq_throwobject;
extern sqapi_reseterror sq_reseterror;
extern sqapi_getlasterror sq_getlasterror;
/*raw object handling*/
extern sqapi_getstackobj sq_getstackobj;
extern sqapi_pushobject sq_pushobject;
extern sqapi_addref sq_addref;
extern sqapi_release sq_release;
extern sqapi_getrefcount sq_getrefcount;
extern sqapi_resetobject sq_resetobject;
extern sqapi_objtostring sq_objtostring;
extern sqapi_objtobool sq_objtobool;
extern sqapi_objtointeger sq_objtointeger;
extern sqapi_objtofloat sq_objtofloat;
extern sqapi_objtouserpointer sq_objtouserpointer;
extern sqapi_getobjtypetag sq_getobjtypetag;
extern sqapi_getvmrefcount sq_getvmrefcount;
/*GC*/
extern sqapi_collectgarbage sq_collectgarbage;
extern sqapi_resurrectunreachable sq_resurrectunreachable;
/*serialization*/
extern sqapi_writeclosure sq_writeclosure;
extern sqapi_readclosure sq_readclosure;
/*mem allocation*/
extern sqapi_malloc sq_malloc;
extern sqapi_realloc sq_realloc;
extern sqapi_free sq_free;
/*debug*/
extern sqapi_stackinfos sq_stackinfos;
extern sqapi_setdebughook sq_setdebughook;
extern sqapi_setnativedebughook sq_setnativedebughook;
/*compiler helpers*/
extern sqapi_loadfile sqstd_loadfile;
extern sqapi_dofile sqstd_dofile;
extern sqapi_writeclosuretofile sqstd_writeclosuretofile;
/*blob*/
extern sqapi_createblob sqstd_createblob;
extern sqapi_getblob sqstd_getblob;
extern sqapi_getblobsize sqstd_getblobsize;
/*string*/
extern sqapi_format sqstd_format;
#endif // SQMOD_PLUGIN_API
#ifdef __cplusplus
} /*extern "C"*/
#endif
#endif /*_SQ_API_H_*/

4
shared/sq_mod.c Normal file
View File

@ -0,0 +1,4 @@
// ////////////////////////////////////////////////////////////////////////////////////////////////
#include "sq_mod.h"
#include "sq_mod.inl"
/* This method is used toa void compilers warning about C++ flags on C files and viceversa. */

4
shared/sq_mod.cpp Normal file
View File

@ -0,0 +1,4 @@
// ////////////////////////////////////////////////////////////////////////////////////////////////
#include "sq_mod.h"
#include "sq_mod.inl"
/* This method is used toa void compilers warning about C++ flags on C files and viceversa. */

579
shared/sq_mod.h Normal file
View File

@ -0,0 +1,579 @@
//
// SqModule: API used to communicate with and register squirrel modules
//
//
// Copyright (c) 2009 Sandu Liviu Catalin (aka. S.L.C)
//
// 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_MOD_H_)
#define _SQ_MOD_H_
#include "sq_api.h"
#include "vcmp.h"
#ifdef __cplusplus
extern "C" {
#endif
#if defined(_MSC_VER)
#define SQMOD_API_EXPORT extern "C" __declspec(dllexport)
#elif defined(__GNUC__)
#define SQMOD_API_EXPORT extern "C"
#else
#define SQMOD_API_EXPORT extern "C"
#endif
#define SQMOD_HOST_NAME "SqModHost"
#define SQMOD_INITIALIZE_CMD 0xDABBAD00
#define SQMOD_TERMINATE_CMD 0xDEADC0DE
/* --------------------------------------------------------------------------------------------
* Allows modules to interface with the plugin API without linking of any sorts
*/
typedef struct
{
unsigned int uStructSize;
HSQAPI (*GetSquirrelAPI) ( void );
HSQUIRRELVM (*GetSquirrelVM) (void);
} sq_exports, SQEXPORTS, *HSQEXPORTS;
/* ------------------------------------------------------------------------------------------------
* PLUGIN SYSTEM
*/
extern SDK_GetServerVersion SqVC_GetServerVersion;
extern SDK_GetServerSettings SqVC_GetServerSettings;
extern SDK_ExportFunctions SqVC_ExportFunctions;
extern SDK_GetNumberOfPlugins SqVC_GetNumberOfPlugins;
extern SDK_GetPluginInfo SqVC_GetPluginInfo;
extern SDK_FindPlugin SqVC_FindPlugin;
extern SDK_GetPluginExports SqVC_GetPluginExports;
extern SDK_GetTime SqVC_GetTime;
/* ------------------------------------------------------------------------------------------------
* MESSAGES
*/
extern SDK_printf SqVC_printf;
extern SDK_SendCustomCommand SqVC_SendCustomCommand;
extern SDK_SendClientMessage SqVC_SendClientMessage;
extern SDK_SendGameMessage SqVC_SendGameMessage;
/* ------------------------------------------------------------------------------------------------
* SERVER SETTINGS
*/
extern SDK_SetServerName SqVC_SetServerName;
extern SDK_GetServerName SqVC_GetServerName;
extern SDK_SetMaxPlayers SqVC_SetMaxPlayers;
extern SDK_GetMaxPlayers SqVC_GetMaxPlayers;
extern SDK_SetServerPassword SqVC_SetServerPassword;
extern SDK_GetServerPassword SqVC_GetServerPassword;
extern SDK_SetGameModeText SqVC_SetGameModeText;
extern SDK_GetGameModeText SqVC_GetGameModeText;
extern SDK_ShutdownServer SqVC_ShutdownServer;
/* ------------------------------------------------------------------------------------------------
* WORLD: settings
*/
extern SDK_SetWorldBounds SqVC_SetWorldBounds;
extern SDK_GetWorldBounds SqVC_GetWorldBounds;
extern SDK_SetWastedSettings SqVC_SetWastedSettings;
extern SDK_GetWastedSettings SqVC_GetWastedSettings;
extern SDK_SetTimeRate SqVC_SetTimeRate;
extern SDK_GetTimeRate SqVC_GetTimeRate;
extern SDK_SetHour SqVC_SetHour;
extern SDK_GetHour SqVC_GetHour;
extern SDK_SetMinute SqVC_SetMinute;
extern SDK_GetMinute SqVC_GetMinute;
extern SDK_SetWeather SqVC_SetWeather;
extern SDK_GetWeather SqVC_GetWeather;
extern SDK_SetGravity SqVC_SetGravity;
extern SDK_GetGravity SqVC_GetGravity;
extern SDK_SetGamespeed SqVC_SetGamespeed;
extern SDK_GetGamespeed SqVC_GetGamespeed;
extern SDK_SetWaterLevel SqVC_SetWaterLevel;
extern SDK_GetWaterLevel SqVC_GetWaterLevel;
extern SDK_SetMaxHeight SqVC_SetMaxHeight;
extern SDK_GetMaxHeight SqVC_GetMaxHeight;
extern SDK_SetKillCmdDelay SqVC_SetKillCmdDelay;
extern SDK_GetKillCmdDelay SqVC_GetKillCmdDelay;
extern SDK_SetVehiclesForcedRespawnHeight SqVC_SetVehiclesForcedRespawnHeight;
extern SDK_GetVehiclesForcedRespawnHeight SqVC_GetVehiclesForcedRespawnHeight;
/* ------------------------------------------------------------------------------------------------
* WORLD: toggles
*/
extern SDK_ToggleSyncFrameLimiter SqVC_ToggleSyncFrameLimiter;
extern SDK_EnabledSyncFrameLimiter SqVC_EnabledSyncFrameLimiter;
extern SDK_ToggleFrameLimiter SqVC_ToggleFrameLimiter;
extern SDK_EnabledFrameLimiter SqVC_EnabledFrameLimiter;
extern SDK_ToggleTaxiBoostJump SqVC_ToggleTaxiBoostJump;
extern SDK_EnabledTaxiBoostJump SqVC_EnabledTaxiBoostJump;
extern SDK_ToggleDriveOnWater SqVC_ToggleDriveOnWater;
extern SDK_EnabledDriveOnWater SqVC_EnabledDriveOnWater;
extern SDK_ToggleFastSwitch SqVC_ToggleFastSwitch;
extern SDK_EnabledFastSwitch SqVC_EnabledFastSwitch;
extern SDK_ToggleFriendlyFire SqVC_ToggleFriendlyFire;
extern SDK_EnabledFriendlyFire SqVC_EnabledFriendlyFire;
extern SDK_ToggleDisableDriveby SqVC_ToggleDisableDriveby;
extern SDK_EnabledDisableDriveby SqVC_EnabledDisableDriveby;
extern SDK_TogglePerfectHandling SqVC_TogglePerfectHandling;
extern SDK_EnabledPerfectHandling SqVC_EnabledPerfectHandling;
extern SDK_ToggleFlyingCars SqVC_ToggleFlyingCars;
extern SDK_EnabledFlyingCars SqVC_EnabledFlyingCars;
extern SDK_ToggleJumpSwitch SqVC_ToggleJumpSwitch;
extern SDK_EnabledJumpSwitch SqVC_EnabledJumpSwitch;
extern SDK_ToggleShowMarkers SqVC_ToggleShowMarkers;
extern SDK_EnabledShowMarkers SqVC_EnabledShowMarkers;
extern SDK_ToggleOnlyShowTeamMarkers SqVC_ToggleOnlyShowTeamMarkers;
extern SDK_EnabledOnlyShowTeamMarkers SqVC_EnabledOnlyShowTeamMarkers;
extern SDK_ToggleStuntBike SqVC_ToggleStuntBike;
extern SDK_EnabledStuntBike SqVC_EnabledStuntBike;
extern SDK_ToggleShootInAir SqVC_ToggleShootInAir;
extern SDK_EnabledShootInAir SqVC_EnabledShootInAir;
extern SDK_ToggleShowNametags SqVC_ToggleShowNametags;
extern SDK_EnabledShowNametags SqVC_EnabledShowNametags;
extern SDK_ToggleJoinMessages SqVC_ToggleJoinMessages;
extern SDK_EnabledJoinMessages SqVC_EnabledJoinMessages;
extern SDK_ToggleDeathMessages SqVC_ToggleDeathMessages;
extern SDK_EnabledDeathMessages SqVC_EnabledDeathMessages;
extern SDK_ToggleChatTagsByDefaultEnabled SqVC_ToggleChatTagsByDefaultEnabled;
extern SDK_EnabledChatTagsByDefault SqVC_EnabledChatTagsByDefault;
/* ------------------------------------------------------------------------------------------------
* MISC
*/
extern SDK_CreateExplosion SqVC_CreateExplosion;
extern SDK_PlaySound SqVC_PlaySound;
extern SDK_HideMapObject SqVC_HideMapObject;
extern SDK_ShowMapObject SqVC_ShowMapObject;
extern SDK_ShowAllMapObjects SqVC_ShowAllMapObjects;
/* ------------------------------------------------------------------------------------------------
* WEAPONDATA
*/
extern SDK_SetWeaponDataValue SqVC_SetWeaponDataValue;
extern SDK_GetWeaponDataValue SqVC_GetWeaponDataValue;
extern SDK_ResetWeaponDataValue SqVC_ResetWeaponDataValue;
extern SDK_IsWeaponDataValueModified SqVC_IsWeaponDataValueModified;
extern SDK_ResetWeaponData SqVC_ResetWeaponData;
extern SDK_ResetAllWeaponData SqVC_ResetAllWeaponData;
/* ------------------------------------------------------------------------------------------------
* KEYBINDS
*/
extern SDK_GetKeyBindUnusedSlot SqVC_GetKeyBindUnusedSlot;
extern SDK_GetKeyBindData SqVC_GetKeyBindData;
extern SDK_RegisterKeyBind SqVC_RegisterKeyBind;
extern SDK_RemoveKeyBind SqVC_RemoveKeyBind;
extern SDK_RemoveAllKeyBinds SqVC_RemoveAllKeyBinds;
/* ------------------------------------------------------------------------------------------------
* BLIPS
*/
extern SDK_CreateCoordBlip SqVC_CreateCoordBlip;
extern SDK_DestroyCoordBlip SqVC_DestroyCoordBlip;
extern SDK_GetCoordBlipInfo SqVC_GetCoordBlipInfo;
/* ------------------------------------------------------------------------------------------------
* SPRITES
*/
extern SDK_CreateSprite SqVC_CreateSprite;
extern SDK_DestroySprite SqVC_DestroySprite;
extern SDK_ShowSprite SqVC_ShowSprite;
extern SDK_HideSprite SqVC_HideSprite;
extern SDK_MoveSprite SqVC_MoveSprite;
extern SDK_SetSpriteCenter SqVC_SetSpriteCenter;
extern SDK_RotateSprite SqVC_RotateSprite;
extern SDK_SetSpriteAlpha SqVC_SetSpriteAlpha;
extern SDK_SetSpriteRelativity SqVC_SetSpriteRelativity;
/* ------------------------------------------------------------------------------------------------
* TEXTDRAWS
*/
extern SDK_CreateTextdraw SqVC_CreateTextdraw;
extern SDK_DestroyTextdraw SqVC_DestroyTextdraw;
extern SDK_ShowTextdraw SqVC_ShowTextdraw;
extern SDK_HideTextdraw SqVC_HideTextdraw;
extern SDK_MoveTextdraw SqVC_MoveTextdraw;
extern SDK_SetTextdrawColour SqVC_SetTextdrawColour;
extern SDK_SetTextdrawRelativity SqVC_SetTextdrawRelativity;
/* ------------------------------------------------------------------------------------------------
* RADIOS
*/
extern SDK_AddRadioStream SqVC_AddRadioStream;
extern SDK_RemoveRadioStream SqVC_RemoveRadioStream;
/* ------------------------------------------------------------------------------------------------
* CLASSES
*/
extern SDK_SetUseClasses SqVC_SetUseClasses;
extern SDK_GetUseClasses SqVC_GetUseClasses;
extern SDK_GetPlayerClass SqVC_GetPlayerClass;
extern SDK_AddPlayerClass SqVC_AddPlayerClass;
extern SDK_SetSpawnPlayerPos SqVC_SetSpawnPlayerPos;
extern SDK_SetSpawnCameraPos SqVC_SetSpawnCameraPos;
extern SDK_SetSpawnCameraLookAt SqVC_SetSpawnCameraLookAt;
/* ------------------------------------------------------------------------------------------------
* ADMIN
*/
extern SDK_IsPlayerAdmin SqVC_IsPlayerAdmin;
extern SDK_SetPlayerAdmin SqVC_SetPlayerAdmin;
extern SDK_GetPlayerIP SqVC_GetPlayerIP;
extern SDK_KickPlayer SqVC_KickPlayer;
extern SDK_BanPlayer SqVC_BanPlayer;
extern SDK_BanIP SqVC_BanIP;
extern SDK_UnbanIP SqVC_UnbanIP;
extern SDK_IsIPBanned SqVC_IsIPBanned;
/* ------------------------------------------------------------------------------------------------
* PLAYERS: basic
*/
extern SDK_GetPlayerIDFromName SqVC_GetPlayerIDFromName;
extern SDK_IsPlayerConnected SqVC_IsPlayerConnected;
extern SDK_IsPlayerSpawned SqVC_IsPlayerSpawned;
extern SDK_IsPlayerStreamedForPlayer SqVC_IsPlayerStreamedForPlayer;
extern SDK_GetPlayerKey SqVC_GetPlayerKey;
extern SDK_SetPlayerWorld SqVC_SetPlayerWorld;
extern SDK_GetPlayerWorld SqVC_GetPlayerWorld;
extern SDK_SetPlayerSecWorld SqVC_SetPlayerSecWorld;
extern SDK_GetPlayerSecWorld SqVC_GetPlayerSecWorld;
extern SDK_GetPlayerUniqueWorld SqVC_GetPlayerUniqueWorld;
extern SDK_IsPlayerWorldCompatible SqVC_IsPlayerWorldCompatible;
extern SDK_GetPlayerState SqVC_GetPlayerState;
extern SDK_GetPlayerName SqVC_GetPlayerName;
extern SDK_SetPlayerName SqVC_SetPlayerName;
extern SDK_SetPlayerTeam SqVC_SetPlayerTeam;
extern SDK_GetPlayerTeam SqVC_GetPlayerTeam;
extern SDK_SetPlayerSkin SqVC_SetPlayerSkin;
extern SDK_GetPlayerSkin SqVC_GetPlayerSkin;
extern SDK_SetPlayerColour SqVC_SetPlayerColour;
extern SDK_GetPlayerColour SqVC_GetPlayerColour;
extern SDK_ForcePlayerSpawn SqVC_ForcePlayerSpawn;
extern SDK_ForcePlayerSelect SqVC_ForcePlayerSelect;
extern SDK_ForceAllSelect SqVC_ForceAllSelect;
/* ------------------------------------------------------------------------------------------------
* PLAYERS: score, ping, money, typing
*/
extern SDK_GivePlayerMoney SqVC_GivePlayerMoney;
extern SDK_SetPlayerMoney SqVC_SetPlayerMoney;
extern SDK_GetPlayerMoney SqVC_GetPlayerMoney;
extern SDK_SetPlayerScore SqVC_SetPlayerScore;
extern SDK_GetPlayerScore SqVC_GetPlayerScore;
extern SDK_GetPlayerPing SqVC_GetPlayerPing;
extern SDK_IsPlayerTyping SqVC_IsPlayerTyping;
extern SDK_GetPlayerFPS SqVC_GetPlayerFPS;
extern SDK_GetPlayerUID SqVC_GetPlayerUID;
extern SDK_GetPlayerWantedLevel SqVC_GetPlayerWantedLevel;
/* ------------------------------------------------------------------------------------------------
* PLAYERS: health and location
*/
extern SDK_SetPlayerHealth SqVC_SetPlayerHealth;
extern SDK_GetPlayerHealth SqVC_GetPlayerHealth;
extern SDK_SetPlayerArmour SqVC_SetPlayerArmour;
extern SDK_GetPlayerArmour SqVC_GetPlayerArmour;
extern SDK_SetPlayerImmunityFlags SqVC_SetPlayerImmunityFlags;
extern SDK_GetPlayerImmunityFlags SqVC_GetPlayerImmunityFlags;
extern SDK_SetPlayerPos SqVC_SetPlayerPos;
extern SDK_GetPlayerPos SqVC_GetPlayerPos;
extern SDK_SetPlayerSpeed SqVC_SetPlayerSpeed;
extern SDK_GetPlayerSpeed SqVC_GetPlayerSpeed;
extern SDK_AddPlayerSpeed SqVC_AddPlayerSpeed;
extern SDK_SetPlayerHeading SqVC_SetPlayerHeading;
extern SDK_GetPlayerHeading SqVC_GetPlayerHeading;
extern SDK_SetPlayerAlpha SqVC_SetPlayerAlpha;
extern SDK_GetPlayerAlpha SqVC_GetPlayerAlpha;
extern SDK_GetPlayerOnFireStatus SqVC_GetPlayerOnFireStatus;
extern SDK_GetPlayerCrouchStatus SqVC_GetPlayerCrouchStatus;
extern SDK_GetPlayerAction SqVC_GetPlayerAction;
extern SDK_GetPlayerGameKeys SqVC_GetPlayerGameKeys;
extern SDK_GetPlayerAimPos SqVC_GetPlayerAimPos;
extern SDK_GetPlayerAimDir SqVC_GetPlayerAimDir;
/* ------------------------------------------------------------------------------------------------
* PLAYERS: vehicle
*/
extern SDK_PutPlayerInVehicle SqVC_PutPlayerInVehicle;
extern SDK_RemovePlayerFromVehicle SqVC_RemovePlayerFromVehicle;
extern SDK_GetPlayerInVehicleStatus SqVC_GetPlayerInVehicleStatus;
extern SDK_GetPlayerInVehicleSlot SqVC_GetPlayerInVehicleSlot;
extern SDK_GetPlayerVehicleID SqVC_GetPlayerVehicleID;
/* ------------------------------------------------------------------------------------------------
* PLAYERS: toggles
*/
extern SDK_TogglePlayerControllable SqVC_TogglePlayerControllable;
extern SDK_EnabledPlayerControllable SqVC_EnabledPlayerControllable;
extern SDK_TogglePlayerDriveby SqVC_TogglePlayerDriveby;
extern SDK_EnabledPlayerDriveby SqVC_EnabledPlayerDriveby;
extern SDK_TogglePlayerWhiteScanlines SqVC_TogglePlayerWhiteScanlines;
extern SDK_EnabledPlayerWhiteScanlines SqVC_EnabledPlayerWhiteScanlines;
extern SDK_TogglePlayerGreenScanlines SqVC_TogglePlayerGreenScanlines;
extern SDK_EnabledPlayerGreenScanlines SqVC_EnabledPlayerGreenScanlines;
extern SDK_TogglePlayerWidescreen SqVC_TogglePlayerWidescreen;
extern SDK_EnabledPlayerWidescreen SqVC_EnabledPlayerWidescreen;
extern SDK_TogglePlayerShowMarkers SqVC_TogglePlayerShowMarkers;
extern SDK_EnabledPlayerShowMarkers SqVC_EnabledPlayerShowMarkers;
extern SDK_TogglePlayerAttackPriv SqVC_TogglePlayerAttackPriv;
extern SDK_EnabledPlayerAttackPriv SqVC_EnabledPlayerAttackPriv;
extern SDK_TogglePlayerHasMarker SqVC_TogglePlayerHasMarker;
extern SDK_EnabledPlayerHasMarker SqVC_EnabledPlayerHasMarker;
extern SDK_TogglePlayerChatTagsEnabled SqVC_TogglePlayerChatTagsEnabled;
extern SDK_EnabledPlayerChatTags SqVC_EnabledPlayerChatTags;
extern SDK_TogglePlayerDrunkEffects SqVC_TogglePlayerDrunkEffects;
extern SDK_EnabledPlayerDrunkEffects SqVC_EnabledPlayerDrunkEffects;
/* ------------------------------------------------------------------------------------------------
* PLAYERS: weapons
*/
extern SDK_GivePlayerWeapon SqVC_GivePlayerWeapon;
extern SDK_SetPlayerWeapon SqVC_SetPlayerWeapon;
extern SDK_GetPlayerWeapon SqVC_GetPlayerWeapon;
extern SDK_GetPlayerWeaponAmmo SqVC_GetPlayerWeaponAmmo;
extern SDK_SetPlayerWeaponSlot SqVC_SetPlayerWeaponSlot;
extern SDK_GetPlayerWeaponSlot SqVC_GetPlayerWeaponSlot;
extern SDK_GetPlayerWeaponAtSlot SqVC_GetPlayerWeaponAtSlot;
extern SDK_GetPlayerAmmoAtSlot SqVC_GetPlayerAmmoAtSlot;
extern SDK_RemovePlayerWeapon SqVC_RemovePlayerWeapon;
extern SDK_RemoveAllWeapons SqVC_RemoveAllWeapons;
/* ------------------------------------------------------------------------------------------------
* PLAYERS: camera
*/
extern SDK_SetCameraPosition SqVC_SetCameraPosition;
extern SDK_RestoreCamera SqVC_RestoreCamera;
extern SDK_IsCameraLocked SqVC_IsCameraLocked;
/* ------------------------------------------------------------------------------------------------
* PLAYERS: misc
*/
extern SDK_SetPlayerAnimation SqVC_SetPlayerAnimation;
extern SDK_SetPlayerWantedLevel SqVC_SetPlayerWantedLevel;
extern SDK_GetPlayerStandingOnVehicle SqVC_GetPlayerStandingOnVehicle;
extern SDK_GetPlayerStandingOnObject SqVC_GetPlayerStandingOnObject;
extern SDK_IsPlayerAway SqVC_IsPlayerAway;
extern SDK_GetPlayerSpectateTarget SqVC_GetPlayerSpectateTarget;
extern SDK_SetPlayerSpectateTarget SqVC_SetPlayerSpectateTarget;
extern SDK_RedirectPlayerToServer SqVC_RedirectPlayerToServer;
/* ------------------------------------------------------------------------------------------------
* VEHICLES
*/
extern SDK_CreateVehicle SqVC_CreateVehicle;
extern SDK_DeleteVehicle SqVC_DeleteVehicle;
extern SDK_GetVehicleSyncSource SqVC_GetVehicleSyncSource;
extern SDK_GetVehicleSyncType SqVC_GetVehicleSyncType;
extern SDK_IsVehicleStreamedForPlayer SqVC_IsVehicleStreamedForPlayer;
extern SDK_SetVehicleWorld SqVC_SetVehicleWorld;
extern SDK_GetVehicleWorld SqVC_GetVehicleWorld;
extern SDK_GetVehicleModel SqVC_GetVehicleModel;
extern SDK_GetVehicleOccupant SqVC_GetVehicleOccupant;
extern SDK_RespawnVehicle SqVC_RespawnVehicle;
extern SDK_SetVehicleImmunityFlags SqVC_SetVehicleImmunityFlags;
extern SDK_GetVehicleImmunityFlags SqVC_GetVehicleImmunityFlags;
extern SDK_KillVehicle SqVC_KillVehicle;
extern SDK_IsVehicleWrecked SqVC_IsVehicleWrecked;
extern SDK_SetVehiclePos SqVC_SetVehiclePos;
extern SDK_GetVehiclePos SqVC_GetVehiclePos;
extern SDK_SetVehicleRot SqVC_SetVehicleRot;
extern SDK_SetVehicleRotEuler SqVC_SetVehicleRotEuler;
extern SDK_GetVehicleRot SqVC_GetVehicleRot;
extern SDK_GetVehicleRotEuler SqVC_GetVehicleRotEuler;
extern SDK_SetVehicleSpeed SqVC_SetVehicleSpeed;
extern SDK_GetVehicleSpeed SqVC_GetVehicleSpeed;
extern SDK_AddVehicleSpeed SqVC_AddVehicleSpeed;
extern SDK_SetVehicleRelSpeed SqVC_SetVehicleRelSpeed;
extern SDK_GetVehicleRelSpeed SqVC_GetVehicleRelSpeed;
extern SDK_AddVehicleRelSpeed SqVC_AddVehicleRelSpeed;
extern SDK_SetVehicleTurnSpeed SqVC_SetVehicleTurnSpeed;
extern SDK_GetVehicleTurnSpeed SqVC_GetVehicleTurnSpeed;
extern SDK_AddVehicleTurnSpeed SqVC_AddVehicleTurnSpeed;
extern SDK_SetVehicleRelTurnSpeed SqVC_SetVehicleRelTurnSpeed;
extern SDK_GetVehicleRelTurnSpeed SqVC_GetVehicleRelTurnSpeed;
extern SDK_AddVehicleRelTurnSpeed SqVC_AddVehicleRelTurnSpeed;
extern SDK_SetVehicleSpawnPos SqVC_SetVehicleSpawnPos;
extern SDK_GetVehicleSpawnPos SqVC_GetVehicleSpawnPos;
extern SDK_SetVehicleSpawnRot SqVC_SetVehicleSpawnRot;
extern SDK_SetVehicleSpawnRotEuler SqVC_SetVehicleSpawnRotEuler;
extern SDK_GetVehicleSpawnRot SqVC_GetVehicleSpawnRot;
extern SDK_GetVehicleSpawnRotEuler SqVC_GetVehicleSpawnRotEuler;
extern SDK_SetVehicleIdleRespawnTimer SqVC_SetVehicleIdleRespawnTimer;
extern SDK_GetVehicleIdleRespawnTimer SqVC_GetVehicleIdleRespawnTimer;
extern SDK_SetVehicleHealth SqVC_SetVehicleHealth;
extern SDK_GetVehicleHealth SqVC_GetVehicleHealth;
extern SDK_SetVehicleColour SqVC_SetVehicleColour;
extern SDK_GetVehicleColour SqVC_GetVehicleColour;
extern SDK_SetVehicleDoorsLocked SqVC_SetVehicleDoorsLocked;
extern SDK_GetVehicleDoorsLocked SqVC_GetVehicleDoorsLocked;
extern SDK_SetVehiclePartStatus SqVC_SetVehiclePartStatus;
extern SDK_GetVehiclePartStatus SqVC_GetVehiclePartStatus;
extern SDK_SetVehicleTyreStatus SqVC_SetVehicleTyreStatus;
extern SDK_GetVehicleTyreStatus SqVC_GetVehicleTyreStatus;
extern SDK_SetVehicleDamageData SqVC_SetVehicleDamageData;
extern SDK_GetVehicleDamageData SqVC_GetVehicleDamageData;
extern SDK_SetVehicleAlarm SqVC_SetVehicleAlarm;
extern SDK_GetVehicleAlarm SqVC_GetVehicleAlarm;
extern SDK_SetVehicleLights SqVC_SetVehicleLights;
extern SDK_GetVehicleLights SqVC_GetVehicleLights;
extern SDK_SetVehicleRadio SqVC_SetVehicleRadio;
extern SDK_GetVehicleRadio SqVC_GetVehicleRadio;
extern SDK_SetVehicleRadioLocked SqVC_SetVehicleRadioLocked;
extern SDK_IsVehicleRadioLocked SqVC_IsVehicleRadioLocked;
extern SDK_GetVehicleGhostState SqVC_GetVehicleGhostState;
extern SDK_SetVehicleGhostState SqVC_SetVehicleGhostState;
extern SDK_GetVehicleTurretRotation SqVC_GetVehicleTurretRotation;
/* ------------------------------------------------------------------------------------------------
* VEHICLES: handling
*/
extern SDK_ResetAllVehicleHandlings SqVC_ResetAllVehicleHandlings;
extern SDK_ExistsHandlingRule SqVC_ExistsHandlingRule;
extern SDK_SetHandlingRule SqVC_SetHandlingRule;
extern SDK_GetHandlingRule SqVC_GetHandlingRule;
extern SDK_ResetHandlingRule SqVC_ResetHandlingRule;
extern SDK_ResetHandling SqVC_ResetHandling;
extern SDK_ExistsInstHandlingRule SqVC_ExistsInstHandlingRule;
extern SDK_SetInstHandlingRule SqVC_SetInstHandlingRule;
extern SDK_GetInstHandlingRule SqVC_GetInstHandlingRule;
extern SDK_ResetInstHandlingRule SqVC_ResetInstHandlingRule;
extern SDK_ResetInstHandling SqVC_ResetInstHandling;
/* ------------------------------------------------------------------------------------------------
* PICKUPS
*/
extern SDK_CreatePickup SqVC_CreatePickup;
extern SDK_DeletePickup SqVC_DeletePickup;
extern SDK_IsPickupStreamedForPlayer SqVC_IsPickupStreamedForPlayer;
extern SDK_SetPickupWorld SqVC_SetPickupWorld;
extern SDK_GetPickupWorld SqVC_GetPickupWorld;
extern SDK_PickupGetAlpha SqVC_PickupGetAlpha;
extern SDK_PickupSetAlpha SqVC_PickupSetAlpha;
extern SDK_PickupIsAutomatic SqVC_PickupIsAutomatic;
extern SDK_PickupSetAutomatic SqVC_PickupSetAutomatic;
extern SDK_SetPickupAutoTimer SqVC_SetPickupAutoTimer;
extern SDK_GetPickupAutoTimer SqVC_GetPickupAutoTimer;
extern SDK_PickupRefresh SqVC_PickupRefresh;
extern SDK_PickupGetPos SqVC_PickupGetPos;
extern SDK_PickupSetPos SqVC_PickupSetPos;
extern SDK_PickupGetModel SqVC_PickupGetModel;
extern SDK_PickupGetQuantity SqVC_PickupGetQuantity;
/* ------------------------------------------------------------------------------------------------
* OBJECTS
*/
extern SDK_CreateObject SqVC_CreateObject;
extern SDK_DeleteObject SqVC_DeleteObject;
extern SDK_IsObjectStreamedForPlayer SqVC_IsObjectStreamedForPlayer;
extern SDK_GetObjectModel SqVC_GetObjectModel;
extern SDK_SetObjectWorld SqVC_SetObjectWorld;
extern SDK_GetObjectWorld SqVC_GetObjectWorld;
extern SDK_SetObjectAlpha SqVC_SetObjectAlpha;
extern SDK_GetObjectAlpha SqVC_GetObjectAlpha;
extern SDK_MoveObjectTo SqVC_MoveObjectTo;
extern SDK_MoveObjectBy SqVC_MoveObjectBy;
extern SDK_SetObjectPos SqVC_SetObjectPos;
extern SDK_GetObjectPos SqVC_GetObjectPos;
extern SDK_RotObjectTo SqVC_RotObjectTo;
extern SDK_RotObjectToEuler SqVC_RotObjectToEuler;
extern SDK_RotObjectBy SqVC_RotObjectBy;
extern SDK_RotObjectByEuler SqVC_RotObjectByEuler;
extern SDK_GetObjectRot SqVC_GetObjectRot;
extern SDK_GetObjectRotEuler SqVC_GetObjectRotEuler;
extern SDK_SetObjectShotReport SqVC_SetObjectShotReport;
extern SDK_IsObjectShotReport SqVC_IsObjectShotReport;
extern SDK_SetObjectBumpReport SqVC_SetObjectBumpReport;
extern SDK_IsObjectBumpReport SqVC_IsObjectBumpReport;
/* ------------------------------------------------------------------------------------------------
*
*/
extern SDK_ToggleWallglitch SqVC_ToggleWallglitch;
extern SDK_EnabledWallglitch SqVC_EnabledWallglitch;
extern SDK_SetVehicleSiren SqVC_SetVehicleSiren;
extern SDK_GetVehicleSiren SqVC_GetVehicleSiren;
extern SDK_GetPlayerUID2 SqVC_GetPlayerUID2;
/* ------------------------------------------------------------------------------------------------
*
*/
extern SDK_CreateCheckpoint SqVC_CreateCheckpoint;
extern SDK_DeleteCheckpoint SqVC_DeleteCheckpoint;
extern SDK_IsCheckpointStreamedForPlayer SqVC_IsCheckpointStreamedForPlayer;
extern SDK_SetCheckpointWorld SqVC_SetCheckpointWorld;
extern SDK_GetCheckpointWorld SqVC_GetCheckpointWorld;
extern SDK_SetCheckpointColor SqVC_SetCheckpointColor;
extern SDK_GetCheckpointColor SqVC_GetCheckpointColor;
extern SDK_SetCheckpointPos SqVC_SetCheckpointPos;
extern SDK_GetCheckpointPos SqVC_GetCheckpointPos;
extern SDK_SetCheckpointRadius SqVC_SetCheckpointRadius;
extern SDK_GetCheckpointRadius SqVC_GetCheckpointRadius;
extern SDK_GetCheckpointOwner SqVC_GetCheckpointOwner;
/* ------------------------------------------------------------------------------------------------
*
*/
extern SDK_CreateSphere SqVC_CreateSphere;
extern SDK_DeleteSphere SqVC_DeleteSphere;
extern SDK_IsSphereStreamedForPlayer SqVC_IsSphereStreamedForPlayer;
extern SDK_SetSphereWorld SqVC_SetSphereWorld;
extern SDK_GetSphereWorld SqVC_GetSphereWorld;
extern SDK_SetSphereColor SqVC_SetSphereColor;
extern SDK_GetSphereColor SqVC_GetSphereColor;
extern SDK_SetSpherePos SqVC_SetSpherePos;
extern SDK_GetSpherePos SqVC_GetSpherePos;
extern SDK_SetSphereRadius SqVC_SetSphereRadius;
extern SDK_GetSphereRadius SqVC_GetSphereRadius;
extern SDK_GetSphereOwner SqVC_GetSphereOwner;
/* --------------------------------------------------------------------------------------------
* Import the functions from the main squirrel plugin.
*/
SQUIRREL_API HSQEXPORTS sq_api_import(PluginFuncs * vcapi);
/* --------------------------------------------------------------------------------------------
* Assign the functions from the specified API structure into the global functions.
*/
SQUIRREL_API SQRESULT sq_api_expand(HSQAPI sqapi);
/* --------------------------------------------------------------------------------------------
* Undo changes done by sq_api_expand.
*/
SQUIRREL_API void sq_api_collapse();
/* --------------------------------------------------------------------------------------------
* Assign the functions from the specified API structure into the global functions.
*/
SQUIRREL_API SQRESULT vc_api_expand(PluginFuncs * vcapi);
/* --------------------------------------------------------------------------------------------
* Undo changes done by vc_api_expand.
*/
SQUIRREL_API void vc_api_collapse();
#ifdef __cplusplus
} /*extern "C"*/
#endif
#endif /*_SQ_API_H_*/

1968
shared/sq_mod.inl Normal file

File diff suppressed because it is too large Load Diff

View File

@ -229,26 +229,33 @@ bool Core::Init()
{
// Get the file path as a string
String path(itr->pItem);
// See if it wasn't already loaded
if (m_Scripts.find(path) != m_Scripts.end())
// See if the specified script path is valid
if (path.empty())
{
LogWrn("Script was already loaded: %s", path.c_str());
// Simply ignore it
continue;
}
// See if it wasn't already loaded
else if (m_Scripts.find(path) != m_Scripts.end())
{
LogWrn("Script was specified before: %s", path.c_str());
// No point in loading it again
continue;
}
// Attempt to compile it
else if (!Compile(path))
// Create a new script container and insert it into the script pool
std::pair< Scripts::iterator, bool > res = m_Scripts.insert(Scripts::value_type(path, Script(m_VM)));
// We don't compile the scripts yet. We just store their path and prepare the objects.
if (!res.second)
{
// Plug-in shouldn't load
LogErr("Unable to queue script: %s", path.c_str());
// Drop all previous scripts
m_Scripts.clear();
// Failed to compile the specified script
return false;
}
else
{
LogScs("Successfully compiled script: %s", path.c_str());
}
}
// See if any script could be compiled
if (m_Scripts.empty())
if (m_Scripts.empty() && !conf.GetBoolValue("Config", "EmptyInit", false))
{
LogErr("No scripts compiled. No reason to load the plug-in");
// No point in loading the plug-in
@ -303,26 +310,28 @@ bool Core::Load()
{
// Are there any scripts to execute?
if (cLogErr(m_Scripts.empty(), "No scripts to execute. Plug-in has no purpose"))
{
return false;
}
LogDbg("Signaling outside plugins to register their API");
// Signal outside plugins to do their monkey business
_Func->SendCustomCommand(0xDABBAD00, "");
LogDbg("Attempting to execute the specified scripts");
// Go through each loaded script
// Go through each specified script
for (Scripts::iterator itr = m_Scripts.begin(); itr != m_Scripts.end(); ++itr)
{
// Attempt to load and compile the script file
itr->second.CompileFile(itr->first);
// See if any compile time error occurred during compilation
if (Error::Occurred(m_VM))
return false; /* Failed to load properly */
// Attempt to execute the script
itr->second.Run();
// See if the executed script had any errors
if (Error::Occurred(m_VM))
{
// Failed to execute scripts
return false;
}
return false; /* Failed to load properly */
else
{
LogScs("Successfully executed script: %s", itr->first.c_str());
}
}
// Successfully loaded
return true;
}
@ -363,42 +372,6 @@ void Core::Terminate()
}
}
bool Core::Compile(const string & name)
{
// See if the specified script path is valid
if (name.empty())
{
LogErr("Cannot compile script without a valid name");
// Failed to compile the specified script
return false;
}
// Create a new script container and insert it into the script pool
std::pair< Scripts::iterator, bool > res = m_Scripts.insert(Scripts::value_type(name, Script(m_VM)));
// See if the script container could be created and inserted
if (res.second)
{
// Attempt to load and compile the specified script file
res.first->second.CompileFile(name);
// See if any compile time error occurred in the compiled script
if (Error::Occurred(m_VM))
{
// Release the script container
m_Scripts.erase(res.first);
// Failed to compile the specified script
return false;
}
}
// Failed to create the script container
else
{
LogErr("Unable to queue script: %s", name.c_str());
// Failed to compile the specified script
return false;
}
// At this point everything went as it should
return true;
}
// ------------------------------------------------------------------------------------------------
CSStr Core::GetOption(const String & name) const
{

View File

@ -499,11 +499,6 @@ public:
protected:
/* --------------------------------------------------------------------------------------------
* Compile the specified file as a script.
*/
bool Compile(const string & name);
/* --------------------------------------------------------------------------------------------
* Script output handlers.
*/

227
source/Exports.cpp Normal file
View File

@ -0,0 +1,227 @@
// ------------------------------------------------------------------------------------------------
#include "Core.hpp"
// ------------------------------------------------------------------------------------------------
#include <stdlib.h>
#include <string.h>
// ------------------------------------------------------------------------------------------------
#include <sqstdio.h>
#include <sqstdblob.h>
#include <sqstdstring.h>
#include <sq_mod.h>
// ------------------------------------------------------------------------------------------------
namespace SqMod {
// ------------------------------------------------------------------------------------------------
static SQAPI g_SqAPI;
static SQEXPORTS g_SqExports;
// ------------------------------------------------------------------------------------------------
static HSQAPI GetSquirrelAPI()
{
return &g_SqAPI;
}
// ------------------------------------------------------------------------------------------------
static HSQUIRRELVM GetSquirrelVM()
{
if (_Core)
return _Core->GetVM();
return NULL;
}
// ------------------------------------------------------------------------------------------------
void InitExports()
{
static HSQEXPORTS sqexports = &g_SqExports;
// Assign the functions that should be exported
g_SqExports.uStructSize = sizeof(SQEXPORTS);
g_SqExports.GetSquirrelAPI = GetSquirrelAPI;
g_SqExports.GetSquirrelVM = GetSquirrelVM;
// Export them to the server
_Func->ExportFunctions(_Info->nPluginId, (void **)(&sqexports), sizeof(SQEXPORTS));
/*vm*/
g_SqAPI.open = sq_open;
g_SqAPI.newthread = sq_newthread;
g_SqAPI.seterrorhandler = sq_seterrorhandler;
g_SqAPI.close = sq_close;
g_SqAPI.setforeignptr = sq_setforeignptr;
g_SqAPI.getforeignptr = sq_getforeignptr;
g_SqAPI.setsharedforeignptr = sq_setsharedforeignptr;
g_SqAPI.getsharedforeignptr = sq_getsharedforeignptr;
g_SqAPI.setvmreleasehook = sq_setvmreleasehook;
g_SqAPI.getvmreleasehook = sq_getvmreleasehook;
g_SqAPI.setsharedreleasehook = sq_setsharedreleasehook;
g_SqAPI.getsharedreleasehook = sq_getsharedreleasehook;
g_SqAPI.setprintfunc = sq_setprintfunc;
g_SqAPI.getprintfunc = sq_getprintfunc;
g_SqAPI.geterrorfunc = sq_geterrorfunc;
g_SqAPI.suspendvm = sq_suspendvm;
g_SqAPI.wakeupvm = sq_wakeupvm;
g_SqAPI.getvmstate = sq_getvmstate;
g_SqAPI.getversion = sq_getversion;
/*compiler*/
g_SqAPI.compile = sq_compile;
g_SqAPI.compilebuffer = sq_compilebuffer;
g_SqAPI.enabledebuginfo = sq_enabledebuginfo;
g_SqAPI.notifyallexceptions = sq_notifyallexceptions;
g_SqAPI.setcompilererrorhandler = sq_setcompilererrorhandler;
/*stack operations*/
g_SqAPI.push = sq_push;
g_SqAPI.pop = sq_pop;
g_SqAPI.poptop = sq_poptop;
g_SqAPI.remove = sq_remove;
g_SqAPI.gettop = sq_gettop;
g_SqAPI.settop = sq_settop;
g_SqAPI.reservestack = sq_reservestack;
g_SqAPI.cmp = sq_cmp;
g_SqAPI.move = sq_move;
/*object creation handling*/
g_SqAPI.newuserdata = sq_newuserdata;
g_SqAPI.newtable = sq_newtable;
g_SqAPI.newtableex = sq_newtableex;
g_SqAPI.newarray = sq_newarray;
g_SqAPI.newclosure = sq_newclosure;
g_SqAPI.setparamscheck = sq_setparamscheck;
g_SqAPI.bindenv = sq_bindenv;
g_SqAPI.setclosureroot = sq_setclosureroot;
g_SqAPI.getclosureroot = sq_getclosureroot;
g_SqAPI.pushstring = sq_pushstring;
g_SqAPI.pushfloat = sq_pushfloat;
g_SqAPI.pushinteger = sq_pushinteger;
g_SqAPI.pushbool = sq_pushbool;
g_SqAPI.pushuserpointer = sq_pushuserpointer;
g_SqAPI.pushnull = sq_pushnull;
g_SqAPI.pushthread = sq_pushthread;
g_SqAPI.gettype = sq_gettype;
g_SqAPI.typeof_ = sq_typeof;
g_SqAPI.getsize = sq_getsize;
g_SqAPI.gethash = sq_gethash;
g_SqAPI.getbase = sq_getbase;
g_SqAPI.instanceof = sq_instanceof;
g_SqAPI.tostring = sq_tostring;
g_SqAPI.tobool = sq_tobool;
g_SqAPI.getstring = sq_getstring;
g_SqAPI.getinteger = sq_getinteger;
g_SqAPI.getfloat = sq_getfloat;
g_SqAPI.getbool = sq_getbool;
g_SqAPI.getthread = sq_getthread;
g_SqAPI.getuserpointer = sq_getuserpointer;
g_SqAPI.getuserdata = sq_getuserdata;
g_SqAPI.settypetag = sq_settypetag;
g_SqAPI.gettypetag = sq_gettypetag;
g_SqAPI.setreleasehook = sq_setreleasehook;
g_SqAPI.getreleasehook = sq_getreleasehook;
g_SqAPI.getscratchpad = sq_getscratchpad;
g_SqAPI.getfunctioninfo = sq_getfunctioninfo;
g_SqAPI.getclosureinfo = sq_getclosureinfo;
g_SqAPI.getclosurename = sq_getclosurename;
g_SqAPI.setnativeclosurename = sq_setnativeclosurename;
g_SqAPI.setinstanceup = sq_setinstanceup;
g_SqAPI.getinstanceup = sq_getinstanceup;
g_SqAPI.setclassudsize = sq_setclassudsize;
g_SqAPI.newclass = sq_newclass;
g_SqAPI.createinstance = sq_createinstance;
g_SqAPI.setattributes = sq_setattributes;
g_SqAPI.getattributes = sq_getattributes;
g_SqAPI.getclass = sq_getclass;
g_SqAPI.weakref = sq_weakref;
g_SqAPI.getdefaultdelegate = sq_getdefaultdelegate;
g_SqAPI.getmemberhandle = sq_getmemberhandle;
g_SqAPI.getbyhandle = sq_getbyhandle;
g_SqAPI.setbyhandle = sq_setbyhandle;
/*object manipulation*/
g_SqAPI.pushroottable = sq_pushroottable;
g_SqAPI.pushregistrytable = sq_pushregistrytable;
g_SqAPI.pushconsttable = sq_pushconsttable;
g_SqAPI.setroottable = sq_setroottable;
g_SqAPI.setconsttable = sq_setconsttable;
g_SqAPI.newslot = sq_newslot;
g_SqAPI.deleteslot = sq_deleteslot;
g_SqAPI.set = sq_set;
g_SqAPI.get = sq_get;
g_SqAPI.rawget = sq_rawget;
g_SqAPI.rawset = sq_rawset;
g_SqAPI.rawdeleteslot = sq_rawdeleteslot;
g_SqAPI.newmember = sq_newmember;
g_SqAPI.rawnewmember = sq_rawnewmember;
g_SqAPI.arrayappend = sq_arrayappend;
g_SqAPI.arraypop = sq_arraypop;
g_SqAPI.arrayresize = sq_arrayresize;
g_SqAPI.arrayreverse = sq_arrayreverse;
g_SqAPI.arrayremove = sq_arrayremove;
g_SqAPI.arrayinsert = sq_arrayinsert;
g_SqAPI.setdelegate = sq_setdelegate;
g_SqAPI.getdelegate = sq_getdelegate;
g_SqAPI.clone = sq_clone;
g_SqAPI.setfreevariable = sq_setfreevariable;
g_SqAPI.next = sq_next;
g_SqAPI.getweakrefval = sq_getweakrefval;
g_SqAPI.clear = sq_clear;
/*calls*/
g_SqAPI.call = sq_call;
g_SqAPI.resume = sq_resume;
g_SqAPI.getlocal = sq_getlocal;
g_SqAPI.getcallee = sq_getcallee;
g_SqAPI.getfreevariable = sq_getfreevariable;
g_SqAPI.throwerror = sq_throwerror;
g_SqAPI.throwobject = sq_throwobject;
g_SqAPI.reseterror = sq_reseterror;
g_SqAPI.getlasterror = sq_getlasterror;
/*raw object handling*/
g_SqAPI.getstackobj = sq_getstackobj;
g_SqAPI.pushobject = sq_pushobject;
g_SqAPI.addref = sq_addref;
g_SqAPI.release = sq_release;
g_SqAPI.getrefcount = sq_getrefcount;
g_SqAPI.resetobject = sq_resetobject;
g_SqAPI.objtostring = sq_objtostring;
g_SqAPI.objtobool = sq_objtobool;
g_SqAPI.objtointeger = sq_objtointeger;
g_SqAPI.objtofloat = sq_objtofloat;
g_SqAPI.objtouserpointer = sq_objtouserpointer;
g_SqAPI.getobjtypetag = sq_getobjtypetag;
g_SqAPI.getvmrefcount = sq_getvmrefcount;
/*GC*/
g_SqAPI.collectgarbage = sq_collectgarbage;
g_SqAPI.resurrectunreachable = sq_resurrectunreachable;
/*serialization*/
g_SqAPI.writeclosure = sq_writeclosure;
g_SqAPI.readclosure = sq_readclosure;
/*mem allocation*/
g_SqAPI.malloc = sq_malloc;
g_SqAPI.realloc = sq_realloc;
g_SqAPI.free = sq_free;
/*debug*/
g_SqAPI.stackinfos = sq_stackinfos;
g_SqAPI.setdebughook = sq_setdebughook;
g_SqAPI.setnativedebughook = sq_setnativedebughook;
/*compiler helpers*/
g_SqAPI.loadfile = sqstd_loadfile;
g_SqAPI.dofile = sqstd_dofile;
g_SqAPI.writeclosuretofile = sqstd_writeclosuretofile;
/*blob*/
g_SqAPI.createblob = sqstd_createblob;
g_SqAPI.getblob = sqstd_getblob;
g_SqAPI.getblobsize = sqstd_getblobsize;
/*string*/
g_SqAPI.format = sqstd_format;
}
} // Namespace:: SqMod

View File

@ -10,6 +10,11 @@
#include <winsock2.h>
#endif // _WIN32
// ------------------------------------------------------------------------------------------------
namespace SqMod {
extern void InitExports();
} // Namespace:: SqMod
// ------------------------------------------------------------------------------------------------
using namespace SqMod;
@ -17,6 +22,29 @@ using namespace SqMod;
void BindCallbacks();
void UnbindCallbacks();
// ------------------------------------------------------------------------------------------------
void DestroyComponents()
{
// Destroy command component
if (_Cmd)
{
delete _Cmd;
_Cmd = NULL;
}
// Destroy core component
if (_Core)
{
delete _Core;
_Core = NULL;
}
// Destroy logger component
if (_Log)
{
delete _Log;
_Log = NULL;
}
}
// ------------------------------------------------------------------------------------------------
SQMOD_API_EXPORT unsigned int VcmpPluginInit(PluginFuncs * funcs, PluginCallbacks * calls, PluginInfo * info)
{
@ -24,23 +52,31 @@ SQMOD_API_EXPORT unsigned int VcmpPluginInit(PluginFuncs * funcs, PluginCallback
WSADATA wsaData;
#endif // _WIN32
_Log = Logger::Get();
_Core = Core::Get();
_Cmd = CmdManager::Get();
// Verify that core components are working
if (!_Log)
{
puts("[SQMOD] Unable to start because the logging class could not be instantiated");
return SQMOD_FAILURE;
}
else if (!_Core)
_Core = Core::Get();
if (!_Core)
{
DestroyComponents();
puts("[SQMOD] Unable to start because the central core class could not be instantiated");
return SQMOD_FAILURE;
}
_Cmd = CmdManager::Get();
if (!_Cmd)
{
DestroyComponents();
puts("[SQMOD] Unable to start because the command class could not be instantiated");
return SQMOD_FAILURE;
}
#if defined(_WIN32)
// Initialize the sockets on windows
else if (WSAStartup(MAKEWORD(2, 2), &wsaData) != 0)
if (WSAStartup(MAKEWORD(2, 2), &wsaData) != 0)
{
DestroyComponents();
puts("[SQMOD] Unable to start because the windows sockets could not be initialized");
return SQMOD_FAILURE;
}
@ -51,12 +87,13 @@ SQMOD_API_EXPORT unsigned int VcmpPluginInit(PluginFuncs * funcs, PluginCallback
_Info = info;
_Info->uPluginVer = SQMOD_VERSION;
strcpy(_Info->szName, SQMOD_NAME);
strcpy(_Info->szName, SQMOD_HOST_NAME);
if (!_Core->Init())
{
LogFtl("The plugin failed to initialize");
_Core->Terminate();
DestroyComponents();
return SQMOD_FAILURE;
}
else if (_Clbk)
@ -65,15 +102,23 @@ SQMOD_API_EXPORT unsigned int VcmpPluginInit(PluginFuncs * funcs, PluginCallback
}
else
{
_Core->Terminate();
DestroyComponents();
LogFtl("Unable to start because the server callbacks are missing");
return SQMOD_FAILURE;
}
// Attempt to initialize the plugin exports
InitExports();
// Initialization was successful
return SQMOD_SUCCESS;
}
// --------------------------------------------------------------------------------------------
static int VC_InitServer(void)
{
if (!_Core)
return SQMOD_FAILURE;
_Core->SetState(1);
if (_Core->Load())
@ -86,18 +131,16 @@ static int VC_InitServer(void)
static void VC_ShutdownServer(void)
{
if (!_Core)
return;
_Core->EmitServerShutdown();
// Deallocate and release everything obtained at startup
_Core->Terminate();
// The server still triggers callbacks and we deallocated everything!
UnbindCallbacks();
// Destroy core components
delete _Cmd;
delete _Core;
delete _Log;
_Cmd = NULL;
_Core = NULL;
_Log = NULL;
// Destroy components
DestroyComponents();
}
static void VC_Frame(float delta)

View File

@ -112,6 +112,7 @@
#define SQMOD_NAME "Squirrel Module"
#define SQMOD_AUTHOR "Sandu Liviu Catalin"
#define SQMOD_COPYRIGHT "Copyright (C) 2015 Sandu Liviu Catalin"
#define SQMOD_HOST_NAME "SqModHost"
#define SQMOD_VERSION 001
#define SQMOD_VERSION_STR "0.0.1"
#define SQMOD_VERSION_MAJOR 0
@ -444,6 +445,8 @@ enum CmdError
#define SQMOD_API_EXPORT extern "C" __declspec(dllexport)
#elif defined(__GNUC__)
#define SQMOD_API_EXPORT extern "C"
#else
#define SQMOD_API_EXPORT extern "C"
#endif
/* ------------------------------------------------------------------------------------------------