commit 98591e3: [Minor] Make lua_ffi more flexible to use

Vsevolod Stakhov vsevolod at highsecure.ru
Tue Aug 4 14:35:08 UTC 2020


Author: Vsevolod Stakhov
Date: 2020-08-04 13:11:27 +0100
URL: https://github.com/rspamd/rspamd/commit/98591e36dbdfa483130d200dbe3423611dfbab81

[Minor] Make lua_ffi more flexible to use

---
 lualib/lua_ffi/init.lua  | 8 ++++++--
 lualib/rspamadm/mime.lua | 5 +++++
 2 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/lualib/lua_ffi/init.lua b/lualib/lua_ffi/init.lua
index e5ca24a11..02b54f932 100644
--- a/lualib/lua_ffi/init.lua
+++ b/lualib/lua_ffi/init.lua
@@ -34,8 +34,7 @@ else
   local ret,result_or_err = pcall(require, 'ffi')
 
   if not ret then
-    io.stderr:write('FFI support is required: please use LuaJIT or install lua-ffi')
-    os.exit(1)
+    return {}
   end
 
   ffi = result_or_err
@@ -51,4 +50,9 @@ exports.common = require "lua_ffi/common"
 exports.dkim = require "lua_ffi/dkim"
 exports.spf = require "lua_ffi/spf"
 
+for k,v in pairs(ffi) do
+  -- Preserve all stuff to use lua_ffi as ffi itself
+  exports[k] = v
+end
+
 return exports
\ No newline at end of file
diff --git a/lualib/rspamadm/mime.lua b/lualib/rspamadm/mime.lua
index 06b163d9b..c8b1f8450 100644
--- a/lualib/rspamadm/mime.lua
+++ b/lualib/rspamadm/mime.lua
@@ -754,6 +754,11 @@ local function sign_handler(opts)
 
   local lua_dkim = require("lua_ffi").dkim
 
+  if not lua_dkim then
+    io.stderr:write('FFI support is required: please use LuaJIT or install lua-ffi')
+    os.exit(1)
+  end
+
   local sign_key
   if rspamd_util.file_exists(opts.key) then
     sign_key = lua_dkim.load_sign_key(opts.key, 'file')


More information about the Commits mailing list