Getting LÖVE license texts from runtime

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
tpimh
Prole
Posts: 5
Joined: Thu Jan 25, 2024 3:06 pm

Getting LÖVE license texts from runtime

Post 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.
User avatar
zorg
Party member
Posts: 3465
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: Getting LÖVE license texts from runtime

Post 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.
Me and my stuff :3True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
tpimh
Prole
Posts: 5
Joined: Thu Jan 25, 2024 3:06 pm

Re: Getting LÖVE license texts from runtime

Post 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)
tpimh
Prole
Posts: 5
Joined: Thu Jan 25, 2024 3:06 pm

Re: Getting LÖVE license texts from runtime

Post 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.
Attachments
license.love
(1.56 KiB) Downloaded 118 times
Post Reply

Who is online

Users browsing this forum: No registered users and 4 guests