lua: _gc are now macros

Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
Julien Danjou 2008-06-16 11:31:38 +02:00
parent 83a2fb66cf
commit 6e36717163
7 changed files with 19 additions and 72 deletions

View File

@ -132,16 +132,7 @@ luaA_keybinding_remove(lua_State *L)
return 0;
}
/** Handle keybinding garbage collection.
*/
static int
luaA_keybinding_gc(lua_State *L)
{
keybinding_t **keybinding = luaA_checkudata(L, 1, "keybinding");
keybinding_unref(keybinding);
keybinding = NULL;
return 0;
}
DO_LUA_GC(keybinding_t, keybinding, "keybinding", keybinding_unref)
/** Convert a keybinding to a printable string.
* \return A string.

10
lua.h
View File

@ -37,6 +37,16 @@ typedef enum
/** Type for Lua function */
typedef int luaA_function;
#define DO_LUA_GC(type, prefix, lua_type, type_unref) \
static int \
luaA_##prefix##_gc(lua_State *L) \
{ \
type **p = luaA_checkudata(L, 1, lua_type); \
type_unref(p); \
*p = NULL; \
return 0; \
}
#define luaA_dostring(L, cmd) \
do { \
if(cmd) \

11
mouse.c
View File

@ -1054,16 +1054,7 @@ luaA_mouse_new(lua_State *L)
return luaA_mouse_userdata_new(button);
}
/** Handle mouse garbage collection.
*/
static int
luaA_mouse_gc(lua_State *L)
{
button_t **b = luaA_checkudata(L, 1, "mouse");
button_unref(b);
*b = NULL;
return 0;
}
DO_LUA_GC(button_t, mouse, "mouse", button_unref)
const struct luaL_reg awesome_mouse_methods[] =
{

View File

@ -570,16 +570,7 @@ luaA_statusbar_widget_get(lua_State *L)
return 1;
}
/** Handle statusbar garbage collection.
*/
static int
luaA_statusbar_gc(lua_State *L)
{
statusbar_t **sb = luaA_checkudata(L, 1, "statusbar");
statusbar_unref(sb);
*sb = NULL;
return 0;
}
DO_LUA_GC(statusbar_t, statusbar, "statusbar", statusbar_unref)
const struct luaL_reg awesome_statusbar_methods[] =
{

13
tag.c
View File

@ -535,17 +535,6 @@ luaA_tag_name_set(lua_State *L)
return 0;
}
/** Handle tag garbage collection.
*/
static int
luaA_tag_gc(lua_State *L)
{
tag_t **tag = luaA_checkudata(L, 1, "tag");
tag_unref(tag);
*tag = NULL;
return 0;
}
/** Get the layout of the tag.
* \param L The Lua VM state.
*
@ -601,6 +590,8 @@ luaA_tag_userdata_new(tag_t *t)
return luaA_settype(globalconf.L, "tag");
}
DO_LUA_GC(tag_t, tag, "tag", tag_unref)
const struct luaL_reg awesome_tag_methods[] =
{
{ "new", luaA_tag_new },

View File

@ -564,22 +564,6 @@ luaA_titlebar_userdata_new(titlebar_t *t)
return luaA_settype(globalconf.L, "titlebar");
}
/** Handle titlebar garbage collection.
* \param L The Lua VM state.
* \return The number of value pushed.
*
* \luastack
* \lvalue A titlebar.
*/
static int
luaA_titlebar_gc(lua_State *L)
{
titlebar_t **titlebar = luaA_checkudata(L, 1, "titlebar");
titlebar_unref(titlebar);
*titlebar = NULL;
return 0;
}
/** Convert a titlebar to a printable string.
* \param L The Lua VM state.
* \return The number of value pushed.
@ -614,6 +598,8 @@ luaA_titlebar_eq(lua_State *L)
return 1;
}
DO_LUA_GC(titlebar_t, titlebar, "titlebar", titlebar_unref)
const struct luaL_reg awesome_titlebar_methods[] =
{
{ "new", luaA_titlebar_new },

View File

@ -442,21 +442,6 @@ luaA_widget_set(lua_State *L)
return 0;
}
/** Handle widget garbage collection.
* \param L The Lua VM state.
*
* \luastack
* \lvalue A widget.
*/
static int
luaA_widget_gc(lua_State *L)
{
widget_t **widget = luaA_checkudata(L, 1, "widget");
widget_unref(widget);
*widget = NULL;
return 0;
}
/** Convert a widget into a printable string.
* \param L The Lua VM state.
*
@ -488,6 +473,8 @@ luaA_widget_eq(lua_State *L)
return 1;
}
DO_LUA_GC(widget_t, widget, "widget", widget_unref)
/** Set the widget name.
* \param L The Lua VM state.
*