lua-users home
lua-l archive

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


Michal Kottman wrote:
> I'm trying to add some kind of introspection to LuaJIT FFI, that will
> allow to determine not only the type of a cdata object, but also list
> it's fields.

Wouldn't it be easier to copy the data structure declarations from
lj_ctype.h, export the root of the type tree and then use Lua code
and the FFI to do the introspection?

> However, it fails when I pass an instance/cdata object of such
> type.

It shouldn't fail for a struct, but you're probably looking at a
pointer or a reference to a struct.

> When looking at ct->info, it is CT_PTR. How can I get to the
> structure this pointer refers to? I've tried using ct =
> ctype_child(cts, ct), but it fails later on setstrV() with assertion
> error.

if (ctype_isptr(ct->info)) ct = ctype_rawchild(cts, ct);

> I have a feeling I am abusing things I should not be touching :).

Well, depends on how adventurous you are. :-)

--Mike