Fix error in element_func where function was being read as the last parameter

This commit is contained in:
Simon Robertshaw 2011-12-09 11:53:19 +00:00
parent d5f58d995e
commit 9dcdccc066

View File

@ -172,8 +172,11 @@ int luacon_partread(lua_State* l){
lua_pop(l, 1); lua_pop(l, 1);
if(i < 0 || i >= PT_NUM || offset==-1) if(i < 0 || i >= NPART || offset==-1)
{ {
if(i < 0 || i >= NPART)
return luaL_error(l, "Out of range");
else
return luaL_error(l, "Invalid property"); return luaL_error(l, "Invalid property");
} }
switch(format) switch(format)
@ -207,8 +210,11 @@ int luacon_partwrite(lua_State* l){
lua_pop(l, 1); lua_pop(l, 1);
if(i < 0 || i >= PT_NUM || offset==-1) if(i < 0 || i >= NPART || offset==-1)
{ {
if(i < 0 || i >= NPART)
return luaL_error(l, "Out of range");
else
return luaL_error(l, "Invalid property"); return luaL_error(l, "Invalid property");
} }
switch(format) switch(format)
@ -626,7 +632,9 @@ int luatpt_element_func(lua_State *l)
{ {
int element = luaL_optint(l, 2, 0); int element = luaL_optint(l, 2, 0);
int replace = luaL_optint(l, 3, 0); int replace = luaL_optint(l, 3, 0);
int function = luaL_ref(l, LUA_REGISTRYINDEX); int function;
lua_pushvalue(l, 1);
function = luaL_ref(l, LUA_REGISTRYINDEX);
if(element > 0 && element < PT_NUM) if(element > 0 && element < PT_NUM)
{ {
lua_el_func[element] = function; lua_el_func[element] = function;