lua-users home
lua-l archive

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

2011/2/21 Mike Pall <>:
> Instead create the userdata from C code and keep the cdata _inside_
> the userdata. Cast the userdata to a pointer to your struct before
> using it:

Hi Mike,
would you officially provide a way to create userdata with payload
from Lua as a workaround? Basically an old request would help here

so that we could do following

local toobj = ffi.typeof("obj_t *")

meta = {__gc = function(ud) ffi.C.delobj( toobj (ud) ) end}
function myobj()
  local obj = ffi.C.newobj()
  local user = ffi.touserdata(obj,meta)  --userdata would have the
size of original cdata (i.e. pointer in this case)
  return user

if you think you rather not have that in the official jit, as the
feature might be removed with 2.1's gc, would it be possible to
manually make such a function as old-school Lua dll. Or is calling ffi
from gc always pure evil?