[SOLVED] How to require a shared or dynamic library and possible bug

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.
User avatar
bzSteve
Prole
Posts: 34
Joined: Tue May 21, 2013 2:31 am

Re: How to require a shared or dynamic library and possible bug

Post by bzSteve »

Thanks, pgimeno. In the past, it worked with the .so. If I modify the package.cpath to add ?.dylib, it works from the command line, but not when dragged to the LÖVE app. Same errors as before. I do have two identical copies of LÖVE 0.10.0 (one on the desktop and one in Applications) that both fail the same way.

The cpath is the same whether it passes or fails.

Code: Select all

./?.so;/usr/local/lib/lua/5.1/?.so;/Users/alex/Desktop/luajit/lib/lua/5.1/?.so;/usr/local/lib/lua/5.1/loadall.so;?.dylib
My new test waits 10 seconds before requiring lfs to give me a chance to see the cpath string.

If I place the lfs.so on my desktop and add /Users/myName/Desktop/?.so to the cpath, it works fine when I drag it to LÖVE. I guess I just don't understand what the correct search path is for the directory that my main.lua is in. I thought that would be ?.so or ./?.so or the same for .dylib.

Isn't it also a bug that the default path isn't my user name and LÖVE (or LuaJIT) doesn't seem to search the path where my main.lua is?
User avatar
pgimeno
Party member
Posts: 3641
Joined: Sun Oct 18, 2015 2:58 pm

Re: How to require a shared or dynamic library and possible bug

Post by pgimeno »

bzSteve wrote:If I place the lfs.so on my desktop and add /Users/myName/Desktop/?.so to the cpath, it works fine when I drag it to LÖVE. I guess I just don't understand what the correct search path is for the directory that my main.lua is in. I thought that would be ?.so or ./?.so or the same for .dylib.
Since you made that work, maybe lfs.currentdir() displays what ./ actually is (or love.filesystem.getWorkingDirectory(), but I'm not sure if that would show the same value). Also, love.filesystem.getRealDirectory("main.lua") and love.filesystem.getSourceBaseDirectory would be handy to print.

Maybe you need to dump those to a file in order to be able to view them more comfortably. Something like:

Code: Select all

local debstr = ""
local function dprint(...)
  for k, v in ipairs({...}) do
    if k ~= 1 then debstr = debstr .. "\t" end
    debstr = debstr .. tostring(v)
  end
  debstr = debstr .. "\n"
end

require("lfs")
dprint(lfs.currentdir())
dprint(love.filesystem.getWorkingDirectory())
dprint(love.filesystem.getRealDirectory("main.lua"))
dprint(love.filesystem.getSourceBaseDirectory())
for k, v in pairs(arg) do dprint(k, v) end
love.filesystem.setIdentity("debug_output")
love.filesystem.write("debug_output.txt", debstr)
bzSteve wrote:Isn't it also a bug that the default path isn't my user name and LÖVE (or LuaJIT) doesn't seem to search the path where my main.lua is?
I don't know, sorry. No idea where that 'alex' came from.
bobbyjones
Party member
Posts: 730
Joined: Sat Apr 26, 2014 7:46 pm

Re: How to require a shared or dynamic library and possible bug

Post by bobbyjones »

bzSteve wrote:Isn't it also a bug that the default path isn't my user name and LÖVE (or LuaJIT) doesn't seem to search the path where my main.lua is?
Cpath has no reason to search next to the main.lua since you are most likely going to ship the binary outside of the .love.
User avatar
LPGhatguy
Prole
Posts: 14
Joined: Thu Aug 09, 2012 12:57 am
Location: Montana, United States
Contact:

Re: How to require a shared or dynamic library and possible bug

Post by LPGhatguy »

From the #love IRC:

<+slime> i haven't put in the effort to reply to bzsteve's thread yet, someone tell him that love.filesystem doesn't look in the game's source directory for .dll/.so files (because operating systems cannot load binary libraries from inside a zip), if the game is fused then it will look in the game's save directory, and if mount(getSourceBaseDirectory()) has been used it'll look there too (if fused)
<+slime> also tell him not to rely on the current working directory, it has no guarantees of being the path he wants
User avatar
bzSteve
Prole
Posts: 34
Joined: Tue May 21, 2013 2:31 am

Re: How to require a shared or dynamic library and possible bug

Post by bzSteve »

You guys are great. I appreciate all your help!

pgimeno, I tried adding the getRealDirectory("main.lua") result to the cpath and that worked! Thank you.

bobbyjones, you're right, of course. I typically just make stuff for my own use and don't ship but I wanted to share this project with a colleague. I'll probably be back asking for more help when I try making a fused project.

LPGhatguy, thank you for passing that along. I'm going to play around with mounting the sourceBaseDirectory like slime suggested.
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 2 guests