lua-users home
lua-l archive

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


I wonder if the following is Lua's expected behavior?

Given:

====== start of test.lua ===========

function myth( n )
    if n == 0 then return 0 end
    return myth(n-1)
end

--setfenv( myth, { aaa = "hi", bbb = "test" } )

s = myth(5)

====== end of test.lua ===========

Within a line hook, when I display the call stack by traversing the activation records using lua_getstack(), I get:

====== Start of output ===========

Function 0: myth() @../../scripts/test.lua, line: 2
Function 1: made tail call so its info is erased by Lua.
Function 2: made tail call so its info is erased by Lua.
Function 3: made tail call so its info is erased by Lua.
Function 4: made tail call so its info is erased by Lua.
Function 5: made tail call so its info is erased by Lua.
Function 6: main() @../../scripts/test.lua, line: 8

====== End of output ===========

Note that if the "what" attribute of "ar" (the activation record) equals "tail", I display the message as seen beside functions 1 to 5.

So far so good (everything is as expected). Now, I uncomment the commented line in test.lua, and the following output is produced:

====== Start of output ===========

Function 0: myth() @../../scripts/test.lua, line: 3
Function 1: main() @../../scripts/test.lua, line: 8

====== End of output ===========

Both outputs were captured just prior to the termination of the execution of the script (i.e. the last time that my line hook was fired). I use only a line hook and no other hooks. The script is ran with lua_dofile( ). The choice of the parameter value for myth() is arbitrary; the same thing happens for myth(1), myth(2), etc.

Does anyone know if this is expected behavior? Or if setfenv() is doing a little more than expected?

Tai