lua: __eq methods are not macros

Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
Julien Danjou 2008-06-16 11:37:55 +02:00
parent 6e36717163
commit 16646c86ab
7 changed files with 24 additions and 83 deletions

View File

@ -1188,18 +1188,6 @@ luaA_client_floating_get(lua_State *L)
return 1; 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. /** Redraw a client by unmapping and mapping it quickly.
* \param L The Lua VM state. * \param L The Lua VM state.
* *
@ -1415,6 +1403,10 @@ luaA_client_ishidden(lua_State *L)
return 1; return 1;
} }
/** Create and push a client userdata.
* \param c The client.
* \return The number of pushed value.
*/
int int
luaA_client_userdata_new(client_t *c) luaA_client_userdata_new(client_t *c)
{ {
@ -1423,6 +1415,8 @@ luaA_client_userdata_new(client_t *c)
return luaA_settype(globalconf.L, "client"); return luaA_settype(globalconf.L, "client");
} }
DO_LUA_EQ(client_t, client, "client")
const struct luaL_reg awesome_client_methods[] = const struct luaL_reg awesome_client_methods[] =
{ {
{ "get", luaA_client_get }, { "get", luaA_client_get },

10
lua.h
View File

@ -47,6 +47,16 @@ typedef int luaA_function;
return 0; \ 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) \ #define luaA_dostring(L, cmd) \
do { \ do { \
if(cmd) \ if(cmd) \

View File

@ -1055,6 +1055,7 @@ luaA_mouse_new(lua_State *L)
} }
DO_LUA_GC(button_t, mouse, "mouse", button_unref) DO_LUA_GC(button_t, mouse, "mouse", button_unref)
DO_LUA_EQ(button_t, mouse, "mouse")
const struct luaL_reg awesome_mouse_methods[] = 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[] = const struct luaL_reg awesome_mouse_meta[] =
{ {
{ "__gc", luaA_mouse_gc }, { "__gc", luaA_mouse_gc },
{ "__eq", luaA_mouse_eq },
{ NULL, NULL } { NULL, NULL }
}; };

View File

@ -273,23 +273,6 @@ statusbar_position_update(statusbar_t *statusbar, position_t position)
statusbar->need_update = true; 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. /** Set the statusbar position.
* \param L The Lua VM state. * \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_GC(statusbar_t, statusbar, "statusbar", statusbar_unref)
DO_LUA_EQ(statusbar_t, statusbar, "statusbar")
const struct luaL_reg awesome_statusbar_methods[] = const struct luaL_reg awesome_statusbar_methods[] =
{ {

18
tag.c
View File

@ -235,23 +235,6 @@ tag_view_only_byindex(int screen, int dindex)
tag_view_only(tag); 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. /** Convert a tag to a printable string.
* \param L The Lua VM state. * \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_GC(tag_t, tag, "tag", tag_unref)
DO_LUA_EQ(tag_t, tag, "tag")
const struct luaL_reg awesome_tag_methods[] = const struct luaL_reg awesome_tag_methods[] =
{ {

View File

@ -580,25 +580,8 @@ luaA_titlebar_tostring(lua_State *L)
return 1; 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_GC(titlebar_t, titlebar, "titlebar", titlebar_unref)
DO_LUA_EQ(titlebar_t, titlebar, "titlebar")
const struct luaL_reg awesome_titlebar_methods[] = const struct luaL_reg awesome_titlebar_methods[] =
{ {

View File

@ -456,25 +456,6 @@ luaA_widget_tostring(lua_State *L)
return 1; 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. /** Set the widget name.
* \param L The Lua VM state. * \param L The Lua VM state.
* *
@ -539,6 +520,9 @@ luaA_widget_visible_get(lua_State *L)
return 1; 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[] = const struct luaL_reg awesome_widget_methods[] =
{ {
{ "new", luaA_widget_new }, { "new", luaA_widget_new },