Fixed bug in console eval command where Squirrel VM doesn't exist.

This commit is contained in:
Graham Clemo 2018-08-04 14:41:10 +01:00
parent b4222fdb2a
commit 0642d121ca
1 changed files with 31 additions and 12 deletions

View File

@ -93,6 +93,7 @@ void squirrel_compilerError(HSQUIRRELVM vm, const SQChar* desc, const SQChar* so
char buffer[1024];
snprintf(buffer, 1023, "%.40s line %.6d column %.6d: %s\n", source, (int)line, (int)column, desc);
if (machine->data)
machine->data->error(machine->data->data, buffer);
}
@ -107,6 +108,7 @@ static SQInteger squirrel_errorHandler(HSQUIRRELVM vm)
char buffer[100];
snprintf(buffer, 99, "%.40s %.40s %.6d\n", si.funcname, si.source, (int)si.line);
if (machine->data)
machine->data->error(machine->data->data, buffer);
++level;
}
@ -1142,6 +1144,7 @@ static SQInteger squirrel_trace(HSQUIRRELVM vm)
color = getSquirrelNumber(vm, 3);
}
if (machine->data)
machine->data->trace(machine->data->data, text ? text : "nil", color);
}
@ -1194,6 +1197,7 @@ static SQInteger squirrel_exit(HSQUIRRELVM vm)
{
tic_machine* machine = getSquirrelMachine(vm);
if (machine->data)
machine->data->exit(machine->data->data);
return 0;
@ -1257,7 +1261,7 @@ static void checkForceExit(HSQUIRRELVM vm, SQInteger type, const SQChar* sourceN
tic_machine* machine = getSquirrelMachine(vm);
tic_tick_data* tick = machine->data;
if(tick->forceExit && tick->forceExit(tick->data))
if(tick && tick->forceExit && tick->forceExit(tick->data))
sq_throwerror(vm, "script execution was interrupted");
}
@ -1332,6 +1336,7 @@ static bool initSquirrel(tic_mem* tic, const char* code)
const SQChar* errorString = "unknown error";
sq_getstring(vm, -1, &errorString);
if (machine->data)
machine->data->error(machine->data->data, errorString);
sq_pop(vm, 2); // error and error string
@ -1367,6 +1372,7 @@ static void callSquirrelTick(tic_mem* tic)
const SQChar* errorString = "unknown error";
sq_getstring(vm, -1, &errorString);
if (machine->data)
machine->data->error(machine->data->data, errorString);
sq_pop(vm, 3); // remove string, error and root table.
}
@ -1374,6 +1380,7 @@ static void callSquirrelTick(tic_mem* tic)
else
{
sq_pop(vm, 1);
if (machine->data)
machine->data->error(machine->data->data, "'function TIC()...' isn't found :(");
}
}
@ -1400,6 +1407,7 @@ static void callSquirrelScanlineName(tic_mem* memory, s32 row, void* data, const
const SQChar* errorString = "unknown error";
sq_getstring(vm, -1, &errorString);
if (machine->data)
machine->data->error(machine->data->data, errorString);
sq_pop(vm, 3); // error string, error and root table
}
@ -1437,6 +1445,7 @@ static void callSquirrelOverline(tic_mem* memory, void* data)
sq_tostring(vm, -1);
const SQChar* errorString = "unknown error";
sq_getstring(vm, -1, &errorString);
if (machine->data)
machine->data->error(machine->data->data, errorString);
sq_pop(vm, 3);
}
@ -1522,6 +1531,14 @@ void evalSquirrel(tic_mem* tic, const char* code) {
tic_machine* machine = (tic_machine*)tic;
HSQUIRRELVM vm = machine->squirrel;
// make sure that the Squirrel interpreter is initialized.
if (vm == NULL)
{
if (!initSquirrel(tic, ""))
return;
vm = machine->squirrel;
}
sq_settop(vm, 0);
if((SQ_FAILED(sq_compilebuffer(vm, code, strlen(code), "squirrel", SQTrue))) ||
@ -1532,9 +1549,11 @@ void evalSquirrel(tic_mem* tic, const char* code) {
sq_tostring(vm, -1);
const SQChar* errorString = "unknown error";
sq_getstring(vm, -1, &errorString);
if (machine->data)
machine->data->error(machine->data->data, errorString);
sq_pop(vm, 3);
}
sq_settop(vm, 0);
}
static const tic_script_config SquirrelSyntaxConfig =