Skip to content

Is it possible to somehow enumerate declared functions using ffi-reflect? #6

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
ppiecuch opened this issue Mar 8, 2020 · 1 comment

Comments

@ppiecuch
Copy link

ppiecuch commented Mar 8, 2020

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

@sonoro1234
Copy link

Inspired by LuaJIT/LuaJIT#745

ffi = require "ffi"

local CTs = {[0] =
"int","struct","ptr","array","void","enum","func","typedef","attrib","field","bitfield","constant","extern","kw"}

local function count_ctypes()
    local cnt = 0
    for i = 1, math.huge do
        local t = ffi.typeinfo(i)
        if t == nil then
            print(cnt)
            break
        end
        t.what = CTs[bit.rshift(t.info, 28)]
        if t.what=="func" then
            print(i,t.name,t.what)
        end
        cnt = cnt + 1
    end
end

count_ctypes()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants