From a5640330d95ed1ca0393844563f75a79d5368fbf Mon Sep 17 00:00:00 2001 From: Julien Danjou Date: Tue, 21 Oct 2008 10:35:23 +0200 Subject: [PATCH] lua: check for ref value before getting them Signed-off-by: Julien Danjou --- mouse.c | 10 ++++++++-- wibox.c | 16 +++++++++++----- widget.c | 10 ++++++++-- 3 files changed, 27 insertions(+), 9 deletions(-) diff --git a/mouse.c b/mouse.c index c80c4255e..4987b345e 100644 --- a/mouse.c +++ b/mouse.c @@ -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 */ diff --git a/wibox.c b/wibox.c index 5ec42d6f5..0321054bb 100644 --- a/wibox.c +++ b/wibox.c @@ -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; } diff --git a/widget.c b/widget.c index c8ce6a42a..27daf95d8 100644 --- a/widget.c +++ b/widget.c @@ -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;