summaryrefslogtreecommitdiffstats
path: root/source/squirrelbindings/SquirrelFunctions.cpp
diff options
context:
space:
mode:
authorlapayo94@gmail.com <lapayo94@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6>2012-07-08 23:01:08 +0200
committerlapayo94@gmail.com <lapayo94@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6>2012-07-08 23:01:08 +0200
commit083228a10dffcaa77b1d0035c29013c6802befd4 (patch)
tree4d8ba1ce8501f044d10135e836e6f956f1b99fa4 /source/squirrelbindings/SquirrelFunctions.cpp
parentAdded a lilypad finisher (diff)
downloadcuberite-083228a10dffcaa77b1d0035c29013c6802befd4.tar
cuberite-083228a10dffcaa77b1d0035c29013c6802befd4.tar.gz
cuberite-083228a10dffcaa77b1d0035c29013c6802befd4.tar.bz2
cuberite-083228a10dffcaa77b1d0035c29013c6802befd4.tar.lz
cuberite-083228a10dffcaa77b1d0035c29013c6802befd4.tar.xz
cuberite-083228a10dffcaa77b1d0035c29013c6802befd4.tar.zst
cuberite-083228a10dffcaa77b1d0035c29013c6802befd4.zip
Diffstat (limited to '')
-rw-r--r--source/squirrelbindings/SquirrelFunctions.cpp65
1 files changed, 65 insertions, 0 deletions
diff --git a/source/squirrelbindings/SquirrelFunctions.cpp b/source/squirrelbindings/SquirrelFunctions.cpp
new file mode 100644
index 000000000..88871369d
--- /dev/null
+++ b/source/squirrelbindings/SquirrelFunctions.cpp
@@ -0,0 +1,65 @@
+
+#include "Globals.h"
+#include "SquirrelFunctions.h"
+#include "SquirrelBindings.h"
+
+static HSQUIRRELVM squirrelvm = NULL;
+
+SQInteger runtimeErrorHandler(HSQUIRRELVM a_VM)
+{
+ const SQChar *sErr = 0;
+ if(sq_gettop(a_VM) >= 1)
+ {
+ if(SQ_SUCCEEDED(sq_getstring(a_VM, 2, &sErr)))
+ {
+ LOGERROR("Squirrel Error: %s", sErr);
+ }
+ else
+ {
+ LOGERROR("Squirrel Error: Unknown Error");
+ }
+ }
+ return 0;
+}
+
+void compilerErrorHandler(HSQUIRRELVM v,
+ const SQChar* a_Desc,
+ const SQChar* a_Source,
+ SQInteger a_Line,
+ SQInteger a_Column)
+{
+
+ LOGERROR("Squirrel Error: %s (%d:%d) %s", a_Source, a_Line, a_Column, a_Desc);
+}
+
+HSQUIRRELVM OpenSquirrelVM()
+{
+ if(!squirrelvm)
+ {
+ squirrelvm = sq_open(1024);
+ Sqrat::DefaultVM::Set(squirrelvm);
+
+ sq_newclosure(squirrelvm, runtimeErrorHandler, 0);
+ sq_seterrorhandler(squirrelvm);
+
+ sq_setcompilererrorhandler(squirrelvm, compilerErrorHandler);
+
+ BindSquirrel(squirrelvm);
+ }
+ return squirrelvm;
+}
+
+void CloseSquirrelVM()
+{
+ if(squirrelvm)
+ {
+ sq_close(squirrelvm);
+ squirrelvm = NULL;
+ }
+}
+
+
+void sqPrint(SQChar * text)
+{
+ LOGINFO("%s", text);
+} \ No newline at end of file