Re: Using FFI as a plugin

  • From: Mike Pall <mike-1205@xxxxxxxxxx>
  • To: luajit@xxxxxxxxxxxxx
  • Date: Thu, 17 May 2012 20:41:45 +0200

Coda Highland wrote:
> My program is a plugin loaded into an external host, and I've
> discovered that the FFI is unable to resolve symbols defined in it
> because the host (for obvious reasons) doesn't load the plugin into
> the global symbol namespace.

Consider a two-step setup: load a tiny plugin that loads a shared
library containing all the rest into the global symbol namespace.

> Is there a way around this while still using the FFI? Perhaps a
> way to provide an explicit function pointer instead of relying
> on dlsym/GetProcAddress? I'd like to avoid the overhead and
> performance hit of wrapping all of my functions in
> Lua_CFunctions if at all possible.

You can pass a pointer to a struct of initialized function
pointers as lightuserdata from the C side, then ffi.cast that back
to the struct pointer on the Lua side. Ok, so there's a little bit
more duplicated stuff on each side. But the net effect is you're
able to just call lib.foo(...).

--Mike

Other related posts: