feat: write obj to variable

This commit is contained in:
Artemy 2022-08-14 23:32:35 +03:00
parent 7e9be774db
commit 983819830b

View file

@ -175,6 +175,14 @@ impl Interpreter {
self.error("Unsupported data type for the `scope` argument, must be an array"); self.error("Unsupported data type for the `scope` argument, must be an array");
} }
}, },
"obj" => match value {
Value::Object(value) => {
return self.calc_obj(value);
}
_ => {
self.error("Unsupported data type for the `obj` argument, must be an array");
}
},
name => { name => {
self.unk_token(&name); self.unk_token(&name);
} }
@ -207,6 +215,17 @@ impl Interpreter {
return Value::Null; return Value::Null;
} }
fn calc_obj(&mut self, value: &Map<String, Value>) -> Value {
let result: Value = value
.into_iter()
.map(|(k, v)| match v {
Value::Object(_) => (k.clone(), self.eval_node(v)),
_ => (k.clone(), v.clone()),
})
.collect();
result
}
fn sleep(&self, value: &serde_json::Number) { fn sleep(&self, value: &serde_json::Number) {
let value = value.as_f64().unwrap() as u64; let value = value.as_f64().unwrap() as u64;
thread::sleep(time::Duration::from_millis(value)); thread::sleep(time::Duration::from_millis(value));