luaa: merge tostring() with DO_LUA_NEW
Also use the same format as standard Lua for tostring output. Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
parent
c2da16332e
commit
85c7bf07c9
29
client.c
29
client.c
|
@ -35,20 +35,7 @@
|
|||
|
||||
extern awesome_t globalconf;
|
||||
|
||||
/** Create a new client userdata.
|
||||
* \param L The Lua VM state.
|
||||
* \param p A client pointer.
|
||||
* \param The number of elements pushed on the stack.
|
||||
*/
|
||||
int
|
||||
luaA_client_userdata_new(lua_State *L, client_t *p)
|
||||
{
|
||||
client_t **pp = lua_newuserdata(L, sizeof(client_t *));
|
||||
*pp = p;
|
||||
client_ref(pp);
|
||||
return luaA_settype(L, "client");
|
||||
}
|
||||
|
||||
DO_LUA_NEW(extern, client_t, client, "client", client_ref)
|
||||
DO_LUA_EQ(client_t, client, "client")
|
||||
DO_LUA_GC(client_t, client, "client", client_unref)
|
||||
|
||||
|
@ -1129,20 +1116,6 @@ luaA_client_redraw(lua_State *L)
|
|||
return 0;
|
||||
}
|
||||
|
||||
/** Return a formated string for a client.
|
||||
* \param L The Lua VM state.
|
||||
* \luastack
|
||||
* \lvalue A client.
|
||||
* \lreturn A string.
|
||||
*/
|
||||
static int
|
||||
luaA_client_tostring(lua_State *L)
|
||||
{
|
||||
client_t **p = luaA_checkudata(L, 1, "client");
|
||||
lua_pushfstring(L, "[client udata(%p) name(%s)]", *p, (*p)->name);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/** Stop managing a client.
|
||||
* \param L The Lua VM state.
|
||||
* \return The number of elements pushed on stack.
|
||||
|
|
15
image.c
15
image.c
|
@ -323,21 +323,6 @@ luaA_image_index(lua_State *L)
|
|||
return 1;
|
||||
}
|
||||
|
||||
/** Return a formated string for an image.
|
||||
* \param L The Lua VM state.
|
||||
* \luastack
|
||||
* \lvalue An image.
|
||||
* \lreturn A string.
|
||||
*/
|
||||
static int
|
||||
luaA_image_tostring(lua_State *L)
|
||||
{
|
||||
image_t **p = luaA_checkudata(L, 1, "image");
|
||||
lua_pushfstring(L, "[image udata(%p) width(%d) height(%d)]", *p,
|
||||
(*p)->width, (*p)->height);
|
||||
return 1;
|
||||
}
|
||||
|
||||
const struct luaL_reg awesome_image_methods[] =
|
||||
{
|
||||
{ "__call", luaA_image_new },
|
||||
|
|
11
keybinding.c
11
keybinding.c
|
@ -383,17 +383,6 @@ luaA_keybinding_remove(lua_State *L)
|
|||
return 0;
|
||||
}
|
||||
|
||||
/** Convert a keybinding to a printable string.
|
||||
* \return A string.
|
||||
*/
|
||||
static int
|
||||
luaA_keybinding_tostring(lua_State *L)
|
||||
{
|
||||
keybinding_t **p = luaA_checkudata(L, 1, "keybinding");
|
||||
lua_pushfstring(L, "[keybinding udata(%p)]", *p);
|
||||
return 1;
|
||||
}
|
||||
|
||||
const struct luaL_reg awesome_keybinding_methods[] =
|
||||
{
|
||||
{ "__call", luaA_keybinding_new },
|
||||
|
|
7
luaa.h
7
luaa.h
|
@ -47,6 +47,13 @@ typedef int luaA_ref;
|
|||
*pp = p; \
|
||||
type_ref(pp); \
|
||||
return luaA_settype(L, lua_type); \
|
||||
} \
|
||||
static int \
|
||||
luaA_##prefix##_tostring(lua_State *L) \
|
||||
{ \
|
||||
type **p = luaA_checkudata(L, 1, lua_type); \
|
||||
lua_pushfstring(L, lua_type ": %p", *p); \
|
||||
return 1; \
|
||||
}
|
||||
|
||||
#define DO_LUA_GC(type, prefix, lua_type, type_unref) \
|
||||
|
|
14
mouse.c
14
mouse.c
|
@ -1119,20 +1119,6 @@ luaA_button_new(lua_State *L)
|
|||
return luaA_button_userdata_new(L, button);
|
||||
}
|
||||
|
||||
/** Return a formated string for a button.
|
||||
* \param L The Lua VM state.
|
||||
* \luastack
|
||||
* \lvalue A button.
|
||||
* \lreturn A string.
|
||||
*/
|
||||
static int
|
||||
luaA_button_tostring(lua_State *L)
|
||||
{
|
||||
button_t **p = luaA_checkudata(L, 1, "button");
|
||||
lua_pushfstring(L, "[button udata(%p)]", *p);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/** Set a button array with a Lua table.
|
||||
* \param L The Lua VM state.
|
||||
* \param idx The index of the Lua table.
|
||||
|
|
15
tag.c
15
tag.c
|
@ -230,21 +230,6 @@ tag_view_only_byindex(int screen, int dindex)
|
|||
tag_view_only(tags->tab[dindex]);
|
||||
}
|
||||
|
||||
/** Convert a tag to a printable string.
|
||||
* \param L The Lua VM state.
|
||||
*
|
||||
* \luastack
|
||||
* \lvalue A tag.
|
||||
* \lreturn A string.
|
||||
*/
|
||||
static int
|
||||
luaA_tag_tostring(lua_State *L)
|
||||
{
|
||||
tag_t **p = luaA_checkudata(L, 1, "tag");
|
||||
lua_pushfstring(L, "[tag udata(%p) name(%s)]", *p, (*p)->name);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/** Create a new tag.
|
||||
* \param L The Lua VM state.
|
||||
*
|
||||
|
|
15
wibox.c
15
wibox.c
|
@ -605,21 +605,6 @@ wibox_attach(wibox_t *wibox, screen_t *s)
|
|||
wibox->need_update = true;
|
||||
}
|
||||
|
||||
|
||||
/** Convert a wibox to a printable string.
|
||||
* \param L The Lua VM state.
|
||||
*
|
||||
* \luastack
|
||||
* \lvalue A wibox.
|
||||
*/
|
||||
static int
|
||||
luaA_wibox_tostring(lua_State *L)
|
||||
{
|
||||
wibox_t **p = luaA_checkudata(L, 1, "wibox");
|
||||
lua_pushfstring(L, "[wibox udata(%p)]", *p);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/** Create a new wibox.
|
||||
* \param L The Lua VM state.
|
||||
*
|
||||
|
|
14
widget.c
14
widget.c
|
@ -418,20 +418,6 @@ luaA_widget_buttons(lua_State *L)
|
|||
return luaA_button_array_get(L, buttons);
|
||||
}
|
||||
|
||||
/** Convert a widget into a printable string.
|
||||
* \param L The Lua VM state.
|
||||
*
|
||||
* \luastack
|
||||
* \lvalue A widget.
|
||||
*/
|
||||
static int
|
||||
luaA_widget_tostring(lua_State *L)
|
||||
{
|
||||
widget_t **p = luaA_checkudata(L, 1, "widget");
|
||||
lua_pushfstring(L, "[widget udata(%p) name(%s)]", *p, (*p)->name);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/** Generic widget.
|
||||
* \param L The Lua VM state.
|
||||
* \return The number of elements pushed on stack.
|
||||
|
|
Loading…
Reference in New Issue