Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LUA_PATH must contain /usr/share/lua and /usr/lib/x86_64-linux-gnu/lua/ #2303

Open
yurtpage opened this issue Apr 10, 2024 · 0 comments
Open

Comments

@yurtpage
Copy link

I have a script that require("socket.unix") and the library is installed in Ubuntu with apt install lua-socket.

But the OpenResty can't resolve the library:

 no file '/usr/local/lib/lua/5.1/socket.so'

This is because it's not it the /usr/local/lib/lua/ but in /usr/lib/x86_64-linux-gnu/lua/.
But this will work if a library was installed with luarocks because it's indeed uses the /usr/local/lib/lua/.

I tried to solve this by adding lua_package_path and lua_package_cpath like this:

  # By default Lua libraies are looked in the /usr/local/share/lua/ and /usr/local/lib/lua/ but must look into /usr/share/lua/ and /usr/lib/x86_64-linux-gnu/lua/
  # set search paths for pure Lua external libraries (';;' is the default path):
  lua_package_path '/usr/share/lua/5.1/?.lua;;';
  # set search paths for Lua external libraries written in C (can also use ';;'):
  lua_package_cpath '/usr/lib/x86_64-linux-gnu/lua/5.1/?.so;;';

This partially solved a problem but failed with another error attempt to call method 'get_certificate' (a nil value).
This is probably because packages has own directories that also needs to be added recursively.
I had to add them manually like this:

  # By default Lua libraies are looked in the /usr/local/share/lua/ and /usr/local/lib/lua/ but must look into /usr/share/lua/ and /usr/lib/x86_64-linux-gnu/lua/
  # set search paths for pure Lua external libraries (';;' is the default path):
  lua_package_path '/usr/share/lua/5.1/?.lua;/usr/share/lua/5.1/socket/?.lua;/usr/share/lua/5.1/ssl/?.lua;;';
  # set search paths for Lua external libraries written in C (can also use ';;'):
  lua_package_cpath '/usr/lib/x86_64-linux-gnu/lua/5.1/?.so;/usr/lib/x86_64-linux-gnu/lua/5.1/socket/?.so;/usr/lib/x86_64-linux-gnu/lua/5.1/mime/?.so;;';

This again didn't worked, don't know why. Anyway this solution would be fragile. Once a new library with own folder installed it also should be manually added to the path.

The only solution that worked was to create symlinks:

ln -s /usr/share/lua /usr/local/share/
ln -s /usr/lib/x86_64-linux-gnu/lua/ /usr/local/lib/

This is not something that I like but solves the problem for now.

I wish to hear how to solve this correctly. At least please add more examples to the lua_package_path and lua_package_cpath.

@yurtpage yurtpage changed the title LUA_PATH must contain /usr/share/lua and LUA_PATH must contain /usr/share/lua and /usr/lib/x86_64-linux-gnu/lua/ Apr 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant