28 #if !defined(_SCRAT_SCRIPT_H_)
29 #define _SCRAT_SCRIPT_H_
35 #include "sqratObject.h"
62 void CompileString(
const string& script,
const string& name = _SC(
"")) {
68 #if !defined (SCRAT_NO_ERROR_CHECKING)
69 if(SQ_FAILED(sq_compilebuffer(vm, script.c_str(),
static_cast<SQInteger
>(script.size() ), name.c_str(),
true))) {
74 sq_compilebuffer(vm, script.c_str(),
static_cast<SQInteger
>(script.size() ), name.c_str(),
true);
76 sq_getstackobj(vm,-1,&obj);
88 bool CompileString(
const string& script,
string& errMsg,
const string& name = _SC(
"")) {
94 #if !defined (SCRAT_NO_ERROR_CHECKING)
95 if(SQ_FAILED(sq_compilebuffer(vm, script.c_str(),
static_cast<SQInteger
>(script.size() ), name.c_str(),
true))) {
96 errMsg = LastErrorString(vm);
100 sq_compilebuffer(vm, script.c_str(),
static_cast<SQInteger
>(script.size() ), name.c_str(),
true);
102 sq_getstackobj(vm,-1,&obj);
118 if(!sq_isnull(obj)) {
119 sq_release(vm, &obj);
120 sq_resetobject(&obj);
123 #if !defined (SCRAT_NO_ERROR_CHECKING)
124 if(SQ_FAILED(sqstd_loadfile(vm, path.c_str(),
true))) {
129 sqstd_loadfile(vm, path.c_str(),
true);
131 sq_getstackobj(vm,-1,&obj);
144 if(!sq_isnull(obj)) {
145 sq_release(vm, &obj);
146 sq_resetobject(&obj);
149 #if !defined (SCRAT_NO_ERROR_CHECKING)
150 if(SQ_FAILED(sqstd_loadfile(vm, path.c_str(),
true))) {
151 errMsg = LastErrorString(vm);
155 sqstd_loadfile(vm, path.c_str(),
true);
157 sq_getstackobj(vm,-1,&obj);
171 #if !defined (SCRAT_NO_ERROR_CHECKING)
172 if(!sq_isnull(obj)) {
174 sq_pushobject(vm, obj);
175 sq_pushroottable(vm);
176 result = sq_call(vm, 1,
false,
true);
178 if(SQ_FAILED(result)) {
184 sq_pushobject(vm, obj);
185 sq_pushroottable(vm);
186 sq_call(vm, 1,
false,
true);
191 #if !defined (SCRAT_NO_ERROR_CHECKING)
192 bool Run(
string& errMsg) {
199 if(!sq_isnull(obj)) {
201 sq_pushobject(vm, obj);
202 sq_pushroottable(vm);
203 result = sq_call(vm, 1,
false,
true);
205 if(SQ_FAILED(result)) {
206 errMsg = LastErrorString(vm);
222 #if !defined (SCRAT_NO_ERROR_CHECKING)
223 if(!sq_isnull(obj)) {
224 sq_pushobject(vm, obj);
225 sqstd_writeclosuretofile(vm, path.c_str());
228 sq_pushobject(vm, obj);
229 sqstd_writeclosuretofile(vm, path.c_str());
static HSQUIRRELVM Get()
Definition: sqratUtil.h:92
void CompileFile(const string &path)
Definition: sqratScript.h:117
Script(HSQUIRRELVM v=DefaultVM::Get())
Definition: sqratScript.h:50
void WriteCompiledFile(const string &path)
Definition: sqratScript.h:221
void Run()
Definition: sqratScript.h:170
Definition: sqratObject.h:48
static Error & Instance()
Definition: sqratUtil.h:134
void Throw(HSQUIRRELVM vm, const string &err)
Definition: sqratUtil.h:210
bool CompileString(const string &script, string &errMsg, const string &name=_SC(""))
Definition: sqratScript.h:88
Helper class for managing Squirrel scripts.
Definition: sqratScript.h:42
bool CompileFile(const string &path, string &errMsg)
Definition: sqratScript.h:143
void CompileString(const string &script, const string &name=_SC(""))
Definition: sqratScript.h:62