[widget] Add luaA_widget_userdata_new() function

Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
Julien Danjou 2008-05-24 19:58:25 +02:00
parent 834405425e
commit 9d99ff48ae
1 changed files with 14 additions and 16 deletions

View File

@ -153,13 +153,22 @@ widget_invalidate_statusbar_bywidget(widget_t *widget)
} }
} }
static int
luaA_widget_userdata_new(widget_t *widget)
{
widget_t **w;
w = lua_newuserdata(globalconf.L, sizeof(widget_t *));
*w = widget;
widget_ref(w);
return luaA_settype(globalconf.L, "widget");
}
static int static int
luaA_widget_new(lua_State *L) luaA_widget_new(lua_State *L)
{ {
const char *type; const char *type;
widget_t **widget, *w; widget_t *w;
WidgetConstructor *wc; WidgetConstructor *wc;
int objpos;
alignment_t align; alignment_t align;
luaA_checktable(L, 1); luaA_checktable(L, 1);
@ -173,20 +182,13 @@ luaA_widget_new(lua_State *L)
else else
return 0; return 0;
widget = lua_newuserdata(L, sizeof(widget_t *));
objpos = lua_gettop(L);
*widget = w;
/* Set visible by default. */ /* Set visible by default. */
w->isvisible = true; w->isvisible = true;
/* \todo check that the name is unique */ /* \todo check that the name is unique */
(*widget)->name = luaA_name_init(L); w->name = luaA_name_init(L);
widget_ref(widget); return luaA_widget_userdata_new(w);
/* repush obj on top */
lua_pushvalue(L, objpos);
return luaA_settype(L, "widget");
} }
static int static int
@ -298,7 +300,6 @@ static int
luaA_widget_get(lua_State *L) luaA_widget_get(lua_State *L)
{ {
statusbar_t *sb; statusbar_t *sb;
widget_t **wobj;
widget_node_t *widget; widget_node_t *widget;
int i = 1, screen; int i = 1, screen;
bool add = true; bool add = true;
@ -319,13 +320,10 @@ luaA_widget_get(lua_State *L)
if(add) if(add)
{ {
witer = p_new(widget_node_t, 1); witer = p_new(widget_node_t, 1);
wobj = lua_newuserdata(L, sizeof(tag_t *));
witer->widget = *wobj = widget->widget;
widget_ref(&widget->widget);
widget_node_list_push(&wlist, witer); widget_node_list_push(&wlist, witer);
luaA_widget_userdata_new(witer->widget);
/* ref again for the list */ /* ref again for the list */
widget_ref(&widget->widget); widget_ref(&widget->widget);
luaA_settype(L, "widget");
lua_rawseti(L, -2, i++); lua_rawseti(L, -2, i++);
} }
add = true; add = true;