lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On 8/11/2009, at 8:06 PM, Mike Pall wrote:
Geoff Leyland wrote:
On some occasions, debug.info(depth) seems to return info about a
different level of the stack frame in LJ2 than in Lua. I'm guessing you know this, and I think it's alluded to on the status page, but I thought
I'd check.  If it is new or of interest I'll try to make a short test
case.

Oh, it turns out that LJ1 behaves the same as LJ2, so I'm sure you
already know.

This is probably about tail calls:

Yes, thanks. I had written a short test case that didn't display the behavior which confused me a bit, but I now know that "function b() a () end" is not a tail call, whereas "function b() return a() end" is. The corrected test is below.

This showed up in a unit test framework that reports errors at the line of the test, not the line of the test machinery that actually finds the error, so for that it would be nice if the two were consistent, but I'd prefer performance over that. One fix for this case would be to add some code to disrupt the tail call.

Cheers,
Geoff


Test case:

function a()
  for i = 1, 3 do
    local d = debug.getinfo(i)
    print(d.name, d.short_src, d.currentline)
  end
end

function b()
  return a()
end

b()

Output:

$ lua getinfo-test.lua
nil	getinfo-test.lua	3
	(tail call)	-1
nil	getinfo-test.lua	12
$ luajit-2.0.0-beta1 getinfo-test.lua
b	getinfo-test.lua	3
nil	getinfo-test.lua	12
nil	[C]	-1