[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: dependencies between C modules, RTLD_GLOBAL
- From: Josh Haberman <jhaberman@...>
- Date: Wed, 13 May 2015 13:03:40 -0700
On Tue, May 12, 2015 at 7:16 PM, Jonathan Goble <email@example.com> wrote:
> On Tue, May 12, 2015 at 9:42 PM, Josh Haberman <firstname.lastname@example.org> wrote:
>> Since package.loadlib bypasses require(), it seems like this approach
>> will involve re-implementing the require() logic? Stuff like checking
>> package.preload, splitting LUA_CPATH on ";", looking in each
>> directory, etc?
> Yes, you'd have to check package.preload, but if not found there,
> `package.searchpath(libname, package.cpath)` ought to return the
> filename for passing to package.loadlib.
I tried this out and it seems to work!
One caveat: require() will load the module RTLD_LOCAL. On OS X at
least, it appears that once you load a module as RTLD_LOCAL,
subsequent loads as RTLD_GLOBAL don't appear to have any effect.
So ultimately my a.lua looks like this:
-- Ensure the library is loaded as RTLD_GLOBAL.
package.loadlib(package.searchpath("a_cext", package.cpath), "*")
-- Let require load the module in the normal way.
Turning these two statements around makes it not work anymore! This
also means I probably need to do a bit more work to give a nicer error
message if the first load fails (for example, if LUA_CPATH was set