10 #include <sqstdmath.h> 11 #include <sqstdstring.h> 13 #include <sqstdblob.h> 16 #define STRLEN(n) _tcslen(n) 18 #define STRLEN(n) strlen(n) 21 HSQUIRRELVM SquirrelVM::_VM =
NULL;
22 SQInteger SquirrelVM::_CallState = -1;
23 SquirrelObject * SquirrelVM::_root =
NULL;
25 SquirrelError::SquirrelError()
34 desc = sqT(
"unknown error");
39 void SquirrelVM::Init(SquirrelInitFlags flags)
51 _root =
new SquirrelObject();
52 _root->AttachToStackObject(-1);
57 BOOL_T SquirrelVM::Update()
70 void SquirrelVM::Shutdown()
86 void SquirrelVM::PrintFunc(HSQUIRRELVM ,
const SQChar* s,...)
91 scvsprintf( temp,s, vl);
96 SquirrelObject SquirrelVM::CompileScript(
const SQChar *s)
98 #define MAX_EXPANDED_PATH 1023 101 ret.AttachToStackObject(-1);
105 throw SquirrelError();
108 SquirrelObject SquirrelVM::CompileBuffer(
const SQChar *s,
const SQChar * debugInfo)
112 ret.AttachToStackObject(-1);
116 throw SquirrelError();
119 SquirrelObject SquirrelVM::RunScript(
const SquirrelObject &o,SquirrelObject *_this)
129 if(SQ_SUCCEEDED(
sq_call(_VM,1,SQTrue,SQ_CALL_RAISE_ERROR))) {
130 ret.AttachToStackObject(-1);
135 throw SquirrelError();
140 BOOL_T SquirrelVM::BeginCall(
const SquirrelObject &func)
150 BOOL_T SquirrelVM::BeginCall(
const SquirrelObject &func,SquirrelObject &_this)
153 throw SquirrelError(sqT(
"call already initialized"));
160 #define _CHECK_CALL_STATE \ 161 if(_CallState == -1) \ 162 throw SquirrelError(sqT("call not initialized")); 164 void SquirrelVM::PushParam(
const SquirrelObject &o)
171 void SquirrelVM::PushParam(
const SQChar *s)
178 void SquirrelVM::PushParam(SQInteger n)
185 void SquirrelVM::PushParam(SQFloat f)
192 void SquirrelVM::PushParamNull()
199 void SquirrelVM::PushParam(SQUserPointer up)
206 SquirrelObject SquirrelVM::EndCall()
209 if(_CallState >= 0) {
211 SQInteger nparams = _CallState;
213 if(SQ_SUCCEEDED(
sq_call(_VM,nparams,SQTrue,SQ_CALL_RAISE_ERROR))) {
214 ret.AttachToStackObject(-1);
218 throw SquirrelError();
225 SquirrelObject SquirrelVM::CreateInstance(SquirrelObject &oclass)
232 throw SquirrelError();
234 ret.AttachToStackObject(-1);
239 SquirrelObject SquirrelVM::CreateTable()
243 ret.AttachToStackObject(-1);
248 SquirrelObject SquirrelVM::CreateString(
const SQChar *s)
252 ret.AttachToStackObject(-1);
258 SquirrelObject SquirrelVM::CreateArray(SQInteger size)
262 ret.AttachToStackObject(-1);
267 SquirrelObject SquirrelVM::CreateFunction(SQFUNCTION func)
271 ret.AttachToStackObject(-1);
276 SquirrelObject SquirrelVM::CreateUserData(SQInteger size) {
279 ret.AttachToStackObject(-1);
284 const SquirrelObject &SquirrelVM::GetRootTable()
289 void SquirrelVM::PushRootTable(
void) {
295 SquirrelObject SquirrelVM::CreateFunction(SQFUNCTION func,
const SQChar * scriptFuncName,
const SQChar * typeMask) {
299 ret.AttachToStackObject(-1);
302 SQInteger numParams = SQ_MATCHTYPEMASKSTRING;
304 if (typeMask[0] ==
'*') {
308 if (SCSNPRINTF(tm,
sizeof(tm),sqT(
"t|y|x%s"),typeMask) < 0) {
310 throw SquirrelError(sqT(
"CreateFunction: typeMask string too long."));
314 SCSNPRINTF(tm,
sizeof(tm),sqT(
"%s"),sqT(
"t|y|x"));
328 sq_createslot(_VM,-3);
332 SquirrelObject SquirrelVM::CreateFunction(SquirrelObject & so,SQFUNCTION func,
const SQChar * scriptFuncName,
const SQChar * typeMask) {
334 SquirrelObject ret = CreateFunction(func,scriptFuncName,typeMask);
341 SquirrelObject SquirrelVM::CreateFunctionGlobal(SQFUNCTION func,
const SQChar * scriptFuncName,
const SQChar * typeMask) {
344 SquirrelObject ret = CreateFunction(func,scriptFuncName,typeMask);
#define _CHECK_CALL_STATE
void sq_pop(HSQUIRRELVM v, SQInteger nelemstopop)
SQRESULT sq_setroottable(HSQUIRRELVM v)
void sq_newtable(HSQUIRRELVM v)
void sq_pushnull(HSQUIRRELVM v)
void sqstd_seterrorhandlers(HSQUIRRELVM v)
void sq_pushroottable(HSQUIRRELVM v)
void sq_pushfloat(HSQUIRRELVM v, SQFloat n)
SQInteger sq_gettop(HSQUIRRELVM v)
void sq_pushinteger(HSQUIRRELVM v, SQInteger n)
void sq_newclosure(HSQUIRRELVM v, SQFUNCTION func, SQUnsignedInteger nfreevars)
SQRESULT sq_call(HSQUIRRELVM v, SQInteger params, SQBool retval, SQBool raiseerror)
SQBool sq_release(HSQUIRRELVM v, HSQOBJECT *po)
SQRESULT sq_setnativeclosurename(HSQUIRRELVM v, SQInteger idx, const SQChar *name)
void sq_settop(HSQUIRRELVM v, SQInteger newtop)
SQRESULT sqstd_register_mathlib(HSQUIRRELVM v)
SQInteger sqstd_register_stringlib(HSQUIRRELVM v)
SQRESULT sq_setparamscheck(HSQUIRRELVM v, SQInteger nparamscheck, const SQChar *typemask)
void sq_pushstring(HSQUIRRELVM v, const SQChar *s, SQInteger len)
void sq_close(HSQUIRRELVM v)
SQRESULT sq_getstring(HSQUIRRELVM v, SQInteger idx, const SQChar **c)
SQRESULT sqstd_register_iolib(HSQUIRRELVM v)
void sq_getlasterror(HSQUIRRELVM v)
void sq_setprintfunc(HSQUIRRELVM v, SQPRINTFUNCTION printfunc)
void sq_resetobject(HSQOBJECT *po)
SQUserPointer sq_newuserdata(HSQUIRRELVM v, SQUnsignedInteger size)
HSQUIRRELVM sq_open(SQInteger initialstacksize)
void sq_newarray(HSQUIRRELVM v, SQInteger size)
SQRESULT sqstd_loadfile(HSQUIRRELVM v, const SQChar *filename, SQBool printerror)
SQRESULT sq_compilebuffer(HSQUIRRELVM v, const SQChar *s, SQInteger size, const SQChar *sourcename, SQBool raiseerror)
void sq_pushobject(HSQUIRRELVM v, HSQOBJECT obj)
SQRESULT sqstd_register_bloblib(HSQUIRRELVM v)
void sq_pushuserpointer(HSQUIRRELVM v, SQUserPointer p)
SQRESULT sq_createinstance(HSQUIRRELVM v, SQInteger idx)