corsix / ffi-reflect Goto Github PK
View Code? Open in Web Editor NEWLuaJIT FFI reflection library
LuaJIT FFI reflection library
Hi,
Let me first say that I'm quite excited about your reflection library and currently testing it out.
Concretely, I'm trying to iterate over the fields of substructs and it doesn't seem to work in the cases where I'd need it to. Maybe you have some advice. Here's what I am doing.
The following slightly shortened example from the docs works:
for refct in reflect.typeof[[
struct {
int a;
union { int b; int c; };
struct { int e; int f; };
}
]]:members() do print(refct.what) end --> field, union, struct
Naming the outer struct has the fields of the inner struct inlined(?) but they can still be iterated.
-- from https://github.com/corsix/ffi-reflect/blob/master/test.lua
local function rec_members(refct, f)
if refct.members then
for refct in refct:members() do
rec_members(refct, f)
end
else
f(refct)
end
end
ffi.cdef [[
struct Test1 {
int a;
union { int b; int c; };
struct { int e; int f; };
};
]]
rec_members(reflect.typeof("struct Test1"), function(rc) print(rc.what) print(rc.name) end)
--> field a field b field c field e field f
If I name the inner struct, I cannot access its fields at all.
ffi.cdef [[
struct Inner { int e; int f; };
struct Test2 {
int a;
union { int b; int c; };
struct Inner inner;
};
]]
rec_members(reflect.typeof("struct Test2"), function(rc) print(rc.what) print(rc.name) end)
--> field a field b field c field inner
Is there another way to make this work? Any chance that getting this only requires a small change?
I see there are alas differences in LuaJIT 2.1. It is probably a moving target, so may be too early to look at it...
Running test.lua in windows7 LuaJIT 2.1 Mingw-W64 compiled for 32 bits gives a crash. (no info on gdb)
Inserting do return end
before line 142 crash is gone.
Hello, I'm encountering the following
ffi.cdef[[ struct ImVec4 { float x,y,z,w; }; ]]
reflect.typeof(ffi.typeof(" struct ImVec4")) -- okay
reflect.typeof(ffi.typeof("const struct ImVec4")) -- complains due to some TODO
error :
./reflect.lua:208: TODO: CTA_QUAL
stack traceback:
[C]: in function 'error'
./reflect.lua:208: in function 'CTA'
./reflect.lua:281: in function 'typeof'
which is into those lines belonging to reflect.lua
:
-- Logic for merging an attribute CType onto the annotated CType.
local CTAs = {[0] =
function(a, refct) error("TODO: CTA_NONE") end,
function(a, refct) error("TODO: CTA_QUAL") end, <<< ERROR THERE
function(a, refct)
a = 2^a.value
refct.alignment = a
refct.attributes.align = a
end,
function(a, refct)
refct.transparent = true
refct.attributes.subtype = refct.typeid
end,
function(a, refct) refct.sym_name = a.name end,
function(a, refct) error("TODO: CTA_BAD") end,
}
The "types" that I get in input are not under my control, I get those const ImVec4
from a 3rd party : https://github.com/cimgui/cimgui/blob/docking_inter/generator/output/definitions.lua
Of course I could also workaround my problem by tricking my code into stripping the const
problematics to reflect.typeof()
Would you have time... to do... this TODO: CTA_QUAL
? :)
Thanks,
Kind Regards
The assertion on line 105 of the bundled test.lua fails.
Here, element_type.convention is 'cdecl' rather than 'stdcall'.
Is this to be expected, or is there something weird happening?
Hello - I guess I would like to iterate over tab table:
(CTState or init_CTState()).tab
Could you suggest how could I do this?
Regards
Pawel
Hello,
Recently LuaJIT 2.1 branch enabled LJ_GC64
mode by default. It would be great to have support for it, I find this library very useful.
Currently on x86_64 reflect.getmetatable()
is giving me Segmentation fault
.
Hello, I have noticed that name field in CType is uint32_t:
uint32_t name;
In GC64 mode this field (GCref) is uint64_t - is it intentionally?
Regards
Pawel
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.