https://github.com/0wain/gmsv_dot_env
📁 A not-so-true-to-life implementation of .env (dot env) for Garry's Mod
https://github.com/0wain/gmsv_dot_env
dot-env dotenv garrys-mod garrysmod gmod gmod-module gmsv rust rust-lang
Last synced: 12 months ago
JSON representation
📁 A not-so-true-to-life implementation of .env (dot env) for Garry's Mod
- Host: GitHub
- URL: https://github.com/0wain/gmsv_dot_env
- Owner: 0wain
- Created: 2022-07-22T22:03:31.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2025-01-07T14:55:46.000Z (about 1 year ago)
- Last Synced: 2025-04-04T18:07:27.300Z (12 months ago)
- Topics: dot-env, dotenv, garrys-mod, garrysmod, gmod, gmod-module, gmsv, rust, rust-lang
- Language: Rust
- Homepage:
- Size: 18.6 KB
- Stars: 9
- Watchers: 1
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# gmsv_dot_env
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.~ I change my mind (I was an idiot then), if you want to add this functionality please open a PR!
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*
## Install
1. Place the dll in `./garrysmod/lua/bin`.
2. Create a `.env` file at `./garrysmod/.env`.
3. Populate the .env file with an appropriate config.
4. Go to a config file and require the DLL at the top of the file: `if SERVER then require('dot_env') end`
5. Set the config value using the `env()` function: `MyAddon.Config.SQL.Password = env('MY_ADDON_SQL_PASSWORD') or "password"`.
6. 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.
## Credits
- [WilliamVenner](https://github.com/WilliamVenner) - Making gmod-rs. Digging through his endless Gmod Rust DLL repos in order to understand how gmod-rs works. I also stole his build action, sue me.
- [dotenv-parser](https://github.com/rubik/dotenv-parser) - Parsing the .env file. Because why make something yourself when someone has already done it better?