From 4e4a7d2703c4f04adab387e9973eea7c6b91e738 Mon Sep 17 00:00:00 2001 From: Julien Danjou Date: Sat, 24 May 2008 08:40:41 +0200 Subject: [PATCH] [tag] Add luaA_tag_userdata_new() function Signed-off-by: Julien Danjou --- tag.c | 30 ++++++++++++++++-------------- tag.h | 1 + widgets/taglist.c | 17 ++++------------- 3 files changed, 21 insertions(+), 27 deletions(-) diff --git a/tag.c b/tag.c index 117abbc5..35461bd7 100644 --- a/tag.c +++ b/tag.c @@ -77,8 +77,6 @@ tag_new(const char *name, layout_t *layout, double mwfact, int nmaster, int ncol if((tag->ncol = ncol) < 1) tag->ncol = 1; - tag_ref(&tag); - return tag; } @@ -268,7 +266,7 @@ static int luaA_tag_get(lua_State *L) { int screen = luaL_checknumber(L, 1) - 1; - tag_t *tag, **tobj; + tag_t *tag; int i = 1; luaA_checkscreen(screen); @@ -277,10 +275,7 @@ luaA_tag_get(lua_State *L) for(tag = globalconf.screens[screen].tags; tag; tag = tag->next) { - tobj = lua_newuserdata(L, sizeof(tag_t *)); - *tobj = tag; - tag_ref(&tag); - luaA_settype(L, "tag"); + luaA_tag_userdata_new(tag); lua_rawseti(L, -2, i++); } @@ -294,7 +289,7 @@ luaA_tag_get(lua_State *L) static int luaA_tag_new(lua_State *L) { - tag_t **tag; + tag_t *tag; int ncol, nmaster; const char *name, *lay; double mwfact; @@ -310,13 +305,11 @@ luaA_tag_new(lua_State *L) layout = name_func_lookup(lay, LayoutList); - tag = lua_newuserdata(L, sizeof(tag_t *)); + tag = tag_new(name, + layout, + mwfact, nmaster, ncol); - *tag = tag_new(name, - layout, - mwfact, nmaster, ncol); - - return luaA_settype(L, "tag"); + return luaA_tag_userdata_new(tag); } static int @@ -462,6 +455,15 @@ luaA_tag_layout_set(lua_State *L) } +int +luaA_tag_userdata_new(tag_t *t) +{ + tag_t **lt = lua_newuserdata(globalconf.L, sizeof(tag_t *)); + *lt = t; + tag_ref(lt); + return luaA_settype(globalconf.L, "tag"); +} + const struct luaL_reg awesome_tag_methods[] = { { "new", luaA_tag_new }, diff --git a/tag.h b/tag.h index 346be636..3e549072 100644 --- a/tag.h +++ b/tag.h @@ -45,6 +45,7 @@ bool is_client_tagged(client_t *, tag_t *); void tag_client_with_current_selected(client_t *); void tag_view_only_byindex(int, int); void tag_append_to_screen(tag_t *, int); +int luaA_tag_userdata_new(tag_t *); DO_RCNT(tag_t, tag, tag_delete) DO_SLIST(tag_t, tag, tag_delete) diff --git a/widgets/taglist.c b/widgets/taglist.c index 0563b76a..72c6f5f9 100644 --- a/widgets/taglist.c +++ b/widgets/taglist.c @@ -196,7 +196,7 @@ taglist_button_press(widget_node_t *w, statusbar_t *statusbar, taglist_data_t *data = w->widget->data; taglist_drawn_area_t *tda; area_t *area; - tag_t *tag, **ltag; + tag_t *tag; /* Find the good drawn area list */ for(tda = data->drawn_area; tda && tda->statusbar != statusbar; tda = tda->next); @@ -211,10 +211,7 @@ taglist_button_press(widget_node_t *w, statusbar_t *statusbar, if(ev->event_x >= AREA_LEFT(*area) && ev->event_x < AREA_RIGHT(*area)) { - ltag = lua_newuserdata(globalconf.L, sizeof(tag_t *)); - luaA_settype(globalconf.L, "tag"); - *ltag = tag; - tag_ref(ltag); + luaA_tag_userdata_new(tag); luaA_dofunction(globalconf.L, b->fct, 1); } break; @@ -223,10 +220,7 @@ taglist_button_press(widget_node_t *w, statusbar_t *statusbar, if(ev->event_y >= AREA_LEFT(*area) && ev->event_y < AREA_RIGHT(*area)) { - ltag = lua_newuserdata(globalconf.L, sizeof(tag_t *)); - luaA_settype(globalconf.L, "tag"); - *ltag = tag; - tag_ref(ltag); + luaA_tag_userdata_new(tag); luaA_dofunction(globalconf.L, b->fct, 1); } break; @@ -235,10 +229,7 @@ taglist_button_press(widget_node_t *w, statusbar_t *statusbar, if(statusbar->width - ev->event_y >= AREA_LEFT(*area) && statusbar->width - ev->event_y < AREA_RIGHT(*area)) { - ltag = lua_newuserdata(globalconf.L, sizeof(tag_t *)); - luaA_settype(globalconf.L, "tag"); - *ltag = tag; - tag_ref(ltag); + luaA_tag_userdata_new(tag); luaA_dofunction(globalconf.L, b->fct, 1); } break;