A not-so-true-to-life implementation of a .env file for gmod. Place a .env at
./garrysmod/.env and any variables set in it will be accessible from within Lua through the
env() function. The file will require you to run
require("dot_env") at the top of a config file.
This does not respect ENVIRONMENT_VARIABLES defined outside of the .env. My intentions were (And always will be) to keep the context of the variables tight and strict, so they are only creatable through the .env file.
Also, this will only work on server side. So if you require it inside a shared file, make sure to account for that.
Also, idk wtf I'm doing with Rust and this is probably a low key mess
- Place the dll in
- Create a
- Populate the .env file with an appropriate config.
- Go to a config file and require the DLL at the top of the file:
if SERVER then require('dot_env') end
- Set the config value using the
MyAddon.Config.SQL.Password = env('MY_ADDON_SQL_PASSWORD') or "password".
- If you are using this in a shared context, you may need to account for that like so:
MyAddon.Config.SharedValue = SERVER and (env('MY_ADDON_SHARED_VAL') or "Fallback") or "Client Fallback", but it is unlikely you would be using this in a shared context.