degesch: add introspection for "app_context"

This commit is contained in:
Přemysl Eric Janouch 2016-10-27 20:02:25 +02:00
parent cb5ad675a6
commit 911276b263
Signed by: p
GPG Key ID: B715679E3A361BE6

View File

@ -2110,6 +2110,18 @@ struct app_context
} }
*g_ctx; *g_ctx;
static struct ispect_field g_ctx_ispect_fields[] =
{
ISPECT_( app_context, global_buffer, REF, buffer )
ISPECT_( app_context, current_buffer, REF, buffer )
{}
};
static struct ispect g_ctx_ispect =
{
.fields = g_ctx_ispect_fields,
};
static int * static int *
filter_color_cube_for_acceptable_nick_colors (size_t *len) filter_color_cube_for_acceptable_nick_colors (size_t *len)
{ {
@ -8570,6 +8582,8 @@ lua_weak_push (struct lua_plugin *plugin, void *object,
wrapper->plugin = plugin; wrapper->plugin = plugin;
wrapper->info = info; wrapper->info = info;
wrapper->object = object; wrapper->object = object;
wrapper->weak_ref = NULL;
if (info->ref)
wrapper->weak_ref = info->ref (object, lua_weak_invalidate, wrapper); wrapper->weak_ref = info->ref (object, lua_weak_invalidate, wrapper);
lua_cache_store (L, object, -1); lua_cache_store (L, object, -1);
} }
@ -8581,6 +8595,7 @@ lua_weak_gc (lua_State *L, const struct lua_weak_info *info)
if (wrapper->object) if (wrapper->object)
{ {
lua_cache_invalidate (L, wrapper->object); lua_cache_invalidate (L, wrapper->object);
if (info->unref)
info->unref (wrapper->object, &wrapper->weak_ref); info->unref (wrapper->object, &wrapper->weak_ref);
wrapper->object = NULL; wrapper->object = NULL;
} }
@ -8616,6 +8631,14 @@ LUA_WEAK_DECLARE (channel, XLUA_CHANNEL_METATABLE)
LUA_WEAK_DECLARE (buffer, XLUA_BUFFER_METATABLE) LUA_WEAK_DECLARE (buffer, XLUA_BUFFER_METATABLE)
LUA_WEAK_DECLARE (server, XLUA_SERVER_METATABLE) LUA_WEAK_DECLARE (server, XLUA_SERVER_METATABLE)
// The global context is kind of fake and don't have any ref-counting,
// however it's still very much an object
static struct lua_weak_info lua_ctx_info =
{
.name = PROGRAM_NAME,
.ispect = &g_ctx_ispect,
};
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
static int static int
@ -9730,8 +9753,18 @@ lua_plugin_connect (lua_State *L)
return 1; return 1;
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
static int
lua_ctx_gc (lua_State *L)
{
return lua_weak_gc (L, &lua_ctx_info);
}
static luaL_Reg lua_plugin_library[] = static luaL_Reg lua_plugin_library[] =
{ {
// These are global functions:
{ "parse", lua_plugin_parse }, { "parse", lua_plugin_parse },
{ "hook_input", lua_plugin_hook_input }, { "hook_input", lua_plugin_hook_input },
{ "hook_irc", lua_plugin_hook_irc }, { "hook_irc", lua_plugin_hook_irc },
@ -9739,6 +9772,10 @@ static luaL_Reg lua_plugin_library[] =
{ "hook_timer", lua_plugin_hook_timer }, { "hook_timer", lua_plugin_hook_timer },
{ "setup_config", lua_plugin_setup_config }, { "setup_config", lua_plugin_setup_config },
{ "connect", lua_plugin_connect }, { "connect", lua_plugin_connect },
// And these are methods:
{ "__gc", lua_ctx_gc },
// TODO: get_prompt_ignore_markers()
{ NULL, NULL }, { NULL, NULL },
}; };
@ -9908,7 +9945,6 @@ lua_plugin_reg_finish (lua_State *L, struct lua_weak_info *info)
lua_setfield (L, -2, "__index"); lua_setfield (L, -2, "__index");
lua_pushcfunction (L, lua_plugin_property_set); lua_pushcfunction (L, lua_plugin_property_set);
lua_setfield (L, -2, "__newindex"); lua_setfield (L, -2, "__newindex");
lua_pop (L, 1); lua_pop (L, 1);
} }
@ -9948,12 +9984,17 @@ lua_plugin_load (struct app_context *ctx, const char *filename,
plugin->ctx = ctx; plugin->ctx = ctx;
plugin->L = L; plugin->L = L;
// Register the degesch library with "plugin" as an upvalue
luaL_checkversion (L); luaL_checkversion (L);
luaL_newlibtable (L, lua_plugin_library);
// Register the degesch library as a singleton with "plugin" as an upvalue
// (mostly historical, but rather convenient)
luaL_newmetatable (L, lua_ctx_info.name);
lua_pushlightuserdata (L, plugin); lua_pushlightuserdata (L, plugin);
luaL_setfuncs (L, lua_plugin_library, 1); luaL_setfuncs (L, lua_plugin_library, 1);
lua_setglobal (L, PROGRAM_NAME); lua_plugin_reg_finish (L, &lua_ctx_info);
lua_weak_push (plugin, ctx, &lua_ctx_info);
lua_setglobal (L, lua_ctx_info.name);
// Create metatables for our objects // Create metatables for our objects
lua_plugin_reg_meta (L, XLUA_HOOK_METATABLE, lua_hook_table); lua_plugin_reg_meta (L, XLUA_HOOK_METATABLE, lua_hook_table);