Add _ENV-table as special case for the VM
This commit is contained in:
parent
131c01c8f0
commit
260963f7cd
@ -94,4 +94,4 @@ for k, v in (ipairs(table)) do
|
|||||||
print(k, v)
|
print(k, v)
|
||||||
end
|
end
|
||||||
|
|
||||||
print(_ENV.sometable)
|
print(_ENV.b)
|
||||||
@ -409,16 +409,27 @@ impl ClosureRunner {
|
|||||||
}
|
}
|
||||||
Instruction::GetGlobal(reg, global) => {
|
Instruction::GetGlobal(reg, global) => {
|
||||||
let constant = constants.get(*global as usize).unwrap().clone();
|
let constant = constants.get(*global as usize).unwrap().clone();
|
||||||
let environment = self.closure.environment.borrow_mut().clone();
|
|
||||||
let glob = environment
|
if let Constant::String(name) = &constant
|
||||||
.get(&constant.as_value().as_indexable()?)
|
&& name.clone() == "_ENV".to_owned()
|
||||||
.cloned();
|
{
|
||||||
if let Some(global) = glob {
|
self.set_stack(
|
||||||
self.set_stack(*reg, StackValue::Value(global));
|
*reg,
|
||||||
|
StackValue::Value(Value::Table(self.closure.environment.clone())),
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
return Err(RuntimeError::GlobalNotFound(
|
let environment = self.closure.environment.borrow_mut().clone();
|
||||||
constants.get(*global as usize).cloned(),
|
let glob = environment
|
||||||
));
|
.get(&constant.as_value().as_indexable()?)
|
||||||
|
.cloned();
|
||||||
|
|
||||||
|
if let Some(global) = glob {
|
||||||
|
self.set_stack(*reg, StackValue::Value(global));
|
||||||
|
} else {
|
||||||
|
return Err(RuntimeError::GlobalNotFound(
|
||||||
|
constants.get(*global as usize).cloned(),
|
||||||
|
));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Instruction::GetUpVal(reg, upvalreg) => {
|
Instruction::GetUpVal(reg, upvalreg) => {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user