From 16646c86ab61c70be29cedfd8389a19ca8abe09f Mon Sep 17 00:00:00 2001 From: Julien Danjou Date: Mon, 16 Jun 2008 11:37:55 +0200 Subject: [PATCH] lua: __eq methods are not macros Signed-off-by: Julien Danjou --- client.c | 18 ++++++------------ lua.h | 10 ++++++++++ mouse.c | 2 ++ statusbar.c | 18 +----------------- tag.c | 18 +----------------- titlebar.c | 19 +------------------ widget.c | 22 +++------------------- 7 files changed, 24 insertions(+), 83 deletions(-) diff --git a/client.c b/client.c index 211db4f0..1d8cc409 100644 --- a/client.c +++ b/client.c @@ -1188,18 +1188,6 @@ luaA_client_floating_get(lua_State *L) return 1; } -/** Check if a client is equal to another. - * \param L The Lua VM state. - */ -static int -luaA_client_eq(lua_State *L) -{ - client_t **c1 = luaA_checkudata(L, 1, "client"); - client_t **c2 = luaA_checkudata(L, 2, "client"); - lua_pushboolean(L, (*c1 == *c2)); - return 1; -} - /** Redraw a client by unmapping and mapping it quickly. * \param L The Lua VM state. * @@ -1415,6 +1403,10 @@ luaA_client_ishidden(lua_State *L) return 1; } +/** Create and push a client userdata. + * \param c The client. + * \return The number of pushed value. + */ int luaA_client_userdata_new(client_t *c) { @@ -1423,6 +1415,8 @@ luaA_client_userdata_new(client_t *c) return luaA_settype(globalconf.L, "client"); } +DO_LUA_EQ(client_t, client, "client") + const struct luaL_reg awesome_client_methods[] = { { "get", luaA_client_get }, diff --git a/lua.h b/lua.h index 9bab2117..17f12a6d 100644 --- a/lua.h +++ b/lua.h @@ -47,6 +47,16 @@ typedef int luaA_function; return 0; \ } +#define DO_LUA_EQ(type, prefix, lua_type) \ + static int \ + luaA_##prefix##_eq(lua_State *L) \ + { \ + type **p1 = luaA_checkudata(L, 1, lua_type); \ + type **p2 = luaA_checkudata(L, 2, lua_type); \ + lua_pushboolean(L, (*p1 == *p2)); \ + return 1; \ + } + #define luaA_dostring(L, cmd) \ do { \ if(cmd) \ diff --git a/mouse.c b/mouse.c index 6afd1e5c..83f931b4 100644 --- a/mouse.c +++ b/mouse.c @@ -1055,6 +1055,7 @@ luaA_mouse_new(lua_State *L) } DO_LUA_GC(button_t, mouse, "mouse", button_unref) +DO_LUA_EQ(button_t, mouse, "mouse") const struct luaL_reg awesome_mouse_methods[] = { @@ -1066,6 +1067,7 @@ const struct luaL_reg awesome_mouse_methods[] = const struct luaL_reg awesome_mouse_meta[] = { { "__gc", luaA_mouse_gc }, + { "__eq", luaA_mouse_eq }, { NULL, NULL } }; diff --git a/statusbar.c b/statusbar.c index 2fae5f23..6047fc4c 100644 --- a/statusbar.c +++ b/statusbar.c @@ -273,23 +273,6 @@ statusbar_position_update(statusbar_t *statusbar, position_t position) statusbar->need_update = true; } -/** Check for statusbar equality. - * \param L The Lua VM state. - * - * \luastack - * \lvalue A statusbar. - * \lparam Another statusbar. - * \return True if statusbar are equals, false otherwise. - */ -static int -luaA_statusbar_eq(lua_State *L) -{ - statusbar_t **t1 = luaA_checkudata(L, 1, "statusbar"); - statusbar_t **t2 = luaA_checkudata(L, 2, "statusbar"); - lua_pushboolean(L, (*t1 == *t2)); - return 1; -} - /** Set the statusbar position. * \param L The Lua VM state. * @@ -571,6 +554,7 @@ luaA_statusbar_widget_get(lua_State *L) } DO_LUA_GC(statusbar_t, statusbar, "statusbar", statusbar_unref) +DO_LUA_EQ(statusbar_t, statusbar, "statusbar") const struct luaL_reg awesome_statusbar_methods[] = { diff --git a/tag.c b/tag.c index 1ac15a62..9ce96173 100644 --- a/tag.c +++ b/tag.c @@ -235,23 +235,6 @@ tag_view_only_byindex(int screen, int dindex) tag_view_only(tag); } -/** Check for tag equality. - * \param L The Lua VM state. - * - * \luastack - * \lvalue A tag. - * \lparam Another tag. - * \lreturn True if tags are equals. - */ -static int -luaA_tag_eq(lua_State *L) -{ - tag_t **t1 = luaA_checkudata(L, 1, "tag"); - tag_t **t2 = luaA_checkudata(L, 2, "tag"); - lua_pushboolean(L, (*t1 == *t2)); - return 1; -} - /** Convert a tag to a printable string. * \param L The Lua VM state. * @@ -591,6 +574,7 @@ luaA_tag_userdata_new(tag_t *t) } DO_LUA_GC(tag_t, tag, "tag", tag_unref) +DO_LUA_EQ(tag_t, tag, "tag") const struct luaL_reg awesome_tag_methods[] = { diff --git a/titlebar.c b/titlebar.c index 032caea2..de8f7b68 100644 --- a/titlebar.c +++ b/titlebar.c @@ -580,25 +580,8 @@ luaA_titlebar_tostring(lua_State *L) return 1; } -/** Check for titlebar equality. - * \param L The Lua VM state. - * \return The number of value pushed, 1. - * - * \luastack - * \lvalue A titlebar. - * \lparam A titlebar to compare with. - * \lreturn A boolean value, true if both titlebar are equals. - */ -static int -luaA_titlebar_eq(lua_State *L) -{ - titlebar_t **t1 = luaA_checkudata(L, 1, "titlebar"); - titlebar_t **t2 = luaA_checkudata(L, 2, "titlebar"); - lua_pushboolean(L, (*t1 == *t2)); - return 1; -} - DO_LUA_GC(titlebar_t, titlebar, "titlebar", titlebar_unref) +DO_LUA_EQ(titlebar_t, titlebar, "titlebar") const struct luaL_reg awesome_titlebar_methods[] = { diff --git a/widget.c b/widget.c index 4480b762..6aff29ea 100644 --- a/widget.c +++ b/widget.c @@ -456,25 +456,6 @@ luaA_widget_tostring(lua_State *L) return 1; } -/** Check for widget equality. - * \param L The Lua VM state. - * - * \luastack - * \lvalue A widget. - * \lparam Another widget. - * \lreturn True if widgets are equal. - */ -static int -luaA_widget_eq(lua_State *L) -{ - widget_t **t1 = luaA_checkudata(L, 1, "widget"); - widget_t **t2 = luaA_checkudata(L, 2, "widget"); - lua_pushboolean(L, (*t1 == *t2)); - return 1; -} - -DO_LUA_GC(widget_t, widget, "widget", widget_unref) - /** Set the widget name. * \param L The Lua VM state. * @@ -539,6 +520,9 @@ luaA_widget_visible_get(lua_State *L) return 1; } +DO_LUA_GC(widget_t, widget, "widget", widget_unref) +DO_LUA_EQ(widget_t, widget, "widget") + const struct luaL_reg awesome_widget_methods[] = { { "new", luaA_widget_new },