[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: debug.getinfo()?
- From: PA <petite.abeille@...>
- Date: Sat, 5 Mar 2005 11:25:07 +0100
Hello,
I have a little logging class where I use debug.getinfo() to build the
context of a log call, e.g. the package and function name which invoked
the log method.
For example, assuming an 'Example.lua' main chunk with the following
log statements:
Log.debug( aDBMap.get( "DEC" ) )
Log.debug( aDBMap.hasKey( "DEC" ) )
Produces this output:
03/05 10:54:56 (Debug) Example.main: "December"
03/05 10:54:56 (Debug) Example.main: true
All in all, this work quite nicely. However, from time to time,
debug.getinfo() seems to get confused. For example, the call after the
ones above:
Log.debug( aDBMap.hasValue( "December" ) )
Produces the following output:
03/05 10:54:56 (Debug) Example.DEC: true
Note the "DEC" value for the function name, instead of "main" as for
every other calls. How come? What is "DEC" doing there? "DEC" is the
key for that value, but it shouldn't have anything to do with
debug.getinfo(), isn't it? This is not critical, as it seldomly happen,
but still, what would explain such confusion?
The relevant implementation of Log goes something like this:
if ( ( aClassName == nil ) or ( aMethodName == nil ) ) then
local someInfo = debug.getinfo( 3, "Sn" )
if ( aClassName == nil ) then
aClassName = LUBundle.nameWithPath(
someInfo.source )
end
if ( aMethodName == nil ) then
aMethodName = someInfo.name
if ( aMethodName == nil ) then
aMethodName = someInfo.what
end
end
end
Full source code available here:
http://dev.alt.textdrive.com/file/lu/LULog.lua
Any insights appreciated. Thanks!
Cheers
--
PA, Onnay Equitursay
http://alt.textdrive.com/