Fix __newindex metamethod, test __call

This commit is contained in:
Sofia 2026-03-21 14:59:26 +02:00
parent 71c11e87e5
commit 1811b91922
2 changed files with 14 additions and 6 deletions

View File

@ -100,7 +100,12 @@ print("hello " .. "there")
SETMETATABLE(table, {
__add = function ()
return 1
end,
__call = function (table, ...)
print(...)
return 1, 2, 3
end
})
print(table + 5)
print(table + 5)
print(table("hello", "there"))

View File

@ -566,10 +566,10 @@ impl ClosureRunner {
.unwrap_or(Value::Nil);
}
Instruction::SetTable(tablereg, indexreg, valuereg) => {
let table_value = self.stack.get(tablereg);
match table_value {
Some(value) => {
let mut table = value.borrow_mut();
let table_stack_value = self.stack.get(tablereg);
match table_stack_value {
Some(table_value) => {
let mut table = table_value.borrow_mut();
if let Value::Table {
contents,
metatable,
@ -605,7 +605,10 @@ impl ClosureRunner {
match self.call_metamethod(
metatable,
"__newindex",
vec![table_value.unwrap().borrow().clone()],
vec![Value::Table {
contents: contents.clone(),
metatable: metatable.clone(),
}],
) {
Ok(_) => {}
Err(_) => match value {