GithubHelp home page GithubHelp logo

ffi-reflect's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ffi-reflect's Issues

Reflecting over substructs

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?

LuaJIT 2.1

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...

test crash

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.

Possibility of implementing the `TODO: CTA_QUAL` ?

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

Failed test on line 105 under LuaJIT 2.0.5

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?

Support luajit 2.1 LJ_GC64 mode

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.

GC64 and CType declaration

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.