diff --git a/examples/test.lua b/examples/test.lua index a8385a5..f587b69 100644 --- a/examples/test.lua +++ b/examples/test.lua @@ -1,7 +1,9 @@ +local b = 5 + function add(x) return function (y) x = x + 1 - return x + y, 1, 2 + return x + y, 1, 2, b end end diff --git a/src/compile.rs b/src/compile.rs index 8fdb19a..3096b88 100644 --- a/src/compile.rs +++ b/src/compile.rs @@ -343,8 +343,9 @@ impl Expression { inner_scope.highest_upvalue = scope.highest_upvalue + scope.register_counter.0; inner_scope.upvalues = scope.upvalues.clone(); + dbg!(&scope.locals); for (name, reg) in &scope.locals { - let new_reg = *reg + inner_scope.highest_upvalue; + let new_reg = *reg + scope.highest_upvalue + 1; inner_scope.upvalues.insert(name.clone(), new_reg); }