From 1c5fc37eefaee39ddb70680e6767d8ce4d3d61e1 Mon Sep 17 00:00:00 2001 From: Julien Danjou Date: Fri, 27 Jun 2008 12:43:39 +0200 Subject: [PATCH] widgets: add newindex support Signed-off-by: Julien Danjou --- structs.h | 2 ++ widget.c | 22 ++++++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/structs.h b/structs.h index c7916735..addcd545 100644 --- a/structs.h +++ b/structs.h @@ -102,6 +102,8 @@ struct widget_t int (*draw)(draw_context_t *, int, widget_node_t *, int, int, void *); /** Index function */ int (*index)(lua_State *); + /** Newindex function */ + int (*newindex)(lua_State *); /** 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 efdd510e..5d59da1e 100644 --- a/widget.c +++ b/widget.c @@ -394,6 +394,7 @@ luaA_widget_visible_set(lua_State *L) /** Get the visible attribute of a widget. * \param L The Lua VM state. + * \return The number of elements pushed on stack. * * \luastack * \lvalue A widget. @@ -407,6 +408,11 @@ luaA_widget_visible_get(lua_State *L) return 1; } + +/** Generic widget index. + * \param L The Lua VM state. + * \return The number of elements pushed on stack. + */ static int luaA_widget_index(lua_State *L) { @@ -441,6 +447,21 @@ luaA_widget_index(lua_State *L) } } +/** Generic widget newindex. + * \param L The Lua VM state. + * \return The number of elements pushed on stack. + */ +static int +luaA_widget_newindex(lua_State *L) +{ + widget_t **widget = luaA_checkudata(L, 1, "widget"); + + if((*widget)->newindex) + return (*widget)->newindex(L); + + return 0; +} + const struct luaL_reg awesome_widget_methods[] = { { "new", luaA_widget_new }, @@ -455,6 +476,7 @@ const struct luaL_reg awesome_widget_meta[] = { "visible_set", luaA_widget_visible_set }, { "visible_get", luaA_widget_visible_get }, { "__index", luaA_widget_index }, + { "__newindex", luaA_widget_newindex }, { "__gc", luaA_widget_gc }, { "__eq", luaA_widget_eq }, { "__tostring", luaA_widget_tostring },