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)
|
||||
end
|
||||
|
||||
print(_ENV.sometable)
|
||||
print(_ENV.b)
|
||||
@ -409,16 +409,27 @@ impl ClosureRunner {
|
||||
}
|
||||
Instruction::GetGlobal(reg, global) => {
|
||||
let constant = constants.get(*global as usize).unwrap().clone();
|
||||
let environment = self.closure.environment.borrow_mut().clone();
|
||||
let glob = environment
|
||||
.get(&constant.as_value().as_indexable()?)
|
||||
.cloned();
|
||||
if let Some(global) = glob {
|
||||
self.set_stack(*reg, StackValue::Value(global));
|
||||
|
||||
if let Constant::String(name) = &constant
|
||||
&& name.clone() == "_ENV".to_owned()
|
||||
{
|
||||
self.set_stack(
|
||||
*reg,
|
||||
StackValue::Value(Value::Table(self.closure.environment.clone())),
|
||||
);
|
||||
} else {
|
||||
return Err(RuntimeError::GlobalNotFound(
|
||||
constants.get(*global as usize).cloned(),
|
||||
));
|
||||
let environment = self.closure.environment.borrow_mut().clone();
|
||||
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) => {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user