diff options
| author | Simon Robertshaw <simon@hardwired.org.uk> | 2011-05-30 19:11:34 (GMT) |
|---|---|---|
| committer | Simon Robertshaw <simon@hardwired.org.uk> | 2011-05-30 19:11:34 (GMT) |
| commit | b0659e3dd190070fdc8b1b5bb404e411825e205a (patch) | |
| tree | 7353a8e151cdc53de4be6621bd6279a04238a482 | |
| parent | d5f1a4cfd073f87d636e6975c28d42b8a7456840 (diff) | |
| download | powder-b0659e3dd190070fdc8b1b5bb404e411825e205a.zip powder-b0659e3dd190070fdc8b1b5bb404e411825e205a.tar.gz | |
Step code registration, just an example at the moment
| -rw-r--r-- | build/test.lua | 12 | ||||
| -rw-r--r-- | includes/luaconsole.h | 1 | ||||
| -rw-r--r-- | src/luaconsole.c | 13 |
3 files changed, 25 insertions, 1 deletions
diff --git a/build/test.lua b/build/test.lua new file mode 100644 index 0000000..f57f02b --- /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 a9c7eae..cb1bb12 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 d019667..bc6a2cc 100644 --- a/src/luaconsole.c +++ b/src/luaconsole.c @@ -4,6 +4,7 @@ #include <luaconsole.h> 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 |
