|
On 2012-02-21 11:42, Olivier Goudron wrote:LuaJIT is telling you what the problem is: you cannot just
I am testing LuaJIT FFI binding and i have a problem with this code :
****
local ffi = require("ffi")
ffi.cdef[[
struct slice{
char *data;
int len;
};
]]
local sk = ffi.new("struct slice")
sk.len = 3
sk.data = ""> print(sk.len)
print(ffi.string(sk.data))
****
The last line cause LuaJIT to crash and the "sk.data = "" assignement
complain with this message : cannot convert 'string' to 'char *'
assign a Lua string to a char* ctype. You need to allocate
the necessary memory and use ffi.copy.
tl;dr: replace the line:
sk.data = "">
by something like:
sk.data = ""> ffi.copy(sk.data,"key")
--
Pierre 'catwell' Chapuis