lua-users home
lua-l archive

Re: How does one find a loop in a gettable chain?

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


It was thus said that the Great Dirk Laurie once stated:
> I'm getting the following error:
> 
> gettable chain too long; possible loop
> 
> It's difficult to locate the error by my usual technique
> of sprinkling print statements around. This may be
> a case where the debug library is needed.
> 
> The traceback is of little use. It contains only the
> outermost call, which is almost the only statement
> in the main chunk.
 You could trying wrapping the topmost call with xpcall(). I do that at
work and use the following message handler:
function stackdump(...)
 local max = select('#',...)
 for i = 1 , max do
 syslog('debug',"Stack: %d %d %s",i,i-max-1,tostring(select(i,...)))
 end
 local stack = {}
 for i = 1 , 10 do
 local info = debug.getinfo(i,"Sl")
 if not info then break end
 table.insert(stack,string.format(" [%s(%d)]",info.source,info.currentline))
 end
 
 syslog('debug',"stack=%s",table.concat(stack))
 return ...
end
I use syslog() because I might not *have* a terminal, but it should be easy
enough to replace syslog() with print().
 -spc (I tend to log to syslog() as I have a real time view of it [1][2])
[1]	https://github.com/spc476/syslogintr
	It's a syslog daemon written in C and Lua. 
[2]	I have syslogintr configured to forward logs to a multicast
	address. I can then run other instances of syslogintr to listen on
	this address and the most common use I use of this is to view the
	logs in realtime (and color coded: https://github.com/spc476/syslogintr/blob/master/realtime.lua)

AltStyle によって変換されたページ (->オリジナル) /