From 3360f1491340d4035898c9a2923fc0fc7b4a09ae Mon Sep 17 00:00:00 2001 From: Sofia Date: Sat, 21 Mar 2026 15:20:13 +0200 Subject: [PATCH] Make tables indexable via pointer value --- examples/test.lua | 3 ++- examples/test.rs | 9 ++++++++- src/vm/value.rs | 2 +- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/examples/test.lua b/examples/test.lua index 93b401a..09a6b75 100644 --- a/examples/test.lua +++ b/examples/test.lua @@ -108,4 +108,5 @@ SETMETATABLE(table, { }) print(table + 5) -print(table("hello", "there")) \ No newline at end of file +print(table("hello", "there")) +print("hello ", table) \ No newline at end of file diff --git a/examples/test.rs b/examples/test.rs index 15bf789..4df8b64 100644 --- a/examples/test.rs +++ b/examples/test.rs @@ -25,7 +25,14 @@ impl value::RustFunction for Max { pub struct Print; impl value::RustFunction for Print { fn execute(&self, parameters: Vec) -> Result, RuntimeError> { - println!("{:?}", parameters); + println!( + "{}", + parameters + .iter() + .map(|v| format!("{}", v)) + .collect::>() + .join("\t") + ); Ok(Vec::new()) } diff --git a/src/vm/value.rs b/src/vm/value.rs index 5eb65ad..0aab46a 100644 --- a/src/vm/value.rs +++ b/src/vm/value.rs @@ -202,7 +202,7 @@ impl Display for Value { } Value::Function(closure) => write!(f, "", closure.prototype), Value::Nil => write!(f, "nil"), - Value::Table { .. } => write!(f, ""), + Value::Table { contents, .. } => write!(f, "", contents.as_ptr() as u64), } } }