lua: check for ref value before getting them

Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
Julien Danjou 2008-10-21 10:35:23 +02:00
parent 862fe193ee
commit a5640330d9
3 changed files with 27 additions and 9 deletions

10
mouse.c
View File

@ -1186,10 +1186,16 @@ luaA_button_index(lua_State *L)
switch(a_tokenize(attr, len))
{
case A_TK_PRESS:
lua_rawgeti(L, LUA_REGISTRYINDEX, (*button)->press);
if((*button)->press != LUA_REFNIL)
lua_rawgeti(L, LUA_REGISTRYINDEX, (*button)->press);
else
lua_pushnil(L);
break;
case A_TK_RELEASE:
lua_rawgeti(L, LUA_REGISTRYINDEX, (*button)->release);
if((*button)->release != LUA_REFNIL)
lua_rawgeti(L, LUA_REGISTRYINDEX, (*button)->release);
else
lua_pushnil(L);
break;
case A_TK_BUTTON:
/* works fine, but not *really* neat */

16
wibox.c
View File

@ -712,9 +712,12 @@ static bool
luaA_wibox_hasitem(lua_State *L, wibox_t *wibox, const void *item)
{
bool ret = false;
lua_rawgeti(globalconf.L, LUA_REGISTRYINDEX, wibox->widgets_table);
if(lua_topointer(L, -1) == item || luaA_hasitem(L, item))
ret = true;
if(wibox->widgets_table != LUA_REFNIL)
{
lua_rawgeti(globalconf.L, LUA_REGISTRYINDEX, wibox->widgets_table);
if(lua_topointer(L, -1) == item || luaA_hasitem(L, item))
ret = true;
}
return ret;
}
@ -814,8 +817,11 @@ luaA_wibox_index(lua_State *L)
lua_pushstring(L, orientation_tostr((*wibox)->sw.orientation));
break;
case A_TK_WIDGETS:
lua_rawgeti(L, LUA_REGISTRYINDEX, (*wibox)->widgets_table);
break;
if((*wibox)->widgets_table != LUA_REFNIL)
lua_rawgeti(L, LUA_REGISTRYINDEX, (*wibox)->widgets_table);
else
lua_pushnil(L);
break;
default:
return 0;
}

View File

@ -397,10 +397,16 @@ luaA_widget_index(lua_State *L)
lua_pushstring(L, (*widget)->name);
return 1;
case A_TK_MOUSE_ENTER:
lua_rawgeti(L, LUA_REGISTRYINDEX, (*widget)->mouse_enter);
if((*widget)->mouse_enter != LUA_REFNIL)
lua_rawgeti(L, LUA_REGISTRYINDEX, (*widget)->mouse_enter);
else
return 0;
return 1;
case A_TK_MOUSE_LEAVE:
lua_rawgeti(L, LUA_REGISTRYINDEX, (*widget)->mouse_leave);
if((*widget)->mouse_leave != LUA_REFNIL)
lua_rawgeti(L, LUA_REGISTRYINDEX, (*widget)->mouse_leave);
else
return 0;
return 1;
default:
break;