lua: userdata_new is now macro

Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
Julien Danjou 2008-06-18 18:31:35 +02:00
parent 6cfa589f03
commit 92f369e3aa
18 changed files with 82 additions and 136 deletions

View File

@ -43,6 +43,16 @@
extern awesome_t globalconf; extern awesome_t globalconf;
int
luaA_client_userdata_new(lua_State *L, client_t *p)
{
client_t **pp = lua_newuserdata(L, sizeof(client_t *));
*pp = p;
return luaA_settype(L, "client");
}
DO_LUA_EQ(client_t, client, "client")
/** Load windows properties, restoring client's tag /** Load windows properties, restoring client's tag
* and floating state before awesome was restarted if any. * and floating state before awesome was restarted if any.
* \todo This may bug if number of tags is != than before. * \todo This may bug if number of tags is != than before.
@ -187,7 +197,7 @@ client_updatetitle(client_t *c)
a_iso2utf8(name, &c->name); a_iso2utf8(name, &c->name);
/* call hook */ /* call hook */
luaA_client_userdata_new(c); luaA_client_userdata_new(globalconf.L, c);
luaA_dofunction(globalconf.L, globalconf.hooks.titleupdate, 1); luaA_dofunction(globalconf.L, globalconf.hooks.titleupdate, 1);
widget_invalidate_cache(c->screen, WIDGET_CACHE_CLIENTS); widget_invalidate_cache(c->screen, WIDGET_CACHE_CLIENTS);
@ -200,7 +210,7 @@ static void
client_unfocus(client_t *c) client_unfocus(client_t *c)
{ {
/* Call hook */ /* Call hook */
luaA_client_userdata_new(globalconf.focus->client); luaA_client_userdata_new(globalconf.L, globalconf.focus->client);
luaA_dofunction(globalconf.L, globalconf.hooks.unfocus, 1); luaA_dofunction(globalconf.L, globalconf.hooks.unfocus, 1);
focus_client_push(NULL); focus_client_push(NULL);
@ -256,7 +266,7 @@ client_focus(client_t *c, int screen)
globalconf.screens[c->screen].need_arrange = true; globalconf.screens[c->screen].need_arrange = true;
/* execute hook */ /* execute hook */
luaA_client_userdata_new(globalconf.focus->client); luaA_client_userdata_new(globalconf.L, globalconf.focus->client);
luaA_dofunction(globalconf.L, globalconf.hooks.focus, 1); luaA_dofunction(globalconf.L, globalconf.hooks.focus, 1);
} }
else else
@ -403,7 +413,7 @@ client_manage(xcb_window_t w, xcb_get_geometry_reply_t *wgeom, int screen)
widget_invalidate_cache(c->screen, WIDGET_CACHE_CLIENTS); widget_invalidate_cache(c->screen, WIDGET_CACHE_CLIENTS);
/* call hook */ /* call hook */
luaA_client_userdata_new(c); luaA_client_userdata_new(globalconf.L, c);
luaA_dofunction(globalconf.L, globalconf.hooks.manage, 1); luaA_dofunction(globalconf.L, globalconf.hooks.manage, 1);
} }
@ -628,7 +638,7 @@ client_unmanage(client_t *c)
tag_t *tag; tag_t *tag;
/* call hook */ /* call hook */
luaA_client_userdata_new(c); luaA_client_userdata_new(globalconf.L, c);
luaA_dofunction(globalconf.L, globalconf.hooks.unmanage, 1); luaA_dofunction(globalconf.L, globalconf.hooks.unmanage, 1);
/* The server grab construct avoids race conditions. */ /* The server grab construct avoids race conditions. */
@ -680,7 +690,7 @@ client_updatewmhints(client_t *c)
if((c->isurgent = (wm_hints_flags & XCB_WM_X_URGENCY_HINT))) if((c->isurgent = (wm_hints_flags & XCB_WM_X_URGENCY_HINT)))
{ {
/* execute hook */ /* execute hook */
luaA_client_userdata_new(c); luaA_client_userdata_new(globalconf.L, c);
luaA_dofunction(globalconf.L, globalconf.hooks.urgent, 1); luaA_dofunction(globalconf.L, globalconf.hooks.urgent, 1);
widget_invalidate_cache(c->screen, WIDGET_CACHE_CLIENTS); widget_invalidate_cache(c->screen, WIDGET_CACHE_CLIENTS);
@ -827,7 +837,7 @@ luaA_client_get(lua_State *L)
for(c = globalconf.clients; c; c = c->next) for(c = globalconf.clients; c; c = c->next)
{ {
luaA_client_userdata_new(c); luaA_client_userdata_new(globalconf.L, c);
lua_rawseti(L, -2, i++); lua_rawseti(L, -2, i++);
} }
@ -886,7 +896,7 @@ luaA_client_visible_get(lua_State *L)
for(c = globalconf.clients; c; c = c->next) for(c = globalconf.clients; c; c = c->next)
if(!c->skip && !c->ishidden && client_isvisible(c, screen)) if(!c->skip && !c->ishidden && client_isvisible(c, screen))
{ {
luaA_client_userdata_new(c); luaA_client_userdata_new(globalconf.L, c);
lua_rawseti(L, -2, i++); lua_rawseti(L, -2, i++);
} }
@ -902,7 +912,7 @@ static int
luaA_client_focus_get(lua_State *L __attribute__ ((unused))) luaA_client_focus_get(lua_State *L __attribute__ ((unused)))
{ {
if(globalconf.focus->client) if(globalconf.focus->client)
return luaA_client_userdata_new(globalconf.focus->client); return luaA_client_userdata_new(globalconf.L, globalconf.focus->client);
return 0; return 0;
} }
@ -1328,7 +1338,7 @@ luaA_client_titlebar_get(lua_State *L)
client_t **c = luaA_checkudata(L, 1, "client"); client_t **c = luaA_checkudata(L, 1, "client");
if((*c)->titlebar) if((*c)->titlebar)
return luaA_titlebar_userdata_new((*c)->titlebar); return luaA_titlebar_userdata_new(globalconf.L, (*c)->titlebar);
return 0; return 0;
} }
@ -1392,20 +1402,6 @@ 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
luaA_client_userdata_new(client_t *c)
{
client_t **lc = lua_newuserdata(globalconf.L, sizeof(client_t *));
*lc = c;
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 },

View File

@ -44,7 +44,7 @@ void client_setfloating(client_t *, bool, layer_t);
char * client_markup_parse(client_t *, const char *, ssize_t); char * client_markup_parse(client_t *, const char *, ssize_t);
void client_setborder(client_t *, int); void client_setborder(client_t *, int);
int luaA_client_userdata_new(client_t *); int luaA_client_userdata_new(lua_State *, client_t *);
DO_SLIST(client_t, client, p_delete) DO_SLIST(client_t, client, p_delete)

View File

@ -61,7 +61,7 @@ event_handle_mouse_button_press(client_t *c,
{ {
if(c) if(c)
{ {
luaA_client_userdata_new(c); luaA_client_userdata_new(globalconf.L, c);
luaA_dofunction(globalconf.L, b->fct, 1); luaA_dofunction(globalconf.L, b->fct, 1);
} }
else else
@ -335,7 +335,7 @@ event_handle_enternotify(void *data __attribute__ ((unused)),
globalconf.pointer_x = ev->root_x; globalconf.pointer_x = ev->root_x;
globalconf.pointer_y = ev->root_y; globalconf.pointer_y = ev->root_y;
luaA_client_userdata_new(c); luaA_client_userdata_new(globalconf.L, c);
luaA_dofunction(globalconf.L, globalconf.hooks.mouseover, 1); luaA_dofunction(globalconf.L, globalconf.hooks.mouseover, 1);
} }
else if((emwin = xembed_getbywin(globalconf.embedded, ev->event))) else if((emwin = xembed_getbywin(globalconf.embedded, ev->event)))

2
ewmh.c
View File

@ -470,7 +470,7 @@ ewmh_process_state_atom(client_t *c, xcb_atom_t state, int set)
{ {
c->isurgent = true; c->isurgent = true;
/* execute hook */ /* execute hook */
luaA_client_userdata_new(c); luaA_client_userdata_new(globalconf.L, c);
luaA_dofunction(globalconf.L, globalconf.hooks.urgent, 1); luaA_dofunction(globalconf.L, globalconf.hooks.urgent, 1);
widget_invalidate_cache(c->screen, WIDGET_CACHE_CLIENTS); widget_invalidate_cache(c->screen, WIDGET_CACHE_CLIENTS);
} }

View File

@ -28,6 +28,9 @@
extern awesome_t globalconf; extern awesome_t globalconf;
DO_LUA_NEW(static, keybinding_t, keybinding, "keybinding", keybinding_ref)
DO_LUA_GC(keybinding_t, keybinding, "keybinding", keybinding_unref)
static void static void
__luaA_keystore(keybinding_t *key, const char *str) __luaA_keystore(keybinding_t *key, const char *str)
{ {
@ -59,7 +62,7 @@ static int
luaA_keybinding_new(lua_State *L) luaA_keybinding_new(lua_State *L)
{ {
size_t i, len; size_t i, len;
keybinding_t *k, **keyb; keybinding_t *k;
const char *key; const char *key;
/* arg 1 is key mod table */ /* arg 1 is key mod table */
@ -81,10 +84,7 @@ luaA_keybinding_new(lua_State *L)
k->mod |= xutil_keymask_fromstr(luaL_checkstring(L, -1)); k->mod |= xutil_keymask_fromstr(luaL_checkstring(L, -1));
} }
keyb = lua_newuserdata(globalconf.L, sizeof(client_t *)); return luaA_keybinding_userdata_new(L, k);
*keyb = k;
keybinding_ref(keyb);
return luaA_settype(L, "keybinding");
} }
/** Add a global key binding. This key binding will always be available. /** Add a global key binding. This key binding will always be available.
@ -132,8 +132,6 @@ luaA_keybinding_remove(lua_State *L)
return 0; return 0;
} }
DO_LUA_GC(keybinding_t, keybinding, "keybinding", keybinding_unref)
/** Convert a keybinding to a printable string. /** Convert a keybinding to a printable string.
* \return A string. * \return A string.
*/ */

6
lua.c
View File

@ -434,15 +434,15 @@ luaA_colors_set(lua_State *L)
* \param type Its type. * \param type Its type.
*/ */
void void
luaA_pushpointer(void *p, awesome_type_t type) luaA_pushpointer(lua_State *L, void *p, awesome_type_t type)
{ {
switch(type) switch(type)
{ {
case AWESOME_TYPE_STATUSBAR: case AWESOME_TYPE_STATUSBAR:
luaA_statusbar_userdata_new(p); luaA_statusbar_userdata_new(L, p);
break; break;
case AWESOME_TYPE_TITLEBAR: case AWESOME_TYPE_TITLEBAR:
luaA_titlebar_userdata_new(p); luaA_titlebar_userdata_new(L, p);
break; break;
} }
} }

12
lua.h
View File

@ -38,6 +38,16 @@ typedef enum
/** Type for Lua function */ /** Type for Lua function */
typedef int luaA_function; typedef int luaA_function;
#define DO_LUA_NEW(decl, type, prefix, lua_type, type_ref) \
decl int \
luaA_##prefix##_userdata_new(lua_State *L, type *p) \
{ \
type **pp = lua_newuserdata(L, sizeof(type *)); \
*pp = p; \
type_ref(pp); \
return luaA_settype(L, lua_type); \
}
#define DO_LUA_GC(type, prefix, lua_type, type_unref) \ #define DO_LUA_GC(type, prefix, lua_type, type_unref) \
static int \ static int \
luaA_##prefix##_gc(lua_State *L) \ luaA_##prefix##_gc(lua_State *L) \
@ -171,7 +181,7 @@ luaA_name_init(lua_State *L)
void luaA_init(void); void luaA_init(void);
bool luaA_parserc(const char *); bool luaA_parserc(const char *);
void luaA_pushpointer(void *, awesome_type_t); void luaA_pushpointer(lua_State *, void *, awesome_type_t);
void luaA_cs_init(void); void luaA_cs_init(void);
void luaA_cs_cleanup(void); void luaA_cs_cleanup(void);
void luaA_on_timer(EV_P_ ev_timer *w, int revents); void luaA_on_timer(EV_P_ ev_timer *w, int revents);

21
mouse.c
View File

@ -41,6 +41,10 @@
extern awesome_t globalconf; extern awesome_t globalconf;
DO_LUA_NEW(static, button_t, mouse, "mouse", button_ref)
DO_LUA_GC(button_t, mouse, "mouse", button_unref)
DO_LUA_EQ(button_t, mouse, "mouse")
/** Define corners. */ /** Define corners. */
typedef enum typedef enum
{ {
@ -1008,18 +1012,6 @@ luaA_mouse_screen_get(lua_State *L)
return 1; return 1;
} }
/** Create a new mouse userdata.
* \param bt The mouse button binding.
*/
static int
luaA_mouse_userdata_new(button_t *bt)
{
button_t **b = lua_newuserdata(globalconf.L, sizeof(button_t *));
*b = bt;
button_ref(b);
return luaA_settype(globalconf.L, "mouse");
}
/** Create a new mouse button bindings. /** Create a new mouse button bindings.
* \param L The Lua VM state. * \param L The Lua VM state.
* \luastack * \luastack
@ -1051,12 +1043,9 @@ luaA_mouse_new(lua_State *L)
button->mod |= xutil_keymask_fromstr(luaL_checkstring(L, -1)); button->mod |= xutil_keymask_fromstr(luaL_checkstring(L, -1));
} }
return luaA_mouse_userdata_new(button); return luaA_mouse_userdata_new(L, button);
} }
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[] =
{ {
{ "new", luaA_mouse_new }, { "new", luaA_mouse_new },

View File

@ -31,6 +31,10 @@
extern awesome_t globalconf; extern awesome_t globalconf;
DO_LUA_NEW(extern, statusbar_t, statusbar, "statusbar", statusbar_ref)
DO_LUA_GC(statusbar_t, statusbar, "statusbar", statusbar_unref)
DO_LUA_EQ(statusbar_t, statusbar, "statusbar")
/** Draw a statusbar. /** Draw a statusbar.
* \param statusbar The statusbar to draw. * \param statusbar The statusbar to draw.
*/ */
@ -523,19 +527,7 @@ luaA_statusbar_new(lua_State *L)
sb->position = position_get_from_str(luaA_getopt_string(L, 1, "position", "top")); sb->position = position_get_from_str(luaA_getopt_string(L, 1, "position", "top"));
return luaA_statusbar_userdata_new(sb); return luaA_statusbar_userdata_new(L, sb);
}
/** Create a new statusbar userdata.
* \param t The statusbar.
*/
int
luaA_statusbar_userdata_new(statusbar_t *t)
{
statusbar_t **sb = lua_newuserdata(globalconf.L, sizeof(statusbar_t *));
*sb = t;
statusbar_ref(sb);
return luaA_settype(globalconf.L, "statusbar");
} }
/** Get all widget from a statusbar. /** Get all widget from a statusbar.
@ -556,7 +548,7 @@ luaA_statusbar_widget_get(lua_State *L)
for(widget = (*sb)->widgets; widget; widget = widget->next) for(widget = (*sb)->widgets; widget; widget = widget->next)
{ {
luaA_widget_userdata_new(widget->widget); luaA_widget_userdata_new(L, widget->widget);
/* ref again for the list */ /* ref again for the list */
widget_ref(&widget->widget); widget_ref(&widget->widget);
lua_rawseti(L, -2, i++); lua_rawseti(L, -2, i++);
@ -565,9 +557,6 @@ luaA_statusbar_widget_get(lua_State *L)
return 1; return 1;
} }
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[] =
{ {
{ "new", luaA_statusbar_new }, { "new", luaA_statusbar_new },

View File

@ -37,7 +37,7 @@ statusbar_delete(statusbar_t **statusbar)
void statusbar_refresh(void); void statusbar_refresh(void);
int luaA_statusbar_userdata_new(statusbar_t *); int luaA_statusbar_userdata_new(lua_State *, statusbar_t *);
DO_RCNT(statusbar_t, statusbar, statusbar_delete) DO_RCNT(statusbar_t, statusbar, statusbar_delete)
DO_SLIST(statusbar_t, statusbar, statusbar_delete) DO_SLIST(statusbar_t, statusbar, statusbar_delete)

26
tag.c
View File

@ -38,6 +38,10 @@
extern awesome_t globalconf; extern awesome_t globalconf;
DO_LUA_NEW(extern, tag_t, tag, "tag", tag_ref)
DO_LUA_GC(tag_t, tag, "tag", tag_unref)
DO_LUA_EQ(tag_t, tag, "tag")
/** View or unview a tag. /** View or unview a tag.
* \param tag the tag * \param tag the tag
* \param view set visible or not * \param view set visible or not
@ -296,7 +300,7 @@ luaA_tag_get(lua_State *L)
for(tag = globalconf.screens[screen].tags; tag; tag = tag->next) for(tag = globalconf.screens[screen].tags; tag; tag = tag->next)
{ {
luaA_tag_userdata_new(tag); luaA_tag_userdata_new(L, tag);
lua_setfield(L, -2, tag->name); lua_setfield(L, -2, tag->name);
} }
@ -323,7 +327,7 @@ luaA_tag_geti(lua_State *L)
for(tag = globalconf.screens[screen].tags; tag; tag = tag->next) for(tag = globalconf.screens[screen].tags; tag; tag = tag->next)
{ {
luaA_tag_userdata_new(tag); luaA_tag_userdata_new(L, tag);
lua_rawseti(L, -2, i++); lua_rawseti(L, -2, i++);
} }
@ -361,7 +365,7 @@ luaA_tag_new(lua_State *L)
layout, layout,
mwfact, nmaster, ncol); mwfact, nmaster, ncol);
return luaA_tag_userdata_new(tag); return luaA_tag_userdata_new(L, tag);
} }
/** Add or remove a tag from the current view. /** Add or remove a tag from the current view.
@ -589,22 +593,6 @@ luaA_tag_layout_set(lua_State *L)
} }
/** Create a new userdata from a tag.
* \param t The tag.
* \return The luaA_settype returnn value.
*/
int
luaA_tag_userdata_new(tag_t *t)
{
tag_t **lt = lua_newuserdata(globalconf.L, sizeof(tag_t *));
*lt = t;
tag_ref(lt);
return luaA_settype(globalconf.L, "tag");
}
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[] =
{ {
{ "new", luaA_tag_new }, { "new", luaA_tag_new },

2
tag.h
View File

@ -45,7 +45,7 @@ bool is_client_tagged(client_t *, tag_t *);
void tag_client_with_current_selected(client_t *); void tag_client_with_current_selected(client_t *);
void tag_view_only_byindex(int, int); void tag_view_only_byindex(int, int);
void tag_append_to_screen(tag_t *, int); void tag_append_to_screen(tag_t *, int);
int luaA_tag_userdata_new(tag_t *); int luaA_tag_userdata_new(lua_State *, tag_t *);
DO_RCNT(tag_t, tag, tag_delete) DO_RCNT(tag_t, tag, tag_delete)
DO_SLIST(tag_t, tag, tag_delete) DO_SLIST(tag_t, tag, tag_delete)

View File

@ -32,6 +32,10 @@
extern awesome_t globalconf; extern awesome_t globalconf;
DO_LUA_NEW(extern, titlebar_t, titlebar, "titlebar", titlebar_ref)
DO_LUA_GC(titlebar_t, titlebar, "titlebar", titlebar_unref)
DO_LUA_EQ(titlebar_t, titlebar, "titlebar")
/** Get a client by its titlebar. /** Get a client by its titlebar.
* \param titlebar The titlebar. * \param titlebar The titlebar.
* \return A client. * \return A client.
@ -327,7 +331,7 @@ luaA_titlebar_new(lua_State *L)
tb->border.width = luaA_getopt_number(L, 1, "border_width", 0); tb->border.width = luaA_getopt_number(L, 1, "border_width", 0);
return luaA_titlebar_userdata_new(tb); return luaA_titlebar_userdata_new(globalconf.L, tb);
} }
/** Add a widget to a titlebar. /** Add a widget to a titlebar.
@ -382,7 +386,7 @@ luaA_titlebar_widget_get(lua_State *L)
for(witer = (*tb)->widgets; witer; witer = witer->next) for(witer = (*tb)->widgets; witer; witer = witer->next)
{ {
luaA_widget_userdata_new(witer->widget); luaA_widget_userdata_new(L, witer->widget);
lua_setfield(L, -2, witer->widget->name); lua_setfield(L, -2, witer->widget->name);
} }
@ -404,7 +408,7 @@ luaA_titlebar_client_get(lua_State *L)
client_t *c; client_t *c;
if((c = client_getbytitlebar(*titlebar))) if((c = client_getbytitlebar(*titlebar)))
return luaA_client_userdata_new(c); return luaA_client_userdata_new(L, c);
return 0; return 0;
} }
@ -481,19 +485,6 @@ luaA_titlebar_border_set(lua_State *L)
return 0; return 0;
} }
/** Create a new titlebar userdata.
* \param t The titlebar.
* \return The number of value pushed.
*/
int
luaA_titlebar_userdata_new(titlebar_t *t)
{
titlebar_t **tb = lua_newuserdata(globalconf.L, sizeof(titlebar_t *));
*tb = t;
titlebar_ref(tb);
return luaA_settype(globalconf.L, "titlebar");
}
/** Convert a titlebar to a printable string. /** Convert a titlebar to a printable string.
* \param L The Lua VM state. * \param L The Lua VM state.
* \return The number of value pushed. * \return The number of value pushed.
@ -510,9 +501,6 @@ luaA_titlebar_tostring(lua_State *L)
return 1; 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[] = const struct luaL_reg awesome_titlebar_methods[] =
{ {
{ "new", luaA_titlebar_new }, { "new", luaA_titlebar_new },

View File

@ -30,7 +30,7 @@ void titlebar_geometry_compute(client_t *, area_t, area_t *);
void titlebar_draw(client_t *); void titlebar_draw(client_t *);
void titlebar_init(client_t *); void titlebar_init(client_t *);
int luaA_titlebar_userdata_new(titlebar_t *); int luaA_titlebar_userdata_new(lua_State *, titlebar_t *);
/** Add the titlebar geometry to a geometry. /** Add the titlebar geometry to a geometry.
* \param t The titlebar * \param t The titlebar

View File

@ -34,6 +34,10 @@
extern awesome_t globalconf; extern awesome_t globalconf;
DO_LUA_NEW(extern, widget_t, widget, "widget", widget_ref)
DO_LUA_GC(widget_t, widget, "widget", widget_unref)
DO_LUA_EQ(widget_t, widget, "widget")
#include "widgetgen.h" #include "widgetgen.h"
/** Compute offset for drawing the first pixel of a widget. /** Compute offset for drawing the first pixel of a widget.
@ -94,7 +98,7 @@ widget_common_button_press(widget_node_t *w,
for(b = w->widget->buttons; b; b = b->next) for(b = w->widget->buttons; b; b = b->next)
if(ev->detail == b->button && CLEANMASK(ev->state) == b->mod && b->fct) if(ev->detail == b->button && CLEANMASK(ev->state) == b->mod && b->fct)
{ {
luaA_pushpointer(p, type); luaA_pushpointer(globalconf.L, p, type);
luaA_dofunction(globalconf.L, b->fct, 1); luaA_dofunction(globalconf.L, b->fct, 1);
} }
} }
@ -291,19 +295,6 @@ widget_invalidate_bywidget(widget_t *widget)
titlebar_draw(c); titlebar_draw(c);
} }
/** Create a new widget userdata. The object is pushed on the stack.
* \param widget The widget.
* \return Return luaA_settype() return value.
*/
int
luaA_widget_userdata_new(widget_t *widget)
{
widget_t **w = lua_newuserdata(globalconf.L, sizeof(widget_t *));
*w = widget;
widget_ref(w);
return luaA_settype(globalconf.L, "widget");
}
/** Create a new widget. /** Create a new widget.
* \param L The Lua VM state. * \param L The Lua VM state.
* *
@ -337,7 +328,7 @@ luaA_widget_new(lua_State *L)
w->name = luaA_name_init(L); w->name = luaA_name_init(L);
return luaA_widget_userdata_new(w); return luaA_widget_userdata_new(L, w);
} }
/** Add a mouse button bindings to a widget. /** Add a mouse button bindings to a widget.
@ -517,9 +508,6 @@ 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 },

View File

@ -37,7 +37,7 @@ widget_t * widget_getbyname(const char *);
void widget_tell_managestatus(widget_t *, widget_tell_status_t, const char *); void widget_tell_managestatus(widget_t *, widget_tell_status_t, const char *);
void widget_render(widget_node_t *, draw_context_t *, xcb_gcontext_t, xcb_drawable_t, int, position_t, int, int, void *); void widget_render(widget_node_t *, draw_context_t *, xcb_gcontext_t, xcb_drawable_t, int, position_t, int, int, void *);
int luaA_widget_userdata_new(widget_t *); int luaA_widget_userdata_new(lua_State *, widget_t *);
widget_constructor_t taglist_new; widget_constructor_t taglist_new;
widget_constructor_t textbox_new; widget_constructor_t textbox_new;

View File

@ -231,8 +231,8 @@ taglist_button_press(widget_node_t *w,
&& ev->event_x < AREA_RIGHT(*area) && ev->event_x < AREA_RIGHT(*area)
&& (data->show_empty || tag->selected || tag_isoccupied(tag)) ) && (data->show_empty || tag->selected || tag_isoccupied(tag)) )
{ {
luaA_pushpointer(object, type); luaA_pushpointer(globalconf.L, object, type);
luaA_tag_userdata_new(tag); luaA_tag_userdata_new(globalconf.L, tag);
luaA_dofunction(globalconf.L, b->fct, 2); luaA_dofunction(globalconf.L, b->fct, 2);
return; return;
} }

View File

@ -228,8 +228,8 @@ tasklist_button_press(widget_node_t *w,
for(b = w->widget->buttons; b; b = b->next) for(b = w->widget->buttons; b; b = b->next)
if(ev->detail == b->button && CLEANMASK(ev->state) == b->mod && b->fct) if(ev->detail == b->button && CLEANMASK(ev->state) == b->mod && b->fct)
{ {
luaA_pushpointer(object, type); luaA_pushpointer(globalconf.L, object, type);
luaA_client_userdata_new(c); luaA_client_userdata_new(globalconf.L, c);
luaA_dofunction(globalconf.L, b->fct, 2); luaA_dofunction(globalconf.L, b->fct, 2);
} }
} }