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.
Getting LÖVE license texts from runtime
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
- zorg
- Party member
- Posts: 3468
- Joined: Thu Dec 13, 2012 2:55 pm
- Location: Absurdistan, Hungary
- Contact:
Re: Getting LÖVE license texts from runtime
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 True 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.
Re: Getting LÖVE license texts from runtime
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:
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
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.
UPD: also tested on Windows and macOS.
- Attachments
-
- license.love
- (1.56 KiB) Downloaded 416 times
Who is online
Users browsing this forum: Majestic-12 [Bot] and 6 guests