[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: LUA Debugger Addin (Visual Studio)
- From: Rici Lake <lua@...>
- Date: Wed, 28 Sep 2005 21:54:13 -0500
On 27-Sep-05, at 12:39 AM, Zulfiqar Malik wrote:
How can i determine whether a symbol is local or global (when a user
specifies a variable to be watched in the watch window), and whether
its a
lua function, C function or something else?
There is no real way to answer this question, particularly since two
local variables might have the same name. Consider:
do
local i = 1
--- lots of stuff using i
end
do
-- this is a different 'i'
local i = "foo"
end
If the program being debugged is halted at some execution point, you
can enumerate the various possible local variables with the debug
interface. However, the Lua API does not give you a practical way
to identify a local variable "i" so that it can be correlated with
a local variable "i" visible at a different point of the program.
(The information can be derived by analysing Lua internal structures,
or can be gleaned by reparsing the Lua source code, which is what I
did with LuaParse.)
Is there anyway to add breakpoints to lua_State because otherwise i
will
have to handle it manually and that is bound to be more error prone.
I believe the intended solution to breakpoints is to install a linehook
and then, inside the hook function, compare the line number with a table
of breakpoints.
I added the source code snippet in lua reference manual (5.0) about
enumerating local variables, but it doesn't work. lua_getstack(...)
always
returns 0. The stack level being passed is the top of the stack.
The 'level' in question here is the execution level, counting backwards
from the current function. This has no relationship whatsoever with the
value returned by lua_gettop(). If you think of the internal execution
stack as a stack of stack-frames, where only the top stack-frame is
visible to the executing function (aside from the use of the debugging
interface), this might make more sense, although you have to remember
that indices inside a stack frame count *upwards* from 1 and *downwards*
from -1, whereas stack-frame levels themselves count *downwards* from 1
(and no absolute index is available.) I've probably confused you more
by that answer.
I would be thankful if someone would answer these questions. Any
comments
about whether this is the right approach or not are most welcome.