Gets the value of an environment variable
(state: &mut State<'gc>, args: Vec<Value<'gc>>)
| 50 | |
| 51 | // Gets the value of an environment variable |
| 52 | fn 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 |
| 68 | fn env_set<'gc>(_state: &mut State<'gc>, args: Vec<Value<'gc>>) -> Result<Value<'gc>, VmError> { |
nothing calls this directly
no test coverage detected