lua-users home
lua-l archive

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


2011/2/21 Mike Pall <mikelu-1102@mike.de>:
> 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: http://lua-users.org/lists/lua-l/2011-01/msg01282.html

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
http://lua-users.org/lists/lua-l/2011-01/msg01379.html

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
end

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?