Open cloudwindy opened 1 year ago
In my experiment, removing the pcall method:
local a
function Use_a()
print(a)
a('test')
end
a = function(prompt)
print(prompt)
end
Use_a()
Produces same result for lua and glua:
$ lua test.lua
function: 0x564dc15af480
test
$ glua test.lua
function: 0xc000156f00
test
@yuin
In my experiment I also found that in certain situations this bug won't reproduce if:
pcall
pcall
Looks like the environment is isolated in error() and everything before become read-only.
local a = 123
function Print_a()
print(a)
end
pcall(function() error() end)
a = 456
print(a)
Print_a()
$ lua test.lua
456
456
$ glua test.lua
456
123
I found https://github.com/yuin/gopher-lua/blob/2b3f02d9173010b12bb3ff2c0e758921accb4096/_state.go#L626-L632 Is this an intented behavior?
You must post issues only here. Questions, ideas must be posted in discussions.
Please answer the following before submitting your issue:
function Use_a() print(a) a('test') end
pcall(function() error('an error') end) a = function(prompt) print(prompt) end
Use_a()
$ lua test.lua function: 0x556330c5dfa0 test
$ glua test.lua nil test.lua:5: attempt to call a non-function object stack traceback: test.lua:5: in function 'Use_a' test.lua:15: in main chunk