Discussion:
How to create namespace without ffi.load()?
Tomash Brechko
2014-09-18 14:48:49 UTC
Permalink
Hello!

Is there a way to create new FFI namespace without ffi.load()? If not, is
it possible to add something like

local mylib = ffi.namespace()

so that after that mylib.cdef() operates on mylib.C that is private to
mylib. I see the following rational for this: when you embed LuaJIT into
larger application you often already linked all required libraries with
that application. Build process may be quite complex and may pull
libraries from non-standard locations, so on LuaJIT part you may simply not
know what name/path pass to ffi.load(). Yet you may still want to use
separate namespace together with __asm__("name") renaming to be able to
call mylib.Func() instead of mylib.mylibprefixFunc() (and to not leak
unrelated C functions through mylib). Even when library name is known
ability to create separate "interface views" may have its uses for the sake
of sandboxing.

Or am I missing some pure-Lua trick that will solve the problem without
requiring

mylib.Func = C.mylibprefixFunc

which is advised against in the docs?
--
Tomash Brechko
Loading...