A Lua implementation of dotenv for Garry's Mod.
- Pure gLua implementation, no binary modules required - far less likely for a game update to break your server.
- Provides an
env()
method which behaves the same as gmsv_dot_env, making it easy to switch (see migration notes here). - All
get{X}
methods support fallback values, making it easier to keep your dotenv file concise. - The parse method is exposed globally, allowing for other means of config distribution depending on your needs.
require("dotenv")
env.load(".env") --Loads /garrysmod/.env
--[[
.env file contents:
STRING="Hello World!"
NUMBER=-12.34
BOOLEAN=true
]]
env.getString("STRING") --"Hello World!"
env.getNumber("NUMBER") --12.34
env.getInteger("NUMBER") --12
env.getBoolean("BOOLEAN") --true
env.getString("I_DONT_EXIST", "Fallback value!") --"Fallback value!"
env.getKeys() --{"STRING", "NUMBER", "BOOLEAN"}
- Download the latest release of gmod-dotenv from the releases page.
- Open the archive with your tool of choice, and extract the "dotenv.lua" file into your server/addon's
includes/modules
. - Apply gmod-dotenv wherever you like, refer to the example usage and wiki for further help.
Documentation on the available methods and their usage can be found here.
- Owain for creating gmsv_dot_env, which inspired me to make my own implementation.
- GLuaTest by CFC Servers, used for automated testing of this library.