RobPol

Dump tables in lua

Discussion created by RobPol on Jun 28, 2012
Latest reply on Jul 20, 2012 by MattGruber

When you get a table back from a nimbus.request it is sometimes handy to be able to dump it out and examine it in the lua ide. Here is a simple table dump function so you can see what's what.  Works with nested tables but I suspect it would choke on anything too complicated (eg functions held in a table)

 

 

----------------------------------------------------------------------------------------------------

--

-- function tdump

--

-- Print a table with possible nested tables

--

----------------------------------------------------------------------------------------------------

 

function tdump ( tab, indent )
   if indent == nil then indent = "" end
   indent = indent.."  "
   if type (tab) ~= "table" then
      print ("invoke with a table, you sent me a: ",type (tab) )
      return
   end
   for k,v in pairs (tab) do
      if type (v) == "table" then
         print (indent,k," <TABLE>")
         tdump (v, indent)
      else
         print (indent,k," = ",v)
      end
   end
end

 

----------------------------------------------------------------------------------------------------

-- test it

----------------------------------------------------------------------------------------------------

rlist = Nimbus.request("hub", "getrobots")

tdump (rlist)

----------------------------------------------------------------------------------------------------

Outcomes