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

Function env_get

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

Gets the value of an environment variable

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

Source from the content-addressed store, hash-verified

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> {
53 if args.is_empty() {
54 return Err(VmError::RuntimeError(
55 "get_env() requires a variable name as argument".into(),
56 ));
57 }
58
59 let var_name = args[0].as_string()?.to_str().unwrap();
60
61 match std::env::var(var_name) {
62 Ok(value) => Ok(Value::String(state.get_context().intern(value.as_bytes()))),
63 Err(_) => Ok(Value::Nil),
64 }
65}
66
67// Sets the value of an environment variable
68fn env_set<'gc>(_state: &mut State<'gc>, args: Vec<Value<'gc>>) -> Result<Value<'gc>, VmError> {

Callers

nothing calls this directly

Calls 6

RuntimeErrorClass · 0.85
to_strMethod · 0.80
as_stringMethod · 0.80
get_contextMethod · 0.80
as_bytesMethod · 0.80
internMethod · 0.45

Tested by

no test coverage detected