lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

On 2012-02-21 11:42, Olivier Goudron wrote:

I am testing LuaJIT FFI binding and i have a problem with this code :

local ffi = require("ffi")
struct slice{
  char *data;
  int len;
local sk ="struct slice")
sk.len = 3 = "key"
The last line cause LuaJIT to crash and the " = "key" assignement
complain with this message : cannot convert 'string' to 'char *'

LuaJIT is telling you what the problem is: you cannot just
assign a Lua string to a char* ctype. You need to allocate
the necessary memory and use ffi.copy.

tl;dr: replace the line: = "key"

by something like: ="char[4]")

Pierre 'catwell' Chapuis