[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: [LuaJIT FFI feature request] ffi.load name transformation callback
- From: Mike Pall <mikelu-1201@...>
- Date: Thu, 19 Jan 2012 19:27:38 +0100
Adam Strzelecki wrote:
> It would be great ffi.load could let use specify name
> transformation function (callback):
There's a perfectly suitable Lua feature for generating all kinds
of namespaces of your own: a proxy table, i.e. a table with a
metatable and __index/__newindex methods. You could also use
newproxy(), which is slightly more efficient, unless you want to
put extra symbols into the proxy table.
> It would save a lot of typing for sure especially for libs using
> long prefixes.
The downside is that searching for e.g. 'begin' is hopeless, but
'glBegin' would give you all the needed info. Also note that code
is more often read than written.
> Also it would be nice if we could enumerate symbols specified by
> cdef present in particular library. This would give us
> possibility also to check presence of particular symbol without
> raising error.
>
> for obj, name, type in ffi.symbols(gl) do
> -- do something
> end
Sadly, the underlying OS APIs (e.g. dlopen/dlsym) do not support
such a functionality. You'd need to probe all symbols or dive down
into the OS-specific file formats of shared libraries (and handle
all the name mangling that the dynamic loader does on its own, too).
--Mike