--- a/src/ai/squirrel/squirrel.cpp Tue Mar 13 22:39:41 2007 +0000
+++ b/src/ai/squirrel/squirrel.cpp Tue Mar 13 22:55:44 2007 +0000
@@ -11,7 +11,7 @@
/**
* Here we handle errors that come from squirrel.
*/
-static void Squirrel_PrintError(HSQUIRRELVM vm, const SQChar *desc, const SQChar *source, SQInteger line, SQInteger column)
+static void Squirrel_CompileError(HSQUIRRELVM vm, const SQChar *desc, const SQChar *source, SQInteger line, SQInteger column)
{
#ifdef _SQ64
printf("Error %s:%ld/%ld: %s\n", source, line, column, desc);
@@ -21,6 +21,24 @@
}
/**
+ * Here we handle run-time errors that come from squirrel.
+ */
+static SQInteger Squirrel_RunError(HSQUIRRELVM vm)
+{
+ const SQChar *sErr = 0;
+
+ if (sq_gettop(vm) >= 1) {
+ if (SQ_SUCCEEDED(sq_getstring(vm, -1, &sErr))) {
+ printf("%s\n", sErr);
+ } else {
+ printf("Unknown error\n");
+ }
+ }
+
+ return 0;
+}
+
+/**
* Here we handle 'print' command within squirrel script.
*/
static void Squirrel_PrintFunc(HSQUIRRELVM vm, const SQChar *s, ...)
@@ -39,12 +57,14 @@
this->vm = sq_open(1024);
/* Handle compile-errors ourself, so we can display it nicely */
- sq_seterrorhandler(this->vm);
- sq_setcompilererrorhandler(this->vm, Squirrel_PrintError);
+ sq_setcompilererrorhandler(this->vm, Squirrel_CompileError);
sq_notifyallexceptions(this->vm, SQTrue);
/* Set a good print-function */
sq_setprintfunc(this->vm, Squirrel_PrintFunc);
+ sq_newclosure(this->vm, &Squirrel_RunError, 0);
+ sq_seterrorhandler(this->vm);
+
/* TODO -- This is ugly! */
strcpy(filename, "ai/");
strcat(filename, script_dir);