Page 2 of 2

Re: Snippet for dumping tables when testing

Posted: Wed Sep 21, 2011 9:11 pm
by Robin
A good way to approach this is to look at where the variable is used, and look upwards, and up indentation levels.

You stop when you see:
  • local var: it is a local variable
  • for var = 1, 10 do or for var in somegenerator() do: it is a local variable
  • function bluh(var, bluh): it is a local variable
  • You are at the start of the file: it is a global variable
Example:

Code: Select all

function a (shazam)
 function b()
    print(shazam) -- a local variable, to be exact the argument to a
 end
end
Although there's more to it, what I just described is the gist of it.

Re: Snippet for dumping tables when testing

Posted: Wed Sep 21, 2011 9:36 pm
by pancakepalace
Thanks for the help. Iv'e updated the code to reflect this cleaner writing.

Re: Snippet for dumping tables when testing

Posted: Wed Sep 21, 2011 11:26 pm
by miko
pancakepalace wrote:All lua types are supported except functions and userData. If someone knows how to support functions by writing them out as strings, that would be great. I'm not even sure if it's possible.
If you have access to the source files, you could try:

Code: Select all

 debug.getinfo(funcname, 'S')
and then read the relevant lines from the file.

Re: Snippet for dumping tables when testing

Posted: Thu Sep 22, 2011 8:40 am
by kikito
I'm also going to put a link to my inspect.lua in case it serves you.

It doesn't do "function dumping", but it numbers functions, tables, etc so they can be told apart easily. It also has a good deal of tests.

Re: Snippet for dumping tables when testing

Posted: Thu Sep 22, 2011 3:10 pm
by pancakepalace
That's really cool! Your code looks more powerful than mine. I'm sure I'll find a use for it. Thanks.