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
71
72
73
74
75
76
77
78
|
#ifdef LUACONSOLE
#include <luaconsole.h>
lua_State *l;
void luacon_open(){
const static struct luaL_reg tptluaapi [] = {
{"test", &luatpt_test},
{"drawtext", &luatpt_drawtext},
{NULL,NULL}
};
l = lua_open();
luaL_openlibs(l);
luaL_openlib(l, "tpt", tptluaapi, 0);
}
int luacon_step(){
//Nothing here yet
return 0;
}
int luacon_keypress(char key){
//Nothing here yet
return 0;
}
int luacon_eval(char *command){
return luaL_dostring (l, command);
}
void luacon_close(){
lua_close(l);
}
int process_command_lua(pixel *vid_buf, char *console, char *console_error)
{
int commandret;
char console2[15];
char console3[15];
char console4[15];
char console5[15];
//sprintf(console_error, "%s", console);
if (console && strcmp(console, "")!=0 && strncmp(console, " ", 1)!=0)
{
sscanf(console,"%14s %14s %14s %14s", console2, console3, console4, console5);
if (strcmp(console2, "quit")==0)
{
return -1;
} else {
commandret = luacon_eval(console);
if (commandret)
strcpy(console_error,"failed to execute code.");
}
}
return 1;
}
//Being TPT interface methods:
int luatpt_test(lua_State* l)
{
int testint = 0;
testint = luaL_optint(l, 1, 0);
printf("Test successful, got %d\n", testint);
return 1;
}
int luatpt_drawtext(lua_State* l)
{
char *string;
int textx, texty, textred, textgreen, textblue, textalpha;
textx = luaL_optint(l, 1, 0);
texty = luaL_optint(l, 2, 0);
string = luaL_optstring(l, 3, 0);
textred = luaL_optint(l, 4, 0);
textgreen = luaL_optint(l, 5, 0);
textblue = luaL_optint(l, 6, 0);
textalpha = luaL_optint(l, 7, 0);
if(vid_buf!=NULL){
drawtext(vid_buf, textx, texty, string, textred, textgreen, textblue, textalpha);
return 0;
}
return -1;
}
#endif
|