From b0659e3dd190070fdc8b1b5bb404e411825e205a Mon Sep 17 00:00:00 2001 From: Simon Robertshaw Date: Mon, 30 May 2011 20:11:34 +0100 Subject: [PATCH] Step code registration, just an example at the moment --- build/test.lua | 12 ++++++++++++ includes/luaconsole.h | 1 + src/luaconsole.c | 13 ++++++++++++- 3 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 build/test.lua diff --git a/build/test.lua b/build/test.lua new file mode 100644 index 000000000..f57f02b8d --- /dev/null +++ b/build/test.lua @@ -0,0 +1,12 @@ +tpt.register_step("do_step") +numberthing = 0 +increment = 2 +function do_step() + numberthing = numberthing + increment; + if numberthing >= 400 then + increment = -2 + elseif numberthing < 4 then + increment = 2 + end + tpt.drawtext(numberthing, 50, "Oh my god, this is amazing", 255, 255, 255, 255) +end diff --git a/includes/luaconsole.h b/includes/luaconsole.h index a9c7eaeff..cb1bb12d0 100644 --- a/includes/luaconsole.h +++ b/includes/luaconsole.h @@ -33,4 +33,5 @@ int luatpt_textwidth(lua_State* l); int luatpt_get_name(lua_State* l); int luatpt_set_shortcuts(lua_State* l); int luatpt_delete(lua_State* l); +int luatpt_register_step(lua_State* l); #endif diff --git a/src/luaconsole.c b/src/luaconsole.c index d01966716..bc6a2cc9a 100644 --- a/src/luaconsole.c +++ b/src/luaconsole.c @@ -4,6 +4,7 @@ #include lua_State *l; +char *step_function = ""; void luacon_open(){ const static struct luaL_reg tptluaapi [] = { {"test", &luatpt_test}, @@ -25,6 +26,7 @@ void luacon_open(){ {"get_name", &luatpt_get_name}, {"set_shortcuts", &luatpt_set_shortcuts}, {"delete", &luatpt_delete}, + {"register_step", &luatpt_register_step}, {NULL,NULL} }; @@ -33,7 +35,10 @@ void luacon_open(){ luaL_openlib(l, "tpt", tptluaapi, 0); } int luacon_step(){ - //Nothing here yet + if(step_function && step_function[0]){ + lua_getfield(l, LUA_GLOBALSINDEX, step_function); + lua_call(l, 0, 0); + } return 0; } int luacon_keypress(char key){ @@ -368,4 +373,10 @@ int luatpt_delete(lua_State* l) //TODO: Implement luatpt_delete (Delete particle) return -1; } + +int luatpt_register_step(lua_State* l) +{ + step_function = luaL_optstring(l, 1, ""); + return 0; +} #endif