From 047d04d438214425e48b2ffb3f34fb0e2ca7fb82 Mon Sep 17 00:00:00 2001 From: Julien Danjou Date: Wed, 29 Jul 2009 15:32:55 +0200 Subject: [PATCH] luaobject: import __tostring as object meta function Signed-off-by: Julien Danjou --- button.c | 5 +---- client.c | 5 +---- common/luaobject.h | 10 +++++++++- image.c | 5 +---- key.c | 5 +---- tag.c | 5 +---- wibox.c | 5 +---- widget.c | 5 +---- 8 files changed, 16 insertions(+), 29 deletions(-) diff --git a/button.c b/button.c index 359e9ce1..d96f3c0a 100644 --- a/button.c +++ b/button.c @@ -23,8 +23,6 @@ #include "common/tokenize.h" -DO_LUA_TOSTRING(button_t, button, "button") - /** Create a new mouse button bindings. * \param L The Lua VM state. * \return The number of elements pushed on stack. @@ -150,11 +148,10 @@ const struct luaL_reg awesome_button_methods[] = }; const struct luaL_reg awesome_button_meta[] = { - LUA_OBJECT_META + LUA_OBJECT_META(button) { "__index", luaA_button_index }, { "__newindex", luaA_button_newindex }, { "__gc", luaA_object_gc }, - { "__tostring", luaA_button_tostring }, { NULL, NULL } }; diff --git a/client.c b/client.c index a83ec847..d05da3d1 100644 --- a/client.c +++ b/client.c @@ -32,8 +32,6 @@ #include "common/atoms.h" #include "common/xutil.h" -DO_LUA_TOSTRING(client_t, client, "client") - client_t * luaA_client_checkudata(lua_State *L, int ud) { @@ -1964,7 +1962,7 @@ const struct luaL_reg awesome_client_methods[] = }; const struct luaL_reg awesome_client_meta[] = { - LUA_OBJECT_META + LUA_OBJECT_META(client) { "isvisible", luaA_client_isvisible }, { "geometry", luaA_client_geometry }, { "struts", luaA_client_struts }, @@ -1978,7 +1976,6 @@ const struct luaL_reg awesome_client_meta[] = { "__index", luaA_client_index }, { "__newindex", luaA_client_newindex }, { "__gc", luaA_client_gc }, - { "__tostring", luaA_client_tostring }, { NULL, NULL } }; diff --git a/common/luaobject.h b/common/luaobject.h index db5a83b2..faa37944 100644 --- a/common/luaobject.h +++ b/common/luaobject.h @@ -191,6 +191,13 @@ int luaA_object_emit_signal_simple(lua_State *); luaA_object_push_item(L, -1, ref); \ lua_remove(L, -2); \ return 1; \ + } \ + \ + static inline int \ + luaA_##prefix##_tostring(lua_State *L) \ + { \ + lua_pushfstring(L, lua_type ": %p", luaL_checkudata(L, 1, lua_type)); \ + return 1; \ } @@ -206,7 +213,8 @@ luaA_object_gc(lua_State *L) return 0; } -#define LUA_OBJECT_META \ +#define LUA_OBJECT_META(prefix) \ + { "__tostring", luaA_##prefix##_tostring }, \ { "add_signal", luaA_object_add_signal_simple }, \ { "remove_signal", luaA_object_remove_signal_simple }, \ { "emit_signal", luaA_object_emit_signal_simple }, diff --git a/image.c b/image.c index 8bdcc43d..9e31ad29 100644 --- a/image.c +++ b/image.c @@ -24,8 +24,6 @@ #include "common/xutil.h" #include -DO_LUA_TOSTRING(image_t, image, "image"); - static int luaA_image_gc(lua_State *L) { @@ -777,7 +775,7 @@ const struct luaL_reg awesome_image_methods[] = }; const struct luaL_reg awesome_image_meta[] = { - LUA_OBJECT_META + LUA_OBJECT_META(image) { "__index", luaA_image_index }, { "rotate", luaA_image_rotate }, { "orientate", luaA_image_orientate }, @@ -792,7 +790,6 @@ const struct luaL_reg awesome_image_meta[] = { "draw_rectangle_gradient", luaA_image_draw_rectangle_gradient }, { "draw_circle", luaA_image_draw_circle }, { "__gc", luaA_image_gc }, - { "__tostring", luaA_image_tostring }, { NULL, NULL } }; diff --git a/key.c b/key.c index 0598dbef..0accbcdf 100644 --- a/key.c +++ b/key.c @@ -31,8 +31,6 @@ #include "common/xutil.h" #include "common/tokenize.h" -DO_LUA_TOSTRING(keyb_t, key, "key") - /** XCB equivalent of XLookupString which translate the keycode given * by PressEvent to a KeySym and a string * \todo use XKB! @@ -1152,8 +1150,7 @@ const struct luaL_reg awesome_key_methods[] = }; const struct luaL_reg awesome_key_meta[] = { - LUA_OBJECT_META - { "__tostring", luaA_key_tostring }, + LUA_OBJECT_META(key) { "__index", luaA_key_index }, { "__newindex", luaA_key_newindex }, { "__gc", luaA_object_gc }, diff --git a/tag.c b/tag.c index 842a2c7b..c36311ba 100644 --- a/tag.c +++ b/tag.c @@ -25,8 +25,6 @@ #include "ewmh.h" #include "widget.h" -DO_LUA_TOSTRING(tag_t, tag, "tag") - void tag_unref_simplified(tag_t **tag) { @@ -411,12 +409,11 @@ const struct luaL_reg awesome_tag_methods[] = }; const struct luaL_reg awesome_tag_meta[] = { - LUA_OBJECT_META + LUA_OBJECT_META(tag) { "clients", luaA_tag_clients }, { "__index", luaA_tag_index }, { "__newindex", luaA_tag_newindex }, { "__gc", luaA_tag_gc }, - { "__tostring", luaA_tag_tostring }, { NULL, NULL }, }; diff --git a/wibox.c b/wibox.c index 2e4dbe17..d420eefb 100644 --- a/wibox.c +++ b/wibox.c @@ -30,8 +30,6 @@ #include "common/xcursor.h" #include "common/xutil.h" -DO_LUA_TOSTRING(wibox_t, wibox, "wibox") - /** Take care of garbage collecting a wibox. * \param L The Lua VM state. * \return The number of elements pushed on stack, 0! @@ -1207,12 +1205,11 @@ const struct luaL_reg awesome_wibox_methods[] = }; const struct luaL_reg awesome_wibox_meta[] = { - LUA_OBJECT_META + LUA_OBJECT_META(wibox) { "geometry", luaA_wibox_geometry }, { "__index", luaA_wibox_index }, { "__newindex", luaA_wibox_newindex }, { "__gc", luaA_wibox_gc }, - { "__tostring", luaA_wibox_tostring }, { NULL, NULL }, }; diff --git a/widget.c b/widget.c index df4144ed..24a8068a 100644 --- a/widget.c +++ b/widget.c @@ -32,8 +32,6 @@ #include "common/atoms.h" #include "common/xutil.h" -DO_LUA_TOSTRING(widget_t, widget, "widget") - /** Collect a widget structure. * \param L The Lua VM state. * \return 0 @@ -558,12 +556,11 @@ const struct luaL_reg awesome_widget_methods[] = }; const struct luaL_reg awesome_widget_meta[] = { - LUA_OBJECT_META + LUA_OBJECT_META(widget) { "extents", luaA_widget_extents }, { "__index", luaA_widget_index }, { "__newindex", luaA_widget_newindex }, { "__gc", luaA_widget_gc }, - { "__tostring", luaA_widget_tostring }, { NULL, NULL } };