amber-lang / amber-lang/amber

[Feature] access compile time environment variables

Offen
#436 2 Kommentare 0 Reaktionen 1 zugewiesene Person Beansprucht von @b1ek Auf GitHub ansehen
enhancement feature proposal hacktoberfest
Vorherrschende Sprache
Rust
Sterne
5.2k
Forks
145
Ø Merge
5 T. 3 Std.
Gemergte PRs (30 T.)
7

Beschreibung

**Is your feature request related to a problem? Please describe.**
see #431

**Describe the solution you'd like**
i think that we should add rust-like compile time macros, like `env!()` in this case which should enable the user to access compile time environment variables.

for the `env!()` macro, i suggest the following syntax:

```ab
fun env(variable: Text, default: Text): Text {
// returns the specified variable if it exists, and default if it is set and the env variable is not available.
// if default value is not set and variable is not available, it will throw a compile time error
}
```

which should be used like this:

```ab
const compile_commit = env!("COMPILE_COMMIT", "unknown");
```

which should be compiled to something like this (assuming `COMPILE_COMMIT` is set to `a8c3083f`:

```bash
declare -r compile_commit = "a8c3083f"
```

**Describe alternatives you've considered**
https://github.com/amber-lang/amber/issues/431#issuecomment-2323256429

Beitragsleitfaden

Für dieses Repository ist kein Beitragsleitfaden indexiert

Bewertung

Dieses Issue wurde noch nicht bewertet.

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.