Advertisement
McDunkinY

Untitled

Aug 14th, 2016
523
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.11 KB | None | 0 0
  1. function PrintTable( Table )
  2.  
  3.     local Cache = { }
  4.  
  5.     local function SubPrintTable( Table, Level )
  6.  
  7.         local Indent1 = ( " " ):rep( Level * 4 )
  8.         local Indent2 = ( " " ):rep( ( Level - 1 ) * 4 )
  9.  
  10.         if ( Cache[ tostring( Table ) ] ) then
  11.  
  12.             print( Indent1 .. "*" .. tostring( Table ) )
  13.  
  14.         else
  15.  
  16.             Cache[ tostring( Table ) ] = true
  17.  
  18.             if ( type( Table ) == "table" ) then
  19.  
  20.                 for Key, Value in pairs( Table ) do
  21.  
  22.                     Key = tostring( Key )
  23.  
  24.                     if ( type( Value ) == "table" ) then
  25.  
  26.                         print( ( "%s[ %q ] = {" ):format( Indent1, Key ) )
  27.                         SubPrintTable( Value, Level + 1 )
  28.                         print( Indent2 .. ( " " ):rep( 4 ) .. "}" )
  29.  
  30.                     elseif ( type( Value ) == "string" ) then
  31.  
  32.                         print( ( "%s[ %q ] = %q," ):format( Indent1, Key, Value ) )
  33.  
  34.                     else
  35.  
  36.                         print( ( "%s[ %q ] = %s," ):format( Indent1, Key, tostring( Value ) ) )
  37.  
  38.                     end
  39.  
  40.                 end
  41.  
  42.             else
  43.  
  44.                 print( Indent1 )
  45.  
  46.             end
  47.  
  48.         end
  49.  
  50.     end
  51.  
  52.     if ( type( Table ) == "table" ) then
  53.  
  54.         print( tostring( Table ) .. " = {" )
  55.         SubPrintTable( Table, 1 )
  56.         print( "}" )
  57.  
  58.     else
  59.  
  60.         SubPrintTable( Table, 1 )
  61.  
  62.     end
  63.  
  64. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement