From 1b6543025cb231ddc4b6ce97c5ac19e9d2b4d232 Mon Sep 17 00:00:00 2001 From: Pierre Habouzit Date: Sat, 28 Jun 2008 01:01:11 +0200 Subject: [PATCH] Don't be silly and use our metatable rather than duplicating the effort. Signed-off-by: Pierre Habouzit Signed-off-by: Julien Danjou --- common/tokenize.gperf | 6 ------ widget.c | 32 +++++++------------------------- 2 files changed, 7 insertions(+), 31 deletions(-) diff --git a/common/tokenize.gperf b/common/tokenize.gperf index 1b229655d..bbeb53074 100644 --- a/common/tokenize.gperf +++ b/common/tokenize.gperf @@ -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 diff --git a/widget.c b/widget.c index 5d59da1e9..a34b3d5e6 100644 --- a/widget.c +++ b/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.