lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


>From PA's email a while back, I downloaded the print-table
implementation at:

http://dev.alt.textdrive.com/browser/HTTP/Data.lua

Works great, except the output is all on one line.  I changed line
110, added a newline to the format string, so it looks like this:

aBuffer[ #aBuffer + 1 ] = ( '\n%s[%s]=%s' ):format( aName, aKey, aValue )

Using PA's usage example, the output with my change is:

_[1]="banana"
_[2]={}
_[2]["qty"]=45
_[2]["fruit"]="mango"

I find this output style helpful, especially with complex nested tables.

Mason Deaver

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

> From: PA <petite.abeille@gmail.com>
> To: Lua list <lua@bazar2.conectiva.com.br>
> Date: Sun, 19 Aug 2007 10:44:17 +0200
> Subject: Re: Function to improve on 'print(table)'...
>
> On Aug 19, 2007, at 08:25, Duck wrote:
>
> >  It's meant to be a sort of legible serialisation for troubleshooting
> > your data.
>
> I guess you could go the whole nine yards and provide a proper serialization mechanism then :)
>
> "Recursive table print/serialization"
> http://lua-users.org/wiki/LuaRecipes
>
> Here is yet another implementation:
>
> http://dev.alt.textdrive.com/browser/HTTP/Data.lua
>
> Usage example:
>
> local Data = require( 'Data' )
> local aTable = {}
>
> aTable[ 1 ] = 'banana'
> aTable[ 2 ] = { fruit = 'mango', qty = 45 }
>
> print( Data( aTable ) )
>
>  > _[1]="banana" _[2]={} _[2]["qty"]=45 _[2]["fruit"]="mango"
>