degesch: add introspection for "str" and "str_map"

This commit is contained in:
Přemysl Eric Janouch 2016-10-27 19:10:35 +02:00
parent 9408dfc67c
commit cb5ad675a6
Signed by: p
GPG Key ID: B715679E3A361BE6
1 changed files with 32 additions and 12 deletions

View File

@ -1247,14 +1247,14 @@ weak_unref (struct weak_ref_link **list, struct weak_ref_link **link)
enum ispect_type enum ispect_type
{ {
ISPECT_BOOL, ISPECT_BOOL, ISPECT_INT, ISPECT_UINT, ISPECT_SIZE, ISPECT_STRING,
ISPECT_INT,
ISPECT_UINT, ISPECT_STR, ///< "struct str"
ISPECT_SIZE, ISPECT_STR_MAP, ///< "struct str_map"
ISPECT_STRING, ISPECT_REF, ///< Weakly referenced object
ISPECT_REF, ///< Weakly referenced
#if 0 #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 ISPECT_LIST, ///< Typically copied, depending on type
#endif #endif
}; };
@ -1404,6 +1404,7 @@ static struct ispect_field g_channel_ispect_fields[] =
{ {
ISPECT( channel, name, STRING ) ISPECT( channel, name, STRING )
ISPECT( channel, topic, STRING ) ISPECT( channel, topic, STRING )
ISPECT( channel, no_param_modes, STR )
ISPECT( channel, users_len, SIZE ) ISPECT( channel, users_len, SIZE )
ISPECT( channel, left_manually, BOOL ) 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 // TODO: either rename the underlying field or fix the plugins
{ "user", offsetof (struct server, irc_user), ISPECT_REF, &g_user_ispect }, { "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_UINT: lua_pushinteger (L, *(unsigned *) p); return true;
case ISPECT_SIZE: lua_pushinteger (L, *(size_t *) 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_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: case ISPECT_REF:
{ {
// TODO: we can definitely make a resolution table right in Lua, // 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 static int