mirror of
https://github.com/artegoser/ONLang
synced 2024-11-05 20:43:57 +03:00
feat: write obj to variable
This commit is contained in:
parent
7e9be774db
commit
983819830b
1 changed files with 19 additions and 0 deletions
|
@ -175,6 +175,14 @@ impl Interpreter {
|
|||
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 => {
|
||||
self.unk_token(&name);
|
||||
}
|
||||
|
@ -207,6 +215,17 @@ impl Interpreter {
|
|||
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) {
|
||||
let value = value.as_f64().unwrap() as u64;
|
||||
thread::sleep(time::Duration::from_millis(value));
|
||||
|
|
Loading…
Reference in a new issue