summaryrefslogtreecommitdiffstats
path: root/src/lua
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@rspamd.com>2023-08-18 13:15:20 +0100
committerVsevolod Stakhov <vsevolod@rspamd.com>2023-08-18 13:15:20 +0100
commiteb6f412f8f2002b16f25dadf0464b4cde5797d7d (patch)
tree2372e7f6722864bb3701aaf4fffdff2a3072de97 /src/lua
parentdbaf8c69895ec2a90a20dbf41b4fa474ac12910b (diff)
downloadrspamd-eb6f412f8f2002b16f25dadf0464b4cde5797d7d.tar.gz
rspamd-eb6f412f8f2002b16f25dadf0464b4cde5797d7d.zip
[Minor] Allow rspamd_lua_require_function to work without function
Diffstat (limited to 'src/lua')
-rw-r--r--src/lua/lua_common.c48
1 files changed, 30 insertions, 18 deletions
diff --git a/src/lua/lua_common.c b/src/lua/lua_common.c
index d41e69822..5991af656 100644
--- a/src/lua/lua_common.c
+++ b/src/lua/lua_common.c
@@ -2251,33 +2251,45 @@ rspamd_lua_require_function(lua_State *L, const gchar *modname,
lua_remove(L, err_pos);
/* Now we should have a table with results */
- if (!lua_istable(L, -1)) {
- msg_warn("require of %s.%s failed: not a table but %s", modname,
- funcname, lua_typename(L, lua_type(L, -1)));
+ if (funcname) {
+ if (!lua_istable(L, -1)) {
+ msg_warn("require of %s.%s failed: not a table but %s", modname,
+ funcname, lua_typename(L, lua_type(L, -1)));
- lua_pop(L, 1);
+ lua_pop(L, 1);
- return FALSE;
- }
+ return FALSE;
+ }
- table_pos = lua_gettop(L);
- lua_pushstring(L, funcname);
- lua_gettable(L, -2);
+ table_pos = lua_gettop(L);
+ lua_pushstring(L, funcname);
+ lua_gettable(L, -2);
+
+ if (lua_type(L, -1) == LUA_TFUNCTION) {
+ /* Remove table, preserve just a function */
+ lua_remove(L, table_pos);
+
+ return TRUE;
+ }
+ else {
+ msg_warn("require of %s.%s failed: not a function but %s", modname,
+ funcname, lua_typename(L, lua_type(L, -1)));
+ }
- if (lua_type(L, -1) == LUA_TFUNCTION) {
- /* Remove table, preserve just a function */
- lua_remove(L, table_pos);
+ lua_pop(L, 2);
+ return FALSE;
+ }
+ else if (lua_isfunction(L, -1)) {
return TRUE;
}
else {
- msg_warn("require of %s.%s failed: not a function but %s", modname,
- funcname, lua_typename(L, lua_type(L, -1)));
- }
-
- lua_pop(L, 2);
+ msg_warn("require of %s failed: not a function but %s", modname,
+ lua_typename(L, lua_type(L, -1)));
+ lua_pop(L, 1);
- return FALSE;
+ return FALSE;
+ }
}
gint rspamd_lua_function_ref_from_str(lua_State *L, const gchar *str, gsize slen,