Step code registration, just an example at the moment

This commit is contained in:
Simon Robertshaw 2011-05-30 20:11:34 +01:00
parent d5f1a4cfd0
commit b0659e3dd1
3 changed files with 25 additions and 1 deletions

12
build/test.lua Normal file
View File

@ -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

View File

@ -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

View File

@ -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