client: Include c.name in the result of tostring(c)
Signed-off-by: Uli Schlachter <psychon@znc.in>
This commit is contained in:
parent
8dc6fa8666
commit
8eed5e7bcf
|
@ -244,6 +244,7 @@ luaA_class_setup(lua_State *L, lua_class_t *class,
|
|||
class->newindex_miss_property = newindex_miss_property;
|
||||
class->checker = checker;
|
||||
class->parent = parent;
|
||||
class->tostring = NULL;
|
||||
class->instances = 0;
|
||||
|
||||
signal_add(&class->signals, "new");
|
||||
|
|
|
@ -72,6 +72,8 @@ struct lua_class_t
|
|||
lua_class_checker_t checker;
|
||||
/** Number of instances of this class in lua */
|
||||
unsigned int instances;
|
||||
/** Class tostring method */
|
||||
lua_class_propfunc_t tostring;
|
||||
};
|
||||
|
||||
const char * luaA_typename(lua_State *, int);
|
||||
|
@ -100,6 +102,11 @@ int luaA_class_new(lua_State *, lua_class_t *);
|
|||
void * luaA_checkudata(lua_State *, int, lua_class_t *);
|
||||
void * luaA_toudata(lua_State *L, int ud, lua_class_t *);
|
||||
|
||||
static inline void luaA_class_set_tostring(lua_class_t *class, lua_class_propfunc_t callback)
|
||||
{
|
||||
class->tostring = callback;
|
||||
}
|
||||
|
||||
static inline void *
|
||||
luaA_checkudataornil(lua_State *L, int udx, lua_class_t *class)
|
||||
{
|
||||
|
|
|
@ -317,22 +317,34 @@ luaA_object_tostring(lua_State *L)
|
|||
{
|
||||
lua_class_t *lua_class = luaA_class_get(L, 1);
|
||||
lua_object_t *object = luaA_checkudata(L, 1, lua_class);
|
||||
int offset = 0;
|
||||
|
||||
int i = 0;
|
||||
for(; lua_class; lua_class = lua_class->parent, i++)
|
||||
for(; lua_class; lua_class = lua_class->parent)
|
||||
{
|
||||
if(i)
|
||||
if(offset)
|
||||
{
|
||||
lua_pushliteral(L, "/");
|
||||
lua_insert(L, - (i * 2));
|
||||
lua_insert(L, -++offset);
|
||||
}
|
||||
lua_pushstring(L, NONULL(lua_class->name));
|
||||
lua_insert(L, - (i * 2) - 1);
|
||||
lua_insert(L, -++offset);
|
||||
|
||||
if (lua_class->tostring) {
|
||||
int k, n;
|
||||
|
||||
lua_pushliteral(L, "(");
|
||||
n = 2 + lua_class->tostring(L, object);
|
||||
lua_pushliteral(L, ")");
|
||||
|
||||
for (k = 0; k < n; k++)
|
||||
lua_insert(L, -offset);
|
||||
offset += n;
|
||||
}
|
||||
}
|
||||
|
||||
lua_pushfstring(L, ": %p", object);
|
||||
|
||||
lua_concat(L, i * 2);
|
||||
lua_concat(L, offset + 1);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
|
|
@ -2156,6 +2156,19 @@ luaA_client_keys(lua_State *L)
|
|||
return luaA_key_array_get(L, 1, keys);
|
||||
}
|
||||
|
||||
static int
|
||||
client_tostring(lua_State *L, client_t *c)
|
||||
{
|
||||
char *name = c->name ? c->name : c->alt_name;
|
||||
ssize_t len = a_strlen(name);
|
||||
ssize_t limit = 20;
|
||||
|
||||
lua_pushlstring(L, name, MIN(len, limit));
|
||||
if (len > limit)
|
||||
lua_pushstring(L, "...");
|
||||
return len > limit ? 2 : 1;
|
||||
}
|
||||
|
||||
/* Client module.
|
||||
* \param L The Lua VM state.
|
||||
* \return The number of pushed elements.
|
||||
|
@ -2233,6 +2246,7 @@ client_class_setup(lua_State *L)
|
|||
(lua_class_checker_t) client_checker,
|
||||
luaA_class_index_miss_property, luaA_class_newindex_miss_property,
|
||||
client_methods, client_meta);
|
||||
luaA_class_set_tostring(&client_class, (lua_class_propfunc_t) client_tostring);
|
||||
luaA_class_add_property(&client_class, "name",
|
||||
NULL,
|
||||
(lua_class_propfunc_t) luaA_client_get_name,
|
||||
|
|
Loading…
Reference in New Issue