summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSimon Robertshaw <simon@hardwired.org.uk>2011-05-30 15:22:39 (GMT)
committer Simon Robertshaw <simon@hardwired.org.uk>2011-05-30 15:22:39 (GMT)
commit79a27c2c90823f1f9212d80c6b2d63cde620855c (patch)
tree04ed2d7542c57446467483447bee6fafea64fbc2 /src
parent5dcc3dbb44f1c721a4adbee3db2dd8b5542e870e (diff)
downloadpowder-79a27c2c90823f1f9212d80c6b2d63cde620855c.zip
powder-79a27c2c90823f1f9212d80c6b2d63cde620855c.tar.gz
Basics for Lua
Diffstat (limited to 'src')
-rw-r--r--src/luaconsole.c61
-rw-r--r--src/main.c29
2 files changed, 90 insertions, 0 deletions
diff --git a/src/luaconsole.c b/src/luaconsole.c
new file mode 100644
index 0000000..4c21613
--- /dev/null
+++ b/src/luaconsole.c
@@ -0,0 +1,61 @@
+#ifdef LUACONSOLE
+#include <luaconsole.h>
+
+lua_State *l;
+void luacon_open(){
+ const static struct luaL_reg tptluaapi [] = {
+ {"test", &luatpt_test},
+ {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;
+}
+
+#endif
diff --git a/src/main.c b/src/main.c
index 41a6c74..c7e325d91 100644
--- a/src/main.c
+++ b/src/main.c
@@ -58,6 +58,9 @@
#ifdef PYCONSOLE
#include "pyconsole.h"
#endif
+#ifdef LUACONSOLE
+#include "luaconsole.h"
+#endif
pixel *vid_buf;
@@ -1560,6 +1563,9 @@ int main(int argc, char *argv[])
fmt.callback = mixaudio;
fmt.userdata = NULL;
+#ifdef LUACONSOLE
+ luacon_open();
+#endif
#ifdef PYCONSOLE
//initialise python console
Py_Initialize();
@@ -2366,6 +2372,9 @@ int main(int argc, char *argv[])
}
}
}
+#ifdef LUACONSOLE
+ luacon_keypress(sdl_key);
+#endif
#ifdef PYCONSOLE
if (pyready==1 && pygood==1)
if (pkey!=NULL && sdl_key!=NULL)
@@ -3331,6 +3340,20 @@ int main(int argc, char *argv[])
if (!console_mode)
hud_enable = 1;
}
+#elif defined LUACONSOLE
+ char *console;
+ sys_pause = 1;
+ console = console_ui(vid_buf, console_error, console_more);
+ console = mystrdup(console);
+ strcpy(console_error,"");
+ if (process_command_lua(vid_buf, console, console_error)==-1)
+ {
+ free(console);
+ break;
+ }
+ free(console);
+ if (!console_mode)
+ hud_enable = 1;
#else
char *console;
sys_pause = 1;
@@ -3349,6 +3372,9 @@ int main(int argc, char *argv[])
}
//execute python step hook
+#ifdef LUACONSOLE
+ luacon_step();
+#endif
#ifdef PYCONSOLE
if (pyready==1 && pygood==1)
if (pstep!=NULL)
@@ -3384,6 +3410,9 @@ int main(int argc, char *argv[])
}
SDL_CloseAudio();
http_done();
+#ifdef LUACONSOLE
+ luacon_close();
+#endif
#ifdef PYCONSOLE
PyRun_SimpleString("import os,tempfile,os.path\ntry:\n os.remove(os.path.join(tempfile.gettempdir(),'tpt_console.py'))\nexcept:\n pass");