degesch: Lua: fix luaL_ref() usage

This commit is contained in:
Přemysl Eric Janouch 2016-01-09 02:39:26 +01:00
parent aca153f575
commit 64143a5957

View File

@ -8018,12 +8018,13 @@ lua_plugin_add_config_schema (struct lua_plugin *plugin,
schema->comment = xstrdup (lua_tostring (L, -1)); schema->comment = xstrdup (lua_tostring (L, -1));
if (lua_plugin_check_field (L, values, "default", LUA_TSTRING, true)) if (lua_plugin_check_field (L, values, "default", LUA_TSTRING, true))
schema->default_ = xstrdup (lua_tostring (L, -1)); schema->default_ = xstrdup (lua_tostring (L, -1));
if (lua_plugin_check_field (L, values, "on_change", LUA_TFUNCTION, true))
self->ref_on_change = luaL_ref (L, -1);
if (lua_plugin_check_field (L, values, "validate", LUA_TFUNCTION, true))
self->ref_validate = luaL_ref (L, -1);
lua_pop (L, 5); lua_pop (L, 3);
(void) lua_plugin_check_field (L, values, "on_change", LUA_TFUNCTION, true);
self->ref_on_change = luaL_ref (L, LUA_REGISTRYINDEX);
(void) lua_plugin_check_field (L, values, "validate", LUA_TFUNCTION, true);
self->ref_validate = luaL_ref (L, LUA_REGISTRYINDEX);
// Try to install the created schema item into our configuration // Try to install the created schema item into our configuration
struct error *warning = NULL, *e = NULL; struct error *warning = NULL, *e = NULL;
@ -8460,12 +8461,10 @@ lua_plugin_connect (lua_State *L)
self->ref_on_success = LUA_REFNIL; self->ref_on_success = LUA_REFNIL;
self->ref_on_error = LUA_REFNIL; self->ref_on_error = LUA_REFNIL;
if (lua_plugin_check_field (L, 3, "on_success", LUA_TFUNCTION, true)) (void) lua_plugin_check_field (L, 3, "on_success", LUA_TFUNCTION, true);
self->ref_on_success = luaL_ref (L, -1); self->ref_on_success = luaL_ref (L, LUA_REGISTRYINDEX);
if (lua_plugin_check_field (L, 3, "on_error", LUA_TFUNCTION, true)) (void) lua_plugin_check_field (L, 3, "on_error", LUA_TFUNCTION, true);
self->ref_on_error = luaL_ref (L, -1); self->ref_on_error = luaL_ref (L, LUA_REGISTRYINDEX);
lua_pop (L, 2);
struct app_context *ctx = plugin->ctx; struct app_context *ctx = plugin->ctx;
struct connector *connector = &self->connector; struct connector *connector = &self->connector;