summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--degesch.c21
1 files changed, 10 insertions, 11 deletions
diff --git a/degesch.c b/degesch.c
index 03b5318..8f8424a 100644
--- a/degesch.c
+++ b/degesch.c
@@ -8018,12 +8018,13 @@ lua_plugin_add_config_schema (struct lua_plugin *plugin,
schema->comment = xstrdup (lua_tostring (L, -1));
if (lua_plugin_check_field (L, values, "default", LUA_TSTRING, true))
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
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_error = LUA_REFNIL;
- if (lua_plugin_check_field (L, 3, "on_success", LUA_TFUNCTION, true))
- self->ref_on_success = luaL_ref (L, -1);
- if (lua_plugin_check_field (L, 3, "on_error", LUA_TFUNCTION, true))
- self->ref_on_error = luaL_ref (L, -1);
-
- lua_pop (L, 2);
+ (void) lua_plugin_check_field (L, 3, "on_success", LUA_TFUNCTION, true);
+ self->ref_on_success = luaL_ref (L, LUA_REGISTRYINDEX);
+ (void) lua_plugin_check_field (L, 3, "on_error", LUA_TFUNCTION, true);
+ self->ref_on_error = luaL_ref (L, LUA_REGISTRYINDEX);
struct app_context *ctx = plugin->ctx;
struct connector *connector = &self->connector;