Don't be silly and use our metatable rather than duplicating the effort.
Signed-off-by: Pierre Habouzit <madcoder@debian.org> Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
parent
843c302e8b
commit
1b6543025c
|
@ -14,10 +14,6 @@ focus
|
|||
image
|
||||
left
|
||||
line
|
||||
mouse_add
|
||||
mouse_remove
|
||||
name_get
|
||||
name_set
|
||||
on
|
||||
plot_data_add
|
||||
plot_properties_set
|
||||
|
@ -38,7 +34,5 @@ top
|
|||
topleft
|
||||
topright
|
||||
true
|
||||
visible_get
|
||||
visible_set
|
||||
width
|
||||
yes
|
||||
|
|
32
widget.c
32
widget.c
|
@ -417,34 +417,16 @@ static int
|
|||
luaA_widget_index(lua_State *L)
|
||||
{
|
||||
widget_t **widget = luaA_checkudata(L, 1, "widget");
|
||||
size_t len;
|
||||
const char *str = luaL_checklstring(L, 2, &len);
|
||||
|
||||
switch(a_tokenize(str, len))
|
||||
{
|
||||
case A_TK_MOUSE_ADD:
|
||||
lua_pushcfunction(L, luaA_widget_mouse_add);
|
||||
lua_getmetatable(L, 1); /* 1 */
|
||||
lua_pushvalue(L, 2); /* 2 */
|
||||
lua_rawget(L, -2); /* 2 */
|
||||
if (!lua_isnil(L, -1)) {
|
||||
lua_remove(L, -2); /* 1 */
|
||||
return 1;
|
||||
case A_TK_MOUSE_REMOVE:
|
||||
lua_pushcfunction(L, luaA_widget_mouse_remove);
|
||||
return 1;
|
||||
case A_TK_NAME_SET:
|
||||
lua_pushcfunction(L, luaA_widget_name_set);
|
||||
return 1;
|
||||
case A_TK_NAME_GET:
|
||||
lua_pushcfunction(L, luaA_widget_name_get);
|
||||
return 1;
|
||||
case A_TK_VISIBLE_SET:
|
||||
lua_pushcfunction(L, luaA_widget_visible_set);
|
||||
return 1;
|
||||
case A_TK_VISIBLE_GET:
|
||||
lua_pushcfunction(L, luaA_widget_visible_get);
|
||||
return 1;
|
||||
default:
|
||||
if((*widget)->index)
|
||||
return (*widget)->index(L);
|
||||
return 0;
|
||||
}
|
||||
lua_pop(L, 2);
|
||||
return (*widget)->index ? (*widget)->index(L) : 0;
|
||||
}
|
||||
|
||||
/** Generic widget newindex.
|
||||
|
|
Loading…
Reference in New Issue