Fix __newindex metamethod, test __call
This commit is contained in:
parent
71c11e87e5
commit
1811b91922
@ -100,7 +100,12 @@ print("hello " .. "there")
|
|||||||
SETMETATABLE(table, {
|
SETMETATABLE(table, {
|
||||||
__add = function ()
|
__add = function ()
|
||||||
return 1
|
return 1
|
||||||
|
end,
|
||||||
|
__call = function (table, ...)
|
||||||
|
print(...)
|
||||||
|
return 1, 2, 3
|
||||||
end
|
end
|
||||||
})
|
})
|
||||||
|
|
||||||
print(table + 5)
|
print(table + 5)
|
||||||
|
print(table("hello", "there"))
|
||||||
@ -566,10 +566,10 @@ impl ClosureRunner {
|
|||||||
.unwrap_or(Value::Nil);
|
.unwrap_or(Value::Nil);
|
||||||
}
|
}
|
||||||
Instruction::SetTable(tablereg, indexreg, valuereg) => {
|
Instruction::SetTable(tablereg, indexreg, valuereg) => {
|
||||||
let table_value = self.stack.get(tablereg);
|
let table_stack_value = self.stack.get(tablereg);
|
||||||
match table_value {
|
match table_stack_value {
|
||||||
Some(value) => {
|
Some(table_value) => {
|
||||||
let mut table = value.borrow_mut();
|
let mut table = table_value.borrow_mut();
|
||||||
if let Value::Table {
|
if let Value::Table {
|
||||||
contents,
|
contents,
|
||||||
metatable,
|
metatable,
|
||||||
@ -605,7 +605,10 @@ impl ClosureRunner {
|
|||||||
match self.call_metamethod(
|
match self.call_metamethod(
|
||||||
metatable,
|
metatable,
|
||||||
"__newindex",
|
"__newindex",
|
||||||
vec![table_value.unwrap().borrow().clone()],
|
vec![Value::Table {
|
||||||
|
contents: contents.clone(),
|
||||||
|
metatable: metatable.clone(),
|
||||||
|
}],
|
||||||
) {
|
) {
|
||||||
Ok(_) => {}
|
Ok(_) => {}
|
||||||
Err(_) => match value {
|
Err(_) => match value {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user