lua-users home
lua-l archive

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

I feel like I'm probably missing something obvious here, so forgive me
if this is a silly question.

The default package.cpath on linux has ./?.so and a few others, but it
seems like it also ought to have a ./lib?.so variant. Otherwise, I
have to take some awkward extra step depending on how I decide to load
the library.

When I compile a library called foo on my Linux box, I get a
file. If I want to load this into Lua, I thought I could just call
require "foo" as long as the .so file was in the directory with my
script, but that doesn't work because of the lib prefix.
I could instead call require "libfoo", but then I have to change the
name of the C function from luaopen_foo to luaopen_libfoo. And then it
breaks for windows unless I change the .dll to be called libfoo.dll
there too. I guess that's not terrible but that seems strange.
I could ship a foo.lua file with my .so/.dll that runs package.loadlib
on the appropriate file, but that needs to know the exact name of the
library, and I don't know how to have it check which environment it's
running so it can decide whether to attempt to open the dll or the
I could change the linux .so to not have the lib prefix, but I'm not
even sure how to do this with gcc automatically. AFAIK it
automatically prepends "lib" and I'd have to go change it manually
every time I recompile.

I feel like either I'm missing some connection here, that there ought
to be an easier way to go about this. it seems like if the cpath just
included lib?.so I could make a simple call to require and be done
with it, no need to ship any files except the .so/.dll itself.