mirror of
https://github.com/artegoser/ONLang
synced 2024-12-23 01:23:46 +03:00
feat: reference variables
This commit is contained in:
parent
983819830b
commit
f1259a6b1b
1 changed files with 20 additions and 0 deletions
|
@ -119,6 +119,14 @@ impl Interpreter {
|
|||
self.error("Unsupported data type for the `var` argument, must be a string");
|
||||
}
|
||||
},
|
||||
"ref" => match value {
|
||||
Value::String(value) => {
|
||||
return self.variable_reference(value);
|
||||
}
|
||||
_ => {
|
||||
self.error("Unsupported data type for the `ref` argument, must be a string");
|
||||
}
|
||||
},
|
||||
"isExist" => match value {
|
||||
Value::String(value) => {
|
||||
return Value::Bool(self.var_exists(value));
|
||||
|
@ -437,6 +445,18 @@ impl Interpreter {
|
|||
}
|
||||
}
|
||||
|
||||
fn variable_reference(&mut self, name: &String) -> Value {
|
||||
if self.var_exists(name) {
|
||||
return json!({ "var": name });
|
||||
} else {
|
||||
self.error(&format!(
|
||||
"The variable {} does not exist, the reference is invalid",
|
||||
name
|
||||
));
|
||||
}
|
||||
Value::Null
|
||||
}
|
||||
|
||||
fn calc(&mut self, value: &Vec<Value>) -> Value {
|
||||
let op1 = &value[0];
|
||||
let operation = &value[1];
|
||||
|
|
Loading…
Add table
Reference in a new issue