1
0
mirror of https://github.com/lxsang/antd-lua-plugin synced 2025-01-01 03:58:22 +01:00
antd-lua-plugin/lib/ffi/example/example.lua

44 lines
1.3 KiB
Lua
Raw Normal View History

2019-05-01 22:06:48 +02:00
require("cif")
local path = "/Users/mrsang/Google Drive/ushare/cwp/ant-http/plugins/antd-lua-plugin/lib/ffi/example/libtest.so"
2019-04-30 20:09:07 +02:00
local lib = nil
local fn = nil
local rettype = nil
local argtype = nil
2019-05-01 22:06:48 +02:00
lib = FFI.load(path)
if lib then
-- now try to lookup for the greet function
echo("looking for greet")
fn = FFI.lookup(lib,"greet")
if fn then
-- now the function found
-- tried to called it
rettype = FFI.atomic(FFI.type.VOID) -- void
if rettype then
argtype = {
FFI.atomic(FFI.type.POINTER),
FFI.atomic(FFI.type.DOUBLE),
FFI.atomic(FFI.type.SINT64),
FFI.atomic(FFI.type.SINT8)
} -- pointer
if(argtype) then
-- call the function
local r = FFI.call(rettype, argtype, fn, {"hello world", 0.987, -76, 65})
if r then
echo("BIG SUCCESS")
2019-04-30 20:09:07 +02:00
else
2019-05-01 22:06:48 +02:00
echo("HELL FAIL")
2019-04-30 20:09:07 +02:00
end
else
2019-05-01 22:06:48 +02:00
echo("argtype not found")
2019-04-30 20:09:07 +02:00
end
else
2019-05-01 22:06:48 +02:00
echo("return type not found")
2019-04-30 20:09:07 +02:00
end
else
2019-05-01 22:06:48 +02:00
echo("unable to find greet")
2019-04-30 20:09:07 +02:00
end
2019-05-01 22:06:48 +02:00
FFI.unloadAll()
2019-04-30 20:09:07 +02:00
else
2019-05-01 22:06:48 +02:00
echo("unable to load the lib")
2019-04-30 20:09:07 +02:00
end
echo("end the day")