-
Notifications
You must be signed in to change notification settings - Fork 0
Constants
When your game is ran or build with Lover, you may access certain constants like the game's name or version defined in lover.toml
.
Skip to the list of constants.
Use the os.getenv
function.
main.lua
local name = os.getenv("LOVER_NAME")
local author = os.getenv("LOVER_AUTHOR")
local version = os.getenv("LOVER_VERSION")
print(name, "by", author)
print("Version:", version)
lover.toml
[package]
name = "Cool game"
author = "Cool person"
version = "1.0"
Output
Cool game by Cool Person
Version: 1.0
-
LOVER_VERSION
: Version of your game -
LOVER_NAME
: Name of your game -
LOVER_AUTHOR
: You -
LOVER_DESCRIPTION
: Description of your game -
LOVER_CONTEXT
: "build" or "run". Used to check if the game is packaged or ran withlover run
. -
LOVER_TIMESTAMP
: Epoch UNIX timestamp of when the game was built or ran bylover run
.
Important
When the game is built, those constants are NOT treated like regular env variables, so passing things like DRI_PRIME
won't have any effect, besides being readable by your game.
They only work like this with lover run
.
You can see how to include custom environment variables in the project configuration.
You can also do
SOME_ENV_VARIABLE=test lover run
If your game is open source or developed by a larger team, it's recommended that you don't rely on those constants in a way that the game will crash without them.
For example you can use
gameVersion = os.getenv("LOVER_VERSION") or "unknown"
so if the game is ran by another tool or regular love
, it will still work.
When you run lover run
, all constants are passed to the love
process as environment variables.
Environment variables cannot be modified when the process is running, so when your game is built, an extra piece of code is injected into it containing a table with all constants and the os.getenv
function is modified to first look into that table before checking the actual env variables.
You can preview it by running
lover module