From 983819830b18fe75377f108e2ea3f6fa9d513799 Mon Sep 17 00:00:00 2001 From: Artemy Date: Sun, 14 Aug 2022 23:32:35 +0300 Subject: [PATCH] feat: write obj to variable --- src/interpreter.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/interpreter.rs b/src/interpreter.rs index cf57725..685b85d 100644 --- a/src/interpreter.rs +++ b/src/interpreter.rs @@ -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) -> 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));