lua-users home
lua-l archive

LuaJIT: userdata and FFI cdata (was: Re: LuaJIT 2 ffi (casting / force hotpath))

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


* Mike Pall:
> The FFI treats userdata like a 'void *' pointing to the payload.
> So you can assign or cast it to a pointer to a struct and then
> access its fields:
>
> ffi.cdef[[
> typedef struct { int x; } foo_t;
> ]]
> local tostruct = ffi.typeof("foo_t *")
> local function inc_x(ud)
> local s = tostruct(ud)
> s.x = s.x + 1
> end
However, it seems that there is no way to create a userdata object
which is not zero-sized. Am I missing something?

AltStyle によって変換されたページ (->オリジナル) /