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:
Pierre Habouzit 2008-06-28 01:01:11 +02:00 committed by Julien Danjou
parent 843c302e8b
commit 1b6543025c
2 changed files with 7 additions and 31 deletions

View File

@ -14,10 +14,6 @@ focus
image image
left left
line line
mouse_add
mouse_remove
name_get
name_set
on on
plot_data_add plot_data_add
plot_properties_set plot_properties_set
@ -38,7 +34,5 @@ top
topleft topleft
topright topright
true true
visible_get
visible_set
width width
yes yes

View File

@ -417,34 +417,16 @@ static int
luaA_widget_index(lua_State *L) luaA_widget_index(lua_State *L)
{ {
widget_t **widget = luaA_checkudata(L, 1, "widget"); widget_t **widget = luaA_checkudata(L, 1, "widget");
size_t len;
const char *str = luaL_checklstring(L, 2, &len);
switch(a_tokenize(str, len)) lua_getmetatable(L, 1); /* 1 */
{ lua_pushvalue(L, 2); /* 2 */
case A_TK_MOUSE_ADD: lua_rawget(L, -2); /* 2 */
lua_pushcfunction(L, luaA_widget_mouse_add); if (!lua_isnil(L, -1)) {
lua_remove(L, -2); /* 1 */
return 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. /** Generic widget newindex.