Page 2 of 3

Re: inspect.lua

Posted: Thu Apr 28, 2011 8:10 am
by kikito
I think I will not use the lua ids after all. They are not deterministic, so generating tests for them is more difficult than I'd like. Plus, if a table has a __tostring metamethod, its id isn't reachable anymore (I think).

Right now I'm thinking about rolling down my own table identifiers - as in 1,2,3,4 ... they should be easier to read and compare than the lua ids anyway.

Re: inspect.lua

Posted: Thu Apr 28, 2011 8:13 am
by BlackBulletIV
You could momentarily set __tostring to nil, and then set it back again. But hey, I think your own identifiers would work just fine.

Re: inspect.lua

Posted: Thu Apr 28, 2011 10:13 pm
by ishkabible
i didn't think about that __tostring thing... rolling your own IDs sounds better becuase the numbers will be so much smaller and as such easier to read. nice idea!!

Re: inspect.lua

Posted: Wed May 04, 2011 12:04 am
by ishkabible
hey kikito, have you updated inspect? i saw you updated cron and memorize so i thought i would ask...

Re: inspect.lua

Posted: Wed May 04, 2011 7:46 am
by kikito
Not yet, sorry! It's on my TODO list.

I'll get on it as soon as I finish with the new tweening lib.

Re: inspect.lua

Posted: Mon May 09, 2011 10:52 pm
by kikito
v1.1 of inspect.lua has been released!

On this version I've added counters.

Counters are used to identify functions, so now they will be called <function 1>, <function 2>, etc instead of simply <function>. This way you can easily tell them appart:

Code: Select all

inspect({print, require, print}) == "<1>{ <function 1>, <function 2>, <function 1> }"
This (should) also happen with threads (<thread 1>, <thread 2>, etc) and userdata (<userdata 1>, <userdata 2>, etc). Although I haven't tested those cases.

You may have noticed the <1> before the table above. Now tables are preceded by an <identifier>:

Code: Select all

inspect({1,2,{3,4}}) == "<1>{ 1, 2, <2>{ 3, 4 } }"
These identifiers are used to avoid "re-printing" the same table again and again. When inspect encounters the same table more than once, instead of reprinting its contents again, it prints <table x>, where x is the table identifier:

Code: Select all

a = {1,2}
b = {3,4,a}
a[3] = b
inspect(a) = "<1>{ 1, 2, <2>{ 3, 4, <table 1> } }"
Notice how the second appearance of a was replaced by <table 1>.

I hope you are satisfied with the changes. Regards, and good night!

Re: inspect.lua

Posted: Mon Oct 29, 2012 11:15 pm
by kikito
New version (1.2.0) of inspect.lua is out:

The biggest change is that in the new version, the <id> of a table will be printed only for the tables that are repeated, while the rest will not. This tones visual noise, and makes the printouts more useful. Now if you see an <id> before a table, you now know that that table will appear more than once on the generated string.

Another change is that now the default depth is "infinite". The historical reason for having such parameter was table recursion, but handling them via <ids> is a better approach IMHO. The depth param is still there, and if you set it up to 4 inspect will behave like before.

There has also been some small code cleanup and refactoring, and the tests have been cleaned up a little bit.

Re: [library] inspect.lua - print tables and debug beautiful

Posted: Sat Sep 20, 2014 2:12 pm
by kikito
It seems that I forgot to mention inspect 2.0 on this thread.

Well, nevertheless, here you go: inspect.lua v3.0.0 is out. You can get it from github or luarocks:

The basic function are the same: you give it a Lua value, and it gives you back a string representing the object, but in a way humans understand easily. It is especially useful for seeing the contents of tables.

Code: Select all

local inspect = require 'inspect'

print(inspect({1,2,3})) -- prints { 1, 2, 3 }
Inspect accepts a second optional parameter called options, which can be used to tweak the generated string in several ways. That is the one which has changed on this version. The new options are explained on the readme.

I have also made the code a bit smaller and faster, and fixed one bug related with floats used as keys on array-like tables.


Re: [library] inspect.lua - print tables and debug beautiful

Posted: Sun Sep 21, 2014 9:06 am
by SuperZazu
As always, a simple & useful tool. Thank you, mate :)

Re: [library] inspect.lua - print tables and debug beautifully

Posted: Mon Jan 01, 2018 6:08 am
by Marty
Hey kikito, great work (not only on this lib).

Is it possible to make inspect work on metatables, too?