From cb5ad675a62323d5d8e24bf49aa6df4acad135a2 Mon Sep 17 00:00:00 2001
From: Přemysl Janouch
Date: Thu, 27 Oct 2016 19:10:35 +0200
Subject: degesch: add introspection for "str" and "str_map"
---
degesch.c | 44 ++++++++++++++++++++++++++++++++------------
1 file changed, 32 insertions(+), 12 deletions(-)
diff --git a/degesch.c b/degesch.c
index 0a76f6b..d6cfdec 100644
--- a/degesch.c
+++ b/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
--
cgit v1.2.3-70-g09d2