summaryrefslogtreecommitdiff
path: root/degesch.c
diff options
context:
space:
mode:
authorPřemysl Janouch <p.janouch@gmail.com>2016-01-09 02:39:26 +0100
committerPřemysl Janouch <p.janouch@gmail.com>2016-01-09 05:01:50 +0100
commit64143a5957f0ed662beca839bcf570c374c98eb4 (patch)
treef0cad760f9f6cd5977457ee7d7dc81ad2d9cfa0d /degesch.c
parentaca153f5750cabfb7ccf0fc0cb5a05a83ed2d026 (diff)
downloadxK-64143a5957f0ed662beca839bcf570c374c98eb4.tar.gz
xK-64143a5957f0ed662beca839bcf570c374c98eb4.tar.xz
xK-64143a5957f0ed662beca839bcf570c374c98eb4.zip
degesch: Lua: fix luaL_ref() usage
Diffstat (limited to 'degesch.c')
-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;