Add helper functions

This commit is contained in:
numzero 2025-04-19 15:20:57 +03:00
parent b131d40702
commit a7ba99b3a8

View File

@ -443,10 +443,34 @@ impl OpenFunction {
#[cfg(test)]
mod tests {
use crate::{ast::*, types::ValueInner};
use crate::{
ast::*,
types::{Value, ValueInner},
};
use super::build;
fn get(table: &Value, index: &str) -> Value {
let Some(ValueInner::Table(table)) = table else {
panic!("a table expected");
};
table.get(index.into())
}
fn set(table: &Value, index: &str, value: Value) {
let Some(ValueInner::Table(table)) = table else {
panic!("a table expected");
};
table.set(index.into(), value);
}
fn call(func: &Value, args: &[Value]) -> Value {
let Some(ValueInner::Function(func)) = func else {
panic!("a function expected");
};
func.call(args)
}
#[test]
fn test_local() {
let testee = Function {