A foreign function interface (FFI) is a mechanism by which a program written in one programming language can call routines or make use of services written or compiled in another one. An FFI is often used in contexts where calls are made into binary dynamic-link library.
Lua-ffi is a portable lightweight C FFI for Lua, based on libffi and aiming to be mostly compatible with LuaJIT FFI, but written from scratch in C language.
local ffi = require 'ffi'
ffi.cdef([[
struct timeval {
time_t tv_sec; /* seconds */
suseconds_t tv_usec; /* microseconds */
};
int gettimeofday(struct timeval *tv, struct timezone *tz);
char *strerror(int errnum);
]])
local function strerror(errno)
return ffi.string(ffi.C.strerror(errno))
end
local tv = ffi.new('struct timeval')
if ffi.C.gettimeofday(tv, nil) < 0 then
print('gettimeofday fail:', strerror(ffi.errno()))
else
print('tv.tv_sec:', tv.tv_sec, 'tv.tv_usec:', tv.tv_usec)
end
void bool char short int long float double
int8_t int16_t int32_t int64_t uint8_t uint16_t uint32_t uint64_t
ino_t dev_t gid_t mode_t nlink_t uid_t off_t pid_t size_t ssize_t useconds_t suseconds_t blksize_t blkcnt_t time_t
sudo apt install -y liblua5.3-dev libffi-dev
git clone https://github.com/zhaojh329/lua-ffi.git
cd lua-ffi && mkdir build && cd build
cmake .. && sudo make install
Languages --->
Lua --->
<> lua-ffi............ A portable lightweight C FFI for lua5.1, based on libffi
<> lua-ffi-lua5.3..... A portable lightweight C FFI for lua5.3, based on libffi
<*> lua-ffi-lua5.4..... A portable lightweight C FFI for lua5.4, based on libffi
This project was inspired by the following repositories:
Thanks to the authors of these repositories for their excellent work.
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。
1. Open source ecosystem
2. Collaboration, People, Software
3. Evaluation model