MCPcopy Index your code
hub / github.com/aiscriptdev/aiscript / env_vars

Function env_vars

aiscript-vm/src/stdlib/env.rs:38–49  ·  view source on GitHub ↗

Returns all environment variables as an object

(state: &mut State<'gc>, _args: Vec<Value<'gc>>)

Source from the content-addressed store, hash-verified

36
37// Returns all environment variables as an object
38fn env_vars<'gc>(state: &mut State<'gc>, _args: Vec<Value<'gc>>) -> Result<Value<'gc>, VmError> {
39 let ctx = state.get_context();
40 let mut env_vars = Object::default();
41
42 for (key, value) in std::env::vars() {
43 let key = ctx.intern(key.as_bytes());
44 let value = Value::String(ctx.intern(value.as_bytes()));
45 env_vars.fields.insert(key, value);
46 }
47
48 Ok(Value::Object(Gc::new(&ctx, RefLock::new(env_vars))))
49}
50
51// Gets the value of an environment variable
52fn env_get<'gc>(state: &mut State<'gc>, args: Vec<Value<'gc>>) -> Result<Value<'gc>, VmError> {

Callers

nothing calls this directly

Calls 4

ObjectClass · 0.85
get_contextMethod · 0.80
as_bytesMethod · 0.80
internMethod · 0.45

Tested by

no test coverage detected