[Lib] Microscope - Create visuals of Lua values

General discussion about LÖVE, Lua, game development, puns, and unicorns.
Post Reply
User avatar
Roland_Yonaba
Inner party member
Posts: 1563
Joined: Tue Jun 21, 2011 6:08 pm
Location: Ouagadougou (Burkina Faso)
Contact:

[Lib] Microscope - Create visuals of Lua values

Post 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:
User avatar
ejmr
Party member
Posts: 302
Joined: Fri Jun 01, 2012 7:45 am
Location: South Carolina, U.S.A.
Contact:

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

Post 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…
ejmr :: Programming and Game-Dev Blog, GitHub
南無妙法蓮華經
bekey
Party member
Posts: 255
Joined: Tue Sep 03, 2013 6:27 pm

[]

Post by bekey »

-snip-
Last edited by bekey on Fri Jan 24, 2014 2:09 am, edited 1 time in total.
User avatar
Davidobot
Party member
Posts: 1226
Joined: Sat Mar 31, 2012 5:18 am
Location: Oxford, UK
Contact:

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

Post 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.
PM me on here or elsewhere if you'd like to discuss porting your game to Nintendo Switch via mazette!
personal page and a raycaster
User avatar
Xgoff
Party member
Posts: 211
Joined: Fri Nov 19, 2010 4:20 am

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

Post 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
kclanc
Citizen
Posts: 89
Joined: Sun Jan 29, 2012 6:39 pm

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

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

Who is online

Users browsing this forum: Google [Bot] and 3 guests