| 1 |
--[[ |
| 2 |
Copyright (c) 2022, Vsevolod Stakhov <[email protected]> |
| 3 |
|
| 4 |
Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 |
you may not use this file except in compliance with the License. |
| 6 |
You may obtain a copy of the License at |
| 7 |
|
| 8 |
http://www.apache.org/licenses/LICENSE-2.0 |
| 9 |
|
| 10 |
Unless required by applicable law or agreed to in writing, software |
| 11 |
distributed under the License is distributed on an "AS IS" BASIS, |
| 12 |
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 |
See the License for the specific language governing permissions and |
| 14 |
limitations under the License. |
| 15 |
]]-- |
| 16 |
|
| 17 |
--[[[ |
| 18 |
-- @module lua_ffi |
| 19 |
-- This module contains ffi interfaces (requires luajit or lua-ffi) |
| 20 |
--]] |
| 21 |
|
| 22 |
local ffi |
| 23 |
|
| 24 |
local exports = {} |
| 25 |
|
| 26 |
if type(jit) == 'table' then |
| 27 |
ffi = require "ffi" |
| 28 |
local NULL = ffi.new 'void*' |
| 29 |
|
| 30 |
exports.is_null = function(o) |
| 31 |
return o ~= NULL |
| 32 |
end |
| 33 |
else |
| 34 |
local ret, result_or_err = pcall(require, 'ffi') |
| 35 |
|
| 36 |
if not ret then |
| 37 |
return {} |
| 38 |
end |
| 39 |
|
| 40 |
ffi = result_or_err |
| 41 |
-- Lua ffi |
| 42 |
local NULL = ffi.NULL or ffi.C.NULL |
| 43 |
exports.is_null = function(o) |
| 44 |
return o ~= NULL |
| 45 |
end |
| 46 |
end |
| 47 |
|
| 48 |
pcall(ffi.load, "rspamd-server", true) |
| 49 |
exports.common = require "lua_ffi/common" |
| 50 |
exports.dkim = require "lua_ffi/dkim" |
| 51 |
exports.spf = require "lua_ffi/spf" |
| 52 |
exports.linalg = require "lua_ffi/linalg" |
| 53 |
|
| 54 |
for k, v in pairs(ffi) do |
| 55 |
-- Preserve all stuff to use lua_ffi as ffi itself |
| 56 |
exports[k] = v |
| 57 |
end |
| 58 |
|
| 59 |
return exports |