lua-users home
lua-l archive

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

On Thu, Jan 19, 2012 at 6:27 PM, Mike Pall <> wrote:
> Sadly, the underlying OS APIs (e.g. dlopen/dlsym) do not support
> such a functionality. You'd need to probe all symbols (...)

Would it be possible to have a function that just probes the one symbol?

The use case I have in mind is an FFI-based Lua script that does one of these:
- load a set of functions statically linked and exported by the
executable itself
- load the same set of functions dynamically linked from a DLL/shared object
- fail, *without* polluting cdef

So, it would look something like:

  local exporter
  if ffi.exports(ffi.C, 'known_function') then
    exporter = ffi.C
    exporter = ffi.load 'known_module' -- error here if not found
  ffi.cdef [[
    void known_function();
    void another_known_function();
    /* ... rest of definition ... */
  return exporter

Of course I could just move one bit of cdef for known_function() up to
the top, and pcall a function that tests for its presence in ffi.C.
But I'd prefer it if it was possible to keep things clean and not add
anything to cdef on failure.