Page 1 of 1

Getting LÖVE license texts from runtime

Posted: Mon Jul 29, 2024 9:08 am
by tpimh
I want to display the LÖVE licensing information from my game menu.

For Windows that would be "directory of love.exe"/license.txt, for macOS that would be "directory of love"/../Resources/license.txt, for Linux in case of the official AppImage, that's "directory of love"/../license.txt (but for versions distributed through package managers, there are options).

I know how to determine the OS in runtime, but how do I get the directory of the executable?

I also want to include similar info about all the assets and libraries, but that seems to be much easier (info embedded in the files or supplied as separate files alongside) than the actual runtime itself.

Re: Getting LÖVE license texts from runtime

Posted: Mon Jul 29, 2024 11:37 am
by zorg
Can you not just put the license text yoursel into a variable and show it wherever you want? Much easier than fiddling with trying to load it in from storage.

Re: Getting LÖVE license texts from runtime

Posted: Mon Jul 29, 2024 12:31 pm
by tpimh
Yes, distributing love license file with the game is way easier, but I want to show the license text of the particular runtime, so that's not exactly what I want to do.

Just learned about "arg[-2]", turns out it has the full path of LÖVE executable (well, at least for AppImage). Need to test this code on other operating systems, and then I will also need to read from the file (using urfs or nativefs, I guess). I also thought that normalizing the path can be good, but couldn't find a native Lua solution for this (both lua-path and lpath are using native modules). Here is what I got so far:

Code: Select all

local loveOS = love.system.getOS()
local pathSeparator = (loveOS == "Windows") and "\\" or "/"

local executablePath = arg[-2]
local executableDir = executablePath:match("(.*" .. pathSeparator .. ")")

local licenseRelpath = "license.txt"
if loveOS ~= "Windows" then
  licenseRelpath = ((loveOS == "OS X") and "../Resources/" or "../") .. licenseRelpath
end
local licensePath = executableDir .. licenseRelpath

print(licensePath)

Re: Getting LÖVE license texts from runtime

Posted: Mon Jul 29, 2024 1:32 pm
by tpimh
This is what I came up with. Only tested on AppImage for Linux, and I know for sure that it will fail when launched using LÖVE installed using package manager. Not very impressive, just loads and displays the license text.

UPD: also tested on Windows and macOS.