Make tables indexable via pointer value

This commit is contained in:
Sofia 2026-03-21 15:20:13 +02:00
parent 10bc804a01
commit 3360f14913
3 changed files with 11 additions and 3 deletions

View File

@ -108,4 +108,5 @@ SETMETATABLE(table, {
})
print(table + 5)
print(table("hello", "there"))
print(table("hello", "there"))
print("hello ", table)

View File

@ -25,7 +25,14 @@ impl value::RustFunction for Max {
pub struct Print;
impl value::RustFunction for Print {
fn execute(&self, parameters: Vec<value::Value>) -> Result<Vec<value::Value>, RuntimeError> {
println!("{:?}", parameters);
println!(
"{}",
parameters
.iter()
.map(|v| format!("{}", v))
.collect::<Vec<_>>()
.join("\t")
);
Ok(Vec::new())
}

View File

@ -202,7 +202,7 @@ impl Display for Value {
}
Value::Function(closure) => write!(f, "<function({})>", closure.prototype),
Value::Nil => write!(f, "nil"),
Value::Table { .. } => write!(f, "<table>"),
Value::Table { contents, .. } => write!(f, "<table#{}>", contents.as_ptr() as u64),
}
}
}