lua-users home
lua-l archive

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


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