]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-lua: Use rawget to check presence of functions in scripts
authorSiavash Tavakoli <siavash.tavakoli@open-xchange.com>
Tue, 7 Sep 2021 14:03:37 +0000 (15:03 +0100)
committertimo.sirainen <timo.sirainen@open-xchange.com>
Fri, 17 Sep 2021 11:47:15 +0000 (11:47 +0000)
With the restricted global variables in next commit, checking for
undeclared functions results in error. Use rawget to avoid metamethods.

src/lib-lua/dlua-script.c

index 31fa69793a272cecdd5dcc82c4918dae6b0373e4..48fe286bb674e0e230a52a1d270cdf494fc86ec6 100644 (file)
@@ -381,9 +381,11 @@ void dlua_script_unref(struct dlua_script **_script)
 bool dlua_script_has_function(struct dlua_script *script, const char *fn)
 {
        i_assert(script != NULL);
-       lua_getglobal(script->L, fn);
+       lua_getglobal(script->L, "_G");
+       lua_pushstring(script->L, fn);
+       lua_rawget(script->L, -2);
        bool ret = lua_isfunction(script->L, -1);
-       lua_pop(script->L, 1);
+       lua_pop(script->L, 2);
        return ret;
 }