lua-users home
lua-l archive

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


Hi!

I have a question concerning the Lua debug interfaces (lua_getstack,
lua_getinfo) etc implemented in Lua 4.0
I apologize for the length of this question but I wanted to make myself clear.

I have implemented Lua in my Active Scripting engine using the Lua 4.0. To
implement Active Script Debugging I am using a line hook and when the line hook
is called on a line that has a breakpoint set , the debugging mechanism is
called. The following code is an extract from the line hook:

[[
void LineHookFunction(lua_State *pluaState, lua_Debug *pluaDebug) {
    if (*pluaDebug->event == 'l') {
        ...
    lua_Debug luaDebug;
    int maxIndex = 0;
    while (lua_getstack(pluaState, maxIndex, &luaDebug)) {
            if (lua_getinfo (pluaState, "lnuS", &luaDebug)) {
                printf("Line hook: c:%u, n:%s, w:%s, u:%u, d:%u, w:%s, s:%s
m:%s\r\n",
                        luaDebug.currentline,
                        luaDebug.name,
                        luaDebug.namewhat,
                        luaDebug.nups,
                        luaDebug.linedefined,
                        luaDebug.what,
                        luaDebug.source,
                        luaDebug.short_src);                
            }           
    maxIndex++;
        }
    }
}

The script function that I run is as follows:

function function2()
    print(" in function2")
    function3() 
end

function function3()
    print(" in function3")  --> breakpoint set here
end

function function1()
    print("in function1")
    function2()
end

function Main()
    local a, b, c
    function1()
end

I load this code into Lua using lua_dobuffer() and then call getglobal and
lua_rawcall as follows:

{
    int nOldTop = lua_gettop(m_luaState);
    lua_getglobal(m_luaState, "Main");
    if (lua_isfunction(m_luaState, -1))
        lua_rawcall(m_luaState, 0, 0);
    lua_settop(m_luaState, nOldTop);
}

Now to my question. I set a breakpoint on the print statement in the function 3
and invoke 'Main'. 
Then when the breakpoint is hit, I get the following output from my line hook

Line hook: c:6, n:function3, w:global, u:0, d:5, w:Lua, s:(0:0) m:string "(0:0)"
Line hook: c:2, n:function2, w:global, u:0, d:0, w:main, s:(0:0) m:string
"(0:0)"
Line hook: c:11, n:function1, w:global, u:0, d:9, w:Lua, s:(0:0) m:string
"(0:0)"

You will observe the following about this output.

-  The function Main does not have an accessible 'activation record'. 
   Does this also mean I am unable to inspect the locals of this function from
my debug code?

- The function 'function2' has a 'what' of 'main' whereas 'function1' and
'function3' have a what of 'Lua'.
   Does the first lexed function in a lua script block get a what of 'main' and
all others are 'Lua'?

>From my debugging routines, could you provide assistance as to how I access the
activation record of function 
'Main' and also access its locals?. Also could you indicate what the meaning is
of the 'what' in the luaDebug structure.

Any assistance that you give would be appreciated.

Thanks,
Paul.