Skip to content

TomDotBat/gmod-dotenv

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

43 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

gmod-dotenv

A Lua implementation of dotenv for Garry's Mod.

Features

  • 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.

Example Usage

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"}

Installation

  1. Download the latest release of gmod-dotenv from the releases page.
  2. Open the archive with your tool of choice, and extract the "dotenv.lua" file into your server/addon's includes/modules.
  3. Apply gmod-dotenv wherever you like, refer to the example usage and wiki for further help.

Documentation

Documentation on the available methods and their usage can be found here.

Credits