How does one find a loop in a gettable chain?

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

How does one find a loop in a gettable chain?

Dirk Laurie-2
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.

Reply | Threaded
Open this post in threaded view
|

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

Sean Conner
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)


Reply | Threaded
Open this post in threaded view
|

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

Philipp Janda
In reply to this post by Dirk Laurie-2
Am 18.02.2016 um 20:33 schröbte Dirk Laurie:

> 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.
>

I've used my microscope[1] module for detecting cycles in __index
metamethods before.


Philipp

   [1]: https://luarocks.org/modules/siffiejoe/microscope



Reply | Threaded
Open this post in threaded view
|

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

Ignacio Burgueño-2
I've used microscope and it is a great tool indeed.
In addition, you can also use StackTracePlus [1] in addition to what Sean suggested.

Regards,
Ignacio



Reply | Threaded
Open this post in threaded view
|

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

Dirk Laurie-2
In reply to this post by Dirk Laurie-2
2016-02-18 21:33 GMT+02:00 Dirk Laurie <[hidden email]>:

> 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.

Thanks to Sean, Philipp and Ignacio, the error has been found.
In the process, I have tried out some magnificent tools that
can do much more than find this silly mistake.