Where do I put external c libs? (luasec on macOS)

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
User avatar
andras
Prole
Posts: 14
Joined: Thu Jun 14, 2018 12:03 pm

Where do I put external c libs? (luasec on macOS)

Post by andras »

Hi there,

I'd like to send HTTPS requests out of my game. I gather from the forums that I need luasec for that. OK, I acquired luasec via luarocks, it is installed here on my machine:

Code: Select all

/usr/local/share/lua/5.1/ssl.lua
/usr/local/share/lua/5.1/ssl/https.lua
/usr/local/lib/lua/5.1/ssl.so
I can now send https requests easily with local https = require 'ssl.https'. I just require 'ssl.https' instead of 'socket.http' and everything works. Amazing.

Except it only works on my machine. My game now depends on the stuff under /usr/local/, if I remove them to simulate being on a random Mac, I get an error "module 'ssl.core' not found". OK then, I'll copy the two lua files and the shared object to my project directory, next to my main.lua. Great, everything works again.

I now make a fused distribution for macOS following the usual guide. I make sure to include ssl.so in my .love file (next to main.lua). No luck.

Code: Select all

Error

ssl.lua:8: module 'ssl.core' not found:
no field package.preload['ssl.core']
no 'ssl/core' in LOVE game directories.
no file 'ssl/core' in LOVE paths.
no file './ssl/core.lua'
no file '/usr/local/share/luajit-2.0.5/ssl/core.lua'
no file '/usr/local/share/lua/5.1/ssl/core.lua'
no file '/usr/local/share/lua/5.1/ssl/core/init.lua'
no file './ssl/core.so'
no file '/usr/local/lib/lua/5.1/ssl/core.so'
no file '/usr/local/lib/lua/5.1/loadall.so'
no file './ssl.so'
no file '/usr/local/lib/lua/5.1/ssl.so'
no file '/usr/local/lib/lua/5.1/loadall.so'
no module 'ssl.core' in LOVERocks path.
no library 'ssl/core.so' in LOVERocks path.
no library 'ssl/.so' in LOVERocks path.
Note that LOVE does try to load './ssl.so'. I also tried to copy ssl.so next to the SuperGame.love file to the folder SuperGame.app/Contents/Resources, alas, I still get the same output. If I copy back ssl.so to /usr/local/lib/lua/5.1, the app starts successfully in fused mode, and sends HTTPS requests like a champ.

So my question: where do I put external C libraries such as luasec's ssl.so so that it works in fused mode? Thanks a lot!
User avatar
pgimeno
Party member
Posts: 3683
Joined: Sun Oct 18, 2015 2:58 pm

Re: Where do I put external c libs? (luasec on macOS)

Post by pgimeno »

I've no idea why it doesn't work out of the box, given that the docs for love.filesystem.setCRequirePath seem to imply that PhysFS is used to search for C modules.

But as a workaround, if you can place the file in a path that you can locate at run time (e.g. using love.filesystem.getSourceBaseDirectory or similar), you can add this line before your 'require' call:

Code: Select all

package.preload['ssl.core'] = package.loadlib(path_to_ssl_so, 'luaopen_ssl_core')
User avatar
andras
Prole
Posts: 14
Joined: Thu Jun 14, 2018 12:03 pm

Re: Where do I put external c libs? (luasec on macOS)

Post by andras »

Thank you, I got it working. It tried to load several other submodules too, so I had to pre-load them as well.

Code: Select all

local base = love.filesystem.getSourceBaseDirectory()
for _, mod in pairs({'core', 'context', 'config', 'x509'}) do
  package.preload['ssl.'..mod] = package.loadlib(base..'/ssl.so', 'luaopen_ssl_'..mod)
end
local https = require 'ssl.https'
And I have to bundle ssl.so next to my .love file, so under Contents/Resources because that seems to be the base directory in fused mode.

Now, onto the windows build!
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Bing [Bot], Google [Bot] and 12 guests