From 85c7bf07c941c0da605e7aa08bb17f0137071183 Mon Sep 17 00:00:00 2001 From: Julien Danjou Date: Sun, 26 Oct 2008 16:15:49 +0100 Subject: [PATCH] luaa: merge tostring() with DO_LUA_NEW Also use the same format as standard Lua for tostring output. Signed-off-by: Julien Danjou --- client.c | 29 +---------------------------- image.c | 15 --------------- keybinding.c | 11 ----------- luaa.h | 7 +++++++ mouse.c | 14 -------------- tag.c | 15 --------------- wibox.c | 15 --------------- widget.c | 14 -------------- 8 files changed, 8 insertions(+), 112 deletions(-) diff --git a/client.c b/client.c index dfb8b4ec..c982e816 100644 --- a/client.c +++ b/client.c @@ -35,20 +35,7 @@ extern awesome_t globalconf; -/** Create a new client userdata. - * \param L The Lua VM state. - * \param p A client pointer. - * \param The number of elements pushed on the stack. - */ -int -luaA_client_userdata_new(lua_State *L, client_t *p) -{ - client_t **pp = lua_newuserdata(L, sizeof(client_t *)); - *pp = p; - client_ref(pp); - return luaA_settype(L, "client"); -} - +DO_LUA_NEW(extern, client_t, client, "client", client_ref) DO_LUA_EQ(client_t, client, "client") DO_LUA_GC(client_t, client, "client", client_unref) @@ -1129,20 +1116,6 @@ luaA_client_redraw(lua_State *L) return 0; } -/** Return a formated string for a client. - * \param L The Lua VM state. - * \luastack - * \lvalue A client. - * \lreturn A string. - */ -static int -luaA_client_tostring(lua_State *L) -{ - client_t **p = luaA_checkudata(L, 1, "client"); - lua_pushfstring(L, "[client udata(%p) name(%s)]", *p, (*p)->name); - return 1; -} - /** Stop managing a client. * \param L The Lua VM state. * \return The number of elements pushed on stack. diff --git a/image.c b/image.c index 85122ecb..5c6f4e31 100644 --- a/image.c +++ b/image.c @@ -323,21 +323,6 @@ luaA_image_index(lua_State *L) return 1; } -/** Return a formated string for an image. - * \param L The Lua VM state. - * \luastack - * \lvalue An image. - * \lreturn A string. - */ -static int -luaA_image_tostring(lua_State *L) -{ - image_t **p = luaA_checkudata(L, 1, "image"); - lua_pushfstring(L, "[image udata(%p) width(%d) height(%d)]", *p, - (*p)->width, (*p)->height); - return 1; -} - const struct luaL_reg awesome_image_methods[] = { { "__call", luaA_image_new }, diff --git a/keybinding.c b/keybinding.c index 7ed99bf1..a53cce5c 100644 --- a/keybinding.c +++ b/keybinding.c @@ -383,17 +383,6 @@ luaA_keybinding_remove(lua_State *L) return 0; } -/** Convert a keybinding to a printable string. - * \return A string. - */ -static int -luaA_keybinding_tostring(lua_State *L) -{ - keybinding_t **p = luaA_checkudata(L, 1, "keybinding"); - lua_pushfstring(L, "[keybinding udata(%p)]", *p); - return 1; -} - const struct luaL_reg awesome_keybinding_methods[] = { { "__call", luaA_keybinding_new }, diff --git a/luaa.h b/luaa.h index 6e8238c3..515cd89a 100644 --- a/luaa.h +++ b/luaa.h @@ -47,6 +47,13 @@ typedef int luaA_ref; *pp = p; \ type_ref(pp); \ return luaA_settype(L, lua_type); \ + } \ + static int \ + luaA_##prefix##_tostring(lua_State *L) \ + { \ + type **p = luaA_checkudata(L, 1, lua_type); \ + lua_pushfstring(L, lua_type ": %p", *p); \ + return 1; \ } #define DO_LUA_GC(type, prefix, lua_type, type_unref) \ diff --git a/mouse.c b/mouse.c index 56e54c21..c77396c3 100644 --- a/mouse.c +++ b/mouse.c @@ -1119,20 +1119,6 @@ luaA_button_new(lua_State *L) return luaA_button_userdata_new(L, button); } -/** Return a formated string for a button. - * \param L The Lua VM state. - * \luastack - * \lvalue A button. - * \lreturn A string. - */ -static int -luaA_button_tostring(lua_State *L) -{ - button_t **p = luaA_checkudata(L, 1, "button"); - lua_pushfstring(L, "[button udata(%p)]", *p); - return 1; -} - /** Set a button array with a Lua table. * \param L The Lua VM state. * \param idx The index of the Lua table. diff --git a/tag.c b/tag.c index 3d09f6eb..9de30679 100644 --- a/tag.c +++ b/tag.c @@ -230,21 +230,6 @@ tag_view_only_byindex(int screen, int dindex) tag_view_only(tags->tab[dindex]); } -/** Convert a tag to a printable string. - * \param L The Lua VM state. - * - * \luastack - * \lvalue A tag. - * \lreturn A string. - */ -static int -luaA_tag_tostring(lua_State *L) -{ - tag_t **p = luaA_checkudata(L, 1, "tag"); - lua_pushfstring(L, "[tag udata(%p) name(%s)]", *p, (*p)->name); - return 1; -} - /** Create a new tag. * \param L The Lua VM state. * diff --git a/wibox.c b/wibox.c index 4cf0698b..402ac163 100644 --- a/wibox.c +++ b/wibox.c @@ -605,21 +605,6 @@ wibox_attach(wibox_t *wibox, screen_t *s) wibox->need_update = true; } - -/** Convert a wibox to a printable string. - * \param L The Lua VM state. - * - * \luastack - * \lvalue A wibox. - */ -static int -luaA_wibox_tostring(lua_State *L) -{ - wibox_t **p = luaA_checkudata(L, 1, "wibox"); - lua_pushfstring(L, "[wibox udata(%p)]", *p); - return 1; -} - /** Create a new wibox. * \param L The Lua VM state. * diff --git a/widget.c b/widget.c index c77a8176..3d04da26 100644 --- a/widget.c +++ b/widget.c @@ -418,20 +418,6 @@ luaA_widget_buttons(lua_State *L) return luaA_button_array_get(L, buttons); } -/** Convert a widget into a printable string. - * \param L The Lua VM state. - * - * \luastack - * \lvalue A widget. - */ -static int -luaA_widget_tostring(lua_State *L) -{ - widget_t **p = luaA_checkudata(L, 1, "widget"); - lua_pushfstring(L, "[widget udata(%p) name(%s)]", *p, (*p)->name); - return 1; -} - /** Generic widget. * \param L The Lua VM state. * \return The number of elements pushed on stack.