local ffi = jit and require('ffi') or require('cffi')
ffi.cdef[[
//typedef intptr_t ssize_t;
ssize_t write(int fd, const void *buf, size_t count);
]]
local s = "hello world\n"
ffi.C.write(1, s, #s) --> expected: no error, get: cannot convert 'string' to 'void const *'
The LuaJIT FFI will happily cast a string to a const void * (but not to void *, understandably), which is useful for interacting with C functions dealing with byte strings (e.g. file descriptor I/O, sockets, etc.). cffi-lua doesn't support this without an explicit cast ffi.cast('const void *', s).
The LuaJIT FFI will happily cast a string to a
const void *
(but not tovoid *
, understandably), which is useful for interacting with C functions dealing with byte strings (e.g. file descriptor I/O, sockets, etc.). cffi-lua doesn't support this without an explicit castffi.cast('const void *', s)
.