degesch: add introspection for "str" and "str_map"
This commit is contained in:
parent
9408dfc67c
commit
cb5ad675a6
44
degesch.c
44
degesch.c
|
@ -1247,14 +1247,14 @@ weak_unref (struct weak_ref_link **list, struct weak_ref_link **link)
|
|||
|
||||
enum ispect_type
|
||||
{
|
||||
ISPECT_BOOL,
|
||||
ISPECT_INT,
|
||||
ISPECT_UINT,
|
||||
ISPECT_SIZE,
|
||||
ISPECT_STRING,
|
||||
ISPECT_REF, ///< Weakly referenced
|
||||
ISPECT_BOOL, ISPECT_INT, ISPECT_UINT, ISPECT_SIZE, ISPECT_STRING,
|
||||
|
||||
ISPECT_STR, ///< "struct str"
|
||||
ISPECT_STR_MAP, ///< "struct str_map"
|
||||
ISPECT_REF, ///< Weakly referenced object
|
||||
#if 0
|
||||
// TODO: also str_map, str_vector
|
||||
// XXX: maybe just a PTR type that doesn't warrant weak_refs but is copied,
|
||||
// LIST-ness seems to be more of a direct flag of a type
|
||||
ISPECT_LIST, ///< Typically copied, depending on type
|
||||
#endif
|
||||
};
|
||||
|
@ -1402,10 +1402,11 @@ struct channel
|
|||
|
||||
static struct ispect_field g_channel_ispect_fields[] =
|
||||
{
|
||||
ISPECT( channel, name, STRING )
|
||||
ISPECT( channel, topic, STRING )
|
||||
ISPECT( channel, users_len, SIZE )
|
||||
ISPECT( channel, left_manually, BOOL )
|
||||
ISPECT( channel, name, STRING )
|
||||
ISPECT( channel, topic, STRING )
|
||||
ISPECT( channel, no_param_modes, STR )
|
||||
ISPECT( channel, users_len, SIZE )
|
||||
ISPECT( channel, left_manually, BOOL )
|
||||
{}
|
||||
};
|
||||
|
||||
|
@ -1766,6 +1767,7 @@ static struct ispect_field g_server_ispect_fields[] =
|
|||
|
||||
// TODO: either rename the underlying field or fix the plugins
|
||||
{ "user", offsetof (struct server, irc_user), ISPECT_REF, &g_user_ispect },
|
||||
{ "user_mode", offsetof (struct server, irc_user_mode), ISPECT_STR, NULL },
|
||||
|
||||
{}
|
||||
};
|
||||
|
@ -9802,6 +9804,24 @@ lua_plugin_property_get_ispect (lua_State *L, const char *property_name)
|
|||
case ISPECT_UINT: lua_pushinteger (L, *(unsigned *) p); return true;
|
||||
case ISPECT_SIZE: lua_pushinteger (L, *(size_t *) p); return true;
|
||||
case ISPECT_STRING: lua_pushstring (L, *(char **) p); return true;
|
||||
case ISPECT_STR:
|
||||
{
|
||||
struct str *s = p;
|
||||
lua_pushlstring (L, s->str, s->len);
|
||||
return true;
|
||||
}
|
||||
case ISPECT_STR_MAP:
|
||||
{
|
||||
// FIXME: we should be able to support other things than strings
|
||||
struct str_map_iter iter;
|
||||
str_map_iter_init (&iter, p);
|
||||
|
||||
char *s;
|
||||
lua_newtable (L);
|
||||
while ((s = str_map_iter_next (&iter)))
|
||||
lua_plugin_kv (L, iter.link->key, s);
|
||||
return true;
|
||||
}
|
||||
case ISPECT_REF:
|
||||
{
|
||||
// TODO: we can definitely make a resolution table right in Lua,
|
||||
|
@ -9816,7 +9836,7 @@ lua_plugin_property_get_ispect (lua_State *L, const char *property_name)
|
|||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
return soft_assert (false);
|
||||
}
|
||||
|
||||
static int
|
||||
|
|
Loading…
Reference in New Issue