Global declarations should directly mutate _G. Currently, the compiled code simply adds or remove the local keyword, which is not sufficient as may simply be reassigning local variables:
local a = 1
global a = 2
print(a) -- 2, should be 1 since local scope should be favored
print(_G.a) -- nil
local function test() {
return 2
}
global function test() {
return 1
}
print(test()) -- 1
print(_G.test) -- nil
Global declarations should directly mutate _G. Currently, the compiled code simply adds or remove the
local
keyword, which is not sufficient as may simply be reassigning local variables: