summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorjacksonmj <mj-pt@jacksonmj.co.uk>2011-06-05 20:19:19 (GMT)
committer Simon Robertshaw <simon@hardwired.org.uk>2011-06-08 11:48:28 (GMT)
commitb3e0085606c87052fddf2f0e25ba8a596a384a74 (patch)
treee1dfba2eefb7dfbf4c72b76a827b0c45a65d77c8 /src
parent1144e3e2d7ac48baee8a12b217df8f2cdbb5480e (diff)
downloadpowder-b3e0085606c87052fddf2f0e25ba8a596a384a74.zip
powder-b3e0085606c87052fddf2f0e25ba8a596a384a74.tar.gz
Make step function registration work properly
Diffstat (limited to 'src')
-rw-r--r--src/luaconsole.c37
1 files changed, 29 insertions, 8 deletions
diff --git a/src/luaconsole.c b/src/luaconsole.c
index 0109f9f..c362e34 100644
--- a/src/luaconsole.c
+++ b/src/luaconsole.c
@@ -53,9 +53,10 @@ int luacon_step(int mx, int my, int mb, int mbq, char key){
if(step_functions[i]){
lua_rawgeti(l, LUA_REGISTRYINDEX, step_functions[i]);
callret = lua_pcall(l, 0, 1, 0);
- if (!callret)
+ if (callret)
{
- // failed, TODO: error reporting
+ // failed, TODO: better error reporting
+ printf("%s\n",luacon_geterror());
}
if(lua_isboolean(l, -1)){
tempb = lua_toboolean(l, -1);
@@ -660,26 +661,46 @@ int luatpt_delete(lua_State* l)
int luatpt_register_step(lua_State* l)
{
- int ref, i;
+ int ref, i, ifree = -1;
if(lua_isfunction(l, 1)){
for(i = 0; i<6; i++){
if(!step_functions[i]){
- ref = luaL_ref(l, LUA_REGISTRYINDEX);
- step_functions[i] = ref;
- break;
- } else { //Supposed to prevent the registration of 2 functions, but this isn't working TODO: FIX!
+ if (ifree<0) ifree = i;
+ } else {
lua_rawgeti(l, LUA_REGISTRYINDEX, step_functions[i]);
if(lua_equal(l, 1, lua_gettop(l))){
+ lua_pop(l, 1);
return luaL_error(l, "Function already registered");
}
+ lua_pop(l, 1);
}
}
+ if (ifree>=0)
+ {
+ ref = luaL_ref(l, LUA_REGISTRYINDEX);
+ step_functions[ifree] = ref;
+ return 0;
+ }
+ else return luaL_error(l, "Step function limit reached");
}
return 0;
}
int luatpt_unregister_step(lua_State* l)
{
- //step_function = luaL_optstring(l, 1, "");
+ int i;
+ if(lua_isfunction(l, 1)){
+ for(i = 0; i<6; i++){
+ if (step_functions[i]){
+ lua_rawgeti(l, LUA_REGISTRYINDEX, step_functions[i]);
+ if(lua_equal(l, 1, lua_gettop(l))){
+ lua_pop(l, 1);
+ luaL_unref(l, LUA_REGISTRYINDEX, step_functions[i]);
+ step_functions[i] = 0;
+ }
+ else lua_pop(l, 1);
+ }
+ }
+ }
return 0;
}
#endif