Page 1 of 1

[Lib] Microscope - Create visuals of Lua values

Posted: Tue Oct 22, 2013 7:52 am
by Roland_Yonaba
Hi all,

I enjoy digging in the Lua ecosytem, to see trending projects and learn from others code. That's the way I recently came accross a nice project that I wanted to share around here.

Let me introduce you to Microscope.

Image

The project is free, MIT Licensed, and maintained by Philipp Janda.

I'll just quote the main page about waht the project does, it is pure awesomeness.
Checking the value of a Lua variable during debugging is often invaluable and print() is a commonly used debugging tool. But what about complex table values? Many Lua programmers have written their own pretty-printer or data dumper and some even use it for (de-)serializing Lua data structures. But this seems to reach its limit when one takes cyclic references, metatables, upvalues and environment tables into account.
This module dumps arbitrarily complex Lua values as GraphViz .dot-files that can be transformed into a variety of image formats.
As a straigthforward example, shamelessly taken from the same page, the following code:

Code: Select all

local up1 = false
local up2 = io.stdout
local t1 = { val = 1 }
local t2 = { val = 2 }
setmetatable( t1, { __index = function( t, k )
  if t2[ k ] ~= nil then
    return t2[ k ]
  else
    return up1 or up2
  end
end } )
setmetatable( t2, { __index = t1 } )
Will be rendered this way:

Image

How nice is that ?

Links: Hope it helps, anyway. :awesome:

Re: [Lib] Microscope - Create visuals of Lua values

Posted: Tue Oct 22, 2013 2:27 pm
by ejmr
I have some nebulous, vague idea that combining Microscope with unit-testing frameworks and/or error output like blue-screens in LÖVE could create a form of awesomeness…

[]

Posted: Tue Oct 22, 2013 5:08 pm
by bekey
-snip-

Re: [Lib] Microscope - Create visuals of Lua values

Posted: Tue Oct 22, 2013 5:46 pm
by Davidobot
If you can somehow merge this into the error screen to show where the error happened, that would speed up debugging, a lot.

Re: [Lib] Microscope - Create visuals of Lua values

Posted: Tue Oct 22, 2013 5:51 pm
by Xgoff
that's pretty neat. i did something similar for luajit's -jv dumps but idk what happened to it

shows that graphviz could do some better layout organization lol

Re: [Lib] Microscope - Create visuals of Lua values

Posted: Tue Oct 22, 2013 8:00 pm
by kclanc
Nice find, that looks awesome! I made something similar for F# a few years back: http://diffable.codeplex.com/wikipage?t ... umentation.

For those wanting a good way to view DOT graphs, I recommend converting them to SVG files and viewing them using Squiggle: http://xmlgraphics.apache.org/batik/tools/browser.html.