lua-users home
lua-l archive

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


On Tue, May 12, 2015 at 9:42 PM, Josh Haberman <jhaberman@gmail.com> wrote:
> On Tue, May 12, 2015 at 4:29 PM, Luiz Henrique de Figueiredo
> <lhf@tecgraf.puc-rio.br> wrote:
>>
>> Since Lua 5.2, package.loadlib accepts an optional argument that allows
>> you to use RTLD_GLOBAL. See
>>         http://www.lua.org/manual/5.3/manual.html#pdf-package.loadlib
>>
>> So the answer is to use package.loadlib directly.
>
> 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.

(Note that I'm basing this on a reading of the manual; I've never
actually had a need to do anything like this, so there may be
something here that I'm missing, but I don't think so.)