[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: debug.getlocal from within return hook
- From: Philipp Janda <siffiejoe@...>
- Date: Tue, 19 May 2015 10:50:44 +0200
Hi!
Am 19.05.2015 um 10:33 schröbte Philipp Janda:
Thanks very much! I can confirm that a single explicit return value
fixes the behavior of the test script on Lua 5.1, 5.2, and 5.3 (an empty
`return` is insufficient). Unfortunately, in my original code where I
encountered the problem I already had an explicit return value (and it
still doesn't work except on LuaJIT). I'll try to come up with an
updated test case.
As promised here the updated test case. Interestingly, which local
variables get garbled depends on which local variable I return
(unfortunately the original code is primarily used on module chunks
where I often return the first local I define (`local M = {}`)) ...
Output (variable `b` is returned from `func`):
func a 10
func b table: 0x11b3da0
func c function: 0x11b4200
func d true
func e string
HOOK a 10
HOOK b table: 0x11b3da0
HOOK c table: 0x11af7b0
HOOK d function: 0x11af590
HOOK e 5
Philipp
local function func()
local a = 10
local b = {}
local c = function() end
local d = true
local e = "string"
local ii, name, value = 2, debug.getlocal( 1, 1 )
while name do
if #name == 1 then
print( "func", name, value )
end
ii, name, value = ii+1, debug.getlocal( 1, ii )
end
print()
return b
end
local function hook()
if debug.getinfo( 2, "f" ).func == func then
local i, name, value = 2, debug.getlocal( 2, 1 )
while name do
if #name == 1 then
print( "HOOK", name, value )
end
i, name, value = i+1, debug.getlocal( 2, i )
end
end
end
debug.sethook( hook, "r" )
func()
debug.sethook()