lua-users home
lua-l archive

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

On Wed, May 13, 2015 at 01:03:40PM -0700, Josh Haberman wrote:
> On Tue, May 12, 2015 at 7:16 PM, Jonathan Goble <> wrote:
> > On Tue, May 12, 2015 at 9:42 PM, Josh Haberman <> 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.

That's because Lua will only load the library once, regardless of the
scoping. As it's already been loaded before it won't call dlopen again with
RTLD_GLOBAL, but instead uses the cached handle.

See ll_loadfunc in the Lua 5.2 source and lookforfunc in the 5.3 source.