From 5bb431fc4a9f16cebbb67c46012e0245b7c945f2 Mon Sep 17 00:00:00 2001 From: Julien Danjou Date: Tue, 1 Jul 2008 15:27:41 +0200 Subject: [PATCH] widgets: don't tokenize twice Signed-off-by: Julien Danjou --- structs.h | 4 ++-- widget.c | 10 ++++++---- widgets/graph.c | 14 +++++++------- widgets/progressbar.c | 14 ++++++-------- widgets/taglist.c | 15 +++++++-------- widgets/tasklist.c | 18 +++++++++--------- widgets/textbox.c | 14 +++++++------- 7 files changed, 44 insertions(+), 45 deletions(-) diff --git a/structs.h b/structs.h index 9b9e5ce0..3c3dfb0f 100644 --- a/structs.h +++ b/structs.h @@ -100,9 +100,9 @@ struct widget_t /** Draw function */ int (*draw)(draw_context_t *, int, widget_node_t *, int, int, void *); /** Index function */ - int (*index)(lua_State *); + int (*index)(lua_State *, awesome_token_t); /** Newindex function */ - int (*newindex)(lua_State *); + int (*newindex)(lua_State *, awesome_token_t); /** ButtonPressedEvent handler */ void (*button_press)(widget_node_t *, xcb_button_press_event_t *, int, void *, awesome_type_t); /** Alignement */ diff --git a/widget.c b/widget.c index 68cc9cab..5dfd3ee5 100644 --- a/widget.c +++ b/widget.c @@ -383,6 +383,7 @@ luaA_widget_index(lua_State *L) size_t len; widget_t **widget = luaA_checkudata(L, 1, "widget"); const char *buf = luaL_checklstring(L, 2, &len); + awesome_token_t token; lua_getmetatable(L, 1); lua_pushvalue(L, 2); @@ -394,7 +395,7 @@ luaA_widget_index(lua_State *L) } lua_pop(L, 2); - switch(a_tokenize(buf, len)) + switch((token = a_tokenize(buf, len))) { case A_TK_VISIBLE: lua_pushboolean(L, (*widget)->isvisible); @@ -403,7 +404,7 @@ luaA_widget_index(lua_State *L) break; } - return (*widget)->index ? (*widget)->index(L) : 0; + return (*widget)->index ? (*widget)->index(L, token) : 0; } /** Generic widget newindex. @@ -416,8 +417,9 @@ luaA_widget_newindex(lua_State *L) size_t len; widget_t **widget = luaA_checkudata(L, 1, "widget"); const char *buf = luaL_checklstring(L, 2, &len); + awesome_token_t token; - switch(a_tokenize(buf, len)) + switch((token = a_tokenize(buf, len))) { case A_TK_VISIBLE: (*widget)->isvisible = luaA_checkboolean(L, 3); @@ -426,7 +428,7 @@ luaA_widget_newindex(lua_State *L) break; } - return (*widget)->newindex ? (*widget)->newindex(L) : 0; + return (*widget)->newindex ? (*widget)->newindex(L, token) : 0; } const struct luaL_reg awesome_widget_methods[] = diff --git a/widgets/graph.c b/widgets/graph.c index 56c3d3ae..5c80ce3e 100644 --- a/widgets/graph.c +++ b/widgets/graph.c @@ -425,17 +425,16 @@ luaA_graph_plot_data_add(lua_State *L) /** Index function for graph widget. * \param L The Lua VM state. + * \param token The key token. * \return The number of elements pushed on stack. */ static int -luaA_graph_index(lua_State *L) +luaA_graph_index(lua_State *L, awesome_token_t token) { - size_t len; widget_t **widget = luaA_checkudata(L, 1, "widget"); graph_data_t *d = (*widget)->data; - const char *attr = luaL_checklstring(L, 2, &len); - switch(a_tokenize(attr, len)) + switch(token) { case A_TK_PLOT_PROPERTIES_SET: lua_pushcfunction(L, luaA_graph_plot_properties_set); @@ -477,21 +476,22 @@ luaA_graph_index(lua_State *L) /** Newindex function for graph widget. * \param L The Lua VM state. + * \param token The key token. * \return The number of elements pushed on stack. */ static int -luaA_graph_newindex(lua_State *L) +luaA_graph_newindex(lua_State *L, awesome_token_t token) { size_t len; widget_t **widget = luaA_checkudata(L, 1, "widget"); graph_data_t *d = (*widget)->data; - const char *buf, *attr = luaL_checklstring(L, 2, &len); + const char *buf; int width; plot_t *plot; position_t pos; xcolor_t color; - switch(a_tokenize(attr, len)) + switch(token) { case A_TK_HEIGHT: d->height = luaL_checknumber(L, 3); diff --git a/widgets/progressbar.c b/widgets/progressbar.c index c3787339..1ec2a640 100644 --- a/widgets/progressbar.c +++ b/widgets/progressbar.c @@ -519,17 +519,16 @@ luaA_progressbar_bar_data_add(lua_State *L) /** Index function for progressbar. * \param L The Lua VM state. + * \param token The key token. * \return The number of elements pushed on the stack. */ static int -luaA_progressbar_index(lua_State *L) +luaA_progressbar_index(lua_State *L, awesome_token_t token) { - size_t len; widget_t **widget = luaA_checkudata(L, 1, "widget"); progressbar_data_t *d = (*widget)->data; - const char *attr = luaL_checklstring(L, 2, &len); - switch(a_tokenize(attr, len)) + switch(token) { case A_TK_BAR_PROPERTIES_SET: lua_pushcfunction(L, luaA_progressbar_bar_properties_set); @@ -570,17 +569,16 @@ luaA_progressbar_index(lua_State *L) /** Newindex function for progressbar. * \param L The Lua VM state. + * \param token The key token. * \return The number of elements pushed on the stack. */ static int -luaA_progressbar_newindex(lua_State *L) +luaA_progressbar_newindex(lua_State *L, awesome_token_t token) { - size_t len; widget_t **widget = luaA_checkudata(L, 1, "widget"); progressbar_data_t *d = (*widget)->data; - const char *attr = luaL_checklstring(L, 2, &len); - switch(a_tokenize(attr, len)) + switch(token) { case A_TK_GAP: d->gap = luaL_checknumber(L, 3); diff --git a/widgets/taglist.c b/widgets/taglist.c index ea93b0a8..1bdbc407 100644 --- a/widgets/taglist.c +++ b/widgets/taglist.c @@ -291,17 +291,16 @@ taglist_button_press(widget_node_t *w, /** Index function for taglist. * \param L The Lua VM state. + * \param token The key token. * \return The number of elements pushed on stack. */ static int -luaA_taglist_index(lua_State *L) +luaA_taglist_index(lua_State *L, awesome_token_t token) { - size_t len; widget_t **widget = luaA_checkudata(L, 1, "widget"); - const char *attr = luaL_checklstring(L, 2, &len); taglist_data_t *d = (*widget)->data; - switch(a_tokenize(attr, len)) + switch(token) { case A_TK_TEXT_NORMAL: lua_pushstring(L, d->text_normal); @@ -322,17 +321,17 @@ luaA_taglist_index(lua_State *L) /** Newindex function for taglist. * \param L The Lua VM state. + * \param token The key token. * \return The number of elements pushed on stack. */ static int -luaA_taglist_newindex(lua_State *L) +luaA_taglist_newindex(lua_State *L, awesome_token_t token) { - size_t len; widget_t **widget = luaA_checkudata(L, 1, "widget"); - const char *buf, *attr = luaL_checklstring(L, 2, &len); + const char *buf; taglist_data_t *d = (*widget)->data; - switch(a_tokenize(attr, len)) + switch(token) { case A_TK_TEXT_NORMAL: if((buf = luaL_checkstring(L, 3))) diff --git a/widgets/tasklist.c b/widgets/tasklist.c index 81556ac2..43a2f2f1 100644 --- a/widgets/tasklist.c +++ b/widgets/tasklist.c @@ -276,18 +276,17 @@ tasklist_button_press(widget_node_t *w, } /** Index function for tasklist widget. - * \lparam L The Lua VM state. + * \param L The Lua VM state. + * \param token The key token. * \return The number of elements pushed on stack. */ static int -luaA_tasklist_index(lua_State *L) +luaA_tasklist_index(lua_State *L, awesome_token_t token) { - size_t len; widget_t **widget = luaA_checkudata(L, 1, "widget"); tasklist_data_t *d = (*widget)->data; - const char *attr = luaL_checklstring(L, 2, &len); - switch(a_tokenize(attr, len)) + switch(token) { case A_TK_TEXT_NORMAL: lua_pushstring(L, d->text_normal); @@ -323,18 +322,19 @@ luaA_tasklist_index(lua_State *L) } /** Newindex function for tasklist widget. - * \lparam L The Lua VM state. + * \param L The Lua VM state. + * \param token The key token. * \return The number of elements pushed on stack. */ static int -luaA_tasklist_newindex(lua_State *L) +luaA_tasklist_newindex(lua_State *L, awesome_token_t token) { size_t len; widget_t **widget = luaA_checkudata(L, 1, "widget"); tasklist_data_t *d = (*widget)->data; - const char *buf, *attr = luaL_checklstring(L, 2, &len); + const char *buf; - switch(a_tokenize(attr, len)) + switch(token) { case A_TK_TEXT_NORMAL: if((buf = luaL_checkstring(L, 3))) diff --git a/widgets/textbox.c b/widgets/textbox.c index 2a25216a..801f19c6 100644 --- a/widgets/textbox.c +++ b/widgets/textbox.c @@ -96,17 +96,16 @@ textbox_destructor(widget_t *w) /** The __index method for a textbox object. * \param L The Lua VM state. + * \param token The key token. * \return The number of elements pushed on stack. */ static int -luaA_textbox_index(lua_State *L) +luaA_textbox_index(lua_State *L, awesome_token_t token) { - size_t len; widget_t **widget = luaA_checkudata(L, 1, "widget"); - const char *attr = luaL_checklstring(L, 2, &len); textbox_data_t *d = (*widget)->data; - switch(a_tokenize(attr, len)) + switch(token) { case A_TK_TEXT: lua_pushstring(L, d->text); @@ -123,17 +122,18 @@ luaA_textbox_index(lua_State *L) /** The __newindex method for a textbox object. * \param L The Lua VM state. + * \param token The key token. * \return The number of elements pushed on stack. */ static int -luaA_textbox_newindex(lua_State *L) +luaA_textbox_newindex(lua_State *L, awesome_token_t token) { size_t len; widget_t **widget = luaA_checkudata(L, 1, "widget"); - const char *buf, *attr = luaL_checklstring(L, 2, &len); + const char *buf; textbox_data_t *d = (*widget)->data; - switch(a_tokenize(attr, len)) + switch(token) { case A_TK_TEXT: if((buf = luaL_checklstring(L, 3, &len)))