summaryrefslogtreecommitdiffstats
path: root/source/squirrelbindings/SquirrelFunctions.cpp
blob: b6410ad2ef949bf83d5c02cdbaea7afe5b804314 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70

#include "Globals.h"
#include "SquirrelFunctions.h"
#include "SquirrelBindings.h"


#ifdef USE_SQUIRREL

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);
}

#endif