From a8115bd45e0d6424aa01bdbf50418acb6366311c Mon Sep 17 00:00:00 2001 From: Julien Danjou Date: Tue, 16 Jun 2009 17:14:48 +0200 Subject: [PATCH] luaobject: ref take index number as argument Signed-off-by: Julien Danjou --- button.c | 2 +- client.c | 6 +++--- common/luaobject.h | 8 +++++--- key.c | 2 +- property.c | 2 +- tag.c | 4 ++-- titlebar.c | 2 +- wibox.c | 4 ++-- widget.c | 2 +- widgets/imagebox.c | 2 +- widgets/textbox.c | 2 +- 11 files changed, 19 insertions(+), 17 deletions(-) diff --git a/button.c b/button.c index 0be4eadd3..5a5c545b2 100644 --- a/button.c +++ b/button.c @@ -102,7 +102,7 @@ luaA_button_array_set(lua_State *L, int idx, button_array_t *buttons) button_array_init(buttons); lua_pushnil(L); while(lua_next(L, idx)) - button_array_append(buttons, button_ref(L)); + button_array_append(buttons, button_ref(L, -1)); } /** Push an array of button as an Lua table onto the stack. diff --git a/client.c b/client.c index 0921f34be..24733f8ae 100644 --- a/client.c +++ b/client.c @@ -459,7 +459,7 @@ client_manage(xcb_window_t w, xcb_get_geometry_reply_t *wgeom, int phys_screen, c = client_new(globalconf.L); /* Push client in client list */ - client_array_push(&globalconf.clients, client_ref(globalconf.L)); + client_array_push(&globalconf.clients, client_ref(globalconf.L, -1)); screen = c->screen = screen_getbycoord(&globalconf.screens.tab[phys_screen], @@ -485,7 +485,7 @@ client_manage(xcb_window_t w, xcb_get_geometry_reply_t *wgeom, int phys_screen, client_setborder(c, wgeom->border_width); if(ewmh_window_icon_get_reply(ewmh_icon_cookie)) - c->icon = image_ref(globalconf.L); + c->icon = image_ref(globalconf.L, -1); /* we honor size hints by default */ c->size_hints_honor = true; @@ -1460,7 +1460,7 @@ luaA_client_newindex(lua_State *L) break; case A_TK_ICON: image_unref(L, c->icon); - c->icon = image_ref(L); + c->icon = image_ref(L, 3); /* execute hook */ hook_property(client, c, "icon"); break; diff --git a/common/luaobject.h b/common/luaobject.h index 0070b4e32..2eb602a64 100644 --- a/common/luaobject.h +++ b/common/luaobject.h @@ -73,12 +73,14 @@ typedef struct } \ \ static inline type * \ - prefix##_ref(lua_State *L) \ + prefix##_ref(lua_State *L, int ud) \ { \ - if(lua_isnil(L, -1)) \ + if(lua_isnil(L, ud)) \ return NULL; \ - type *item = luaL_checkudata(L, -1, lua_type); \ + type *item = luaL_checkudata(L, ud, lua_type); \ + lua_pushvalue(L, ud); \ luaA_ref_array_append(&item->refs, luaL_ref(L, LUA_REGISTRYINDEX)); \ + lua_remove(L, ud); \ return item; \ } \ \ diff --git a/key.c b/key.c index 3c774f59d..6eb46396a 100644 --- a/key.c +++ b/key.c @@ -1066,7 +1066,7 @@ luaA_key_array_set(lua_State *L, int idx, key_array_t *keys) lua_pushnil(L); while(lua_next(L, idx)) - key_array_append(keys, key_ref(L)); + key_array_append(keys, key_ref(L, -1)); } /** Push an array of key as an Lua table onto the stack. diff --git a/property.c b/property.c index 206be214a..c39e7f9f2 100644 --- a/property.c +++ b/property.c @@ -355,7 +355,7 @@ property_handle_net_wm_icon(void *data, { image_unref(globalconf.L, c->icon); if(ewmh_window_icon_from_reply(reply)) - c->icon = image_ref(globalconf.L); + c->icon = image_ref(globalconf.L, -1); /* execute hook */ hook_property(client, c, "icon"); } diff --git a/tag.c b/tag.c index 92984b657..8caf4ce98 100644 --- a/tag.c +++ b/tag.c @@ -90,7 +90,7 @@ tag_append_to_screen(screen_t *s) int phys_screen = screen_virttophys(screen_index); tag->screen = s; - tag_array_append(&s->tags, tag_ref(globalconf.L)); + tag_array_append(&s->tags, tag_ref(globalconf.L, -1)); ewmh_update_net_numbers_of_desktop(phys_screen); ewmh_update_net_desktop_names(phys_screen); ewmh_update_workarea(phys_screen); @@ -145,7 +145,7 @@ tag_remove_from_screen(tag_t *tag) void tag_client(client_t *c) { - tag_t *t = tag_ref(globalconf.L); + tag_t *t = tag_ref(globalconf.L, -1); /* don't tag twice */ if(is_client_tagged(c, t)) diff --git a/titlebar.c b/titlebar.c index 86b061824..1379d58cd 100644 --- a/titlebar.c +++ b/titlebar.c @@ -223,7 +223,7 @@ void titlebar_client_attach(client_t *c) { /* check if we can register the object */ - wibox_t *t = wibox_ref(globalconf.L); + wibox_t *t = wibox_ref(globalconf.L, -1); titlebar_client_detach(c); diff --git a/wibox.c b/wibox.c index 7a4d2b714..eb092b205 100644 --- a/wibox.c +++ b/wibox.c @@ -408,7 +408,7 @@ wibox_attach(screen_t *s) { int phys_screen = screen_virttophys(screen_array_indexof(&globalconf.screens, s)); - wibox_t *wibox = wibox_ref(globalconf.L); + wibox_t *wibox = wibox_ref(globalconf.L, -1); wibox_detach(wibox); @@ -736,7 +736,7 @@ luaA_wibox_newindex(lua_State *L) break; case A_TK_BG_IMAGE: image_unref(L, wibox->bg_image); - wibox->bg_image = image_ref(L); + wibox->bg_image = image_ref(L, 3); wibox->need_update = true; break; case A_TK_ALIGN: diff --git a/widget.c b/widget.c index 5d83a9ca8..831103345 100644 --- a/widget.c +++ b/widget.c @@ -123,7 +123,7 @@ luaA_table2widgets(lua_State *L, widget_node_array_t *widgets) { widget_node_t w; p_clear(&w, 1); - w.widget = widget_ref(L); + w.widget = widget_ref(L, -1); widget_node_array_append(widgets, w); } else diff --git a/widgets/imagebox.c b/widgets/imagebox.c index 00d65e0a8..195218dad 100644 --- a/widgets/imagebox.c +++ b/widgets/imagebox.c @@ -197,7 +197,7 @@ luaA_imagebox_newindex(lua_State *L, awesome_token_t token) case A_TK_IMAGE: image_unref(L, d->image); - d->image = image_ref(L); + d->image = image_ref(L, 3); break; case A_TK_BG: if(lua_isnil(L, 3)) diff --git a/widgets/textbox.c b/widgets/textbox.c index b17285e8f..9fb5f4db1 100644 --- a/widgets/textbox.c +++ b/widgets/textbox.c @@ -297,7 +297,7 @@ luaA_textbox_newindex(lua_State *L, awesome_token_t token) break; case A_TK_BG_IMAGE: image_unref(L, d->bg_image); - d->bg_image = image_ref(L); + d->bg_image = image_ref(L, 3); break; case A_TK_BG: if(lua_isnil(L, 3))