From ca9e012357944ef2213a14d3668aa73b14a91bb4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Enrique=20Garc=C3=ADa=20Cota?= Date: Tue, 10 May 2011 00:48:23 +0200 Subject: [PATCH] edited README --- README.textile | 55 ++++++++++++++++++++++++++++++-------------------- 1 file changed, 33 insertions(+), 22 deletions(-) diff --git a/README.textile b/README.textile index e8c4453..a8f45f1 100644 --- a/README.textile +++ b/README.textile @@ -8,11 +8,11 @@ h1. Examples of use "Array-like" tables are rendered horizontally: -
inspect({1,2,3,4}) == "{ 1, 2, 3, 4 }"
+
inspect({1,2,3,4}) == "<1>{ 1, 2, 3, 4 }"
"dictionary-like" tables are rendered with one element per line: -
inspect({a=1,b=2}) == [[{
+
inspect({a=1,b=2}) == [[<1>{
   a = 1,
   b = 2
 }]]
@@ -22,7 +22,7 @@ The keys will be sorted alphanumerically when possible. "Hybrid" tables will have the array part on the first line, and the dictionary part just below them:
-inspect({1,2,3,a=1,b=2}) == [[{ 1, 2, 3,
+inspect({1,2,3,a=1,b=2}) == [[<1>{ 1, 2, 3,
   a = 1,
   b = 2
 }]]
@@ -31,8 +31,8 @@ inspect({1,2,3,a=1,b=2}) == [[{ 1, 2, 3,
 Tables can be nested, and will be indented with two spaces per level.
 
 
-inspect({a={b=2}}) = [
-  a = {
+inspect({a={b=2}}) = [[<1>{
+  a = <2>{
     b = 2
   }
 }]]
@@ -42,10 +42,10 @@ By default, @inspect@ will stop rendering at a depth of 4 levels. When that poin
 
 
 local t5 = {a = {b = {c = {d = {e = 5}}}}}
-inspect(t5) == [[
-  a = {
-    b = {
-      c = {
+inspect(t5) == [[<1>{
+  a = <2>{
+    b = <3>{
+      c = <4>{
         d = {...}
       }
     }
@@ -56,17 +56,17 @@ inspect(t5) == [[
 You can increase/decrease the max depth with the second parameter:
 
 
-inspect(t5, 2) == [[{
-  a = {
+inspect(t5, 2) == [[<1>{
+  a = <2>{
     b = {...}
   }
 }]])
 
-inspect(t5, 7) == [[{
-  a = {
-    b = {
-      c = {
-        d = {
+inspect(t5, 7) == [[<1>{
+  a = <2>{
+    b = <3>{
+      c = <4>{
+        d = <5>{
           e = 5
         }
       }
@@ -75,13 +75,13 @@ inspect(t5, 7) == [[{
 }]])
 
-Functions, userdata and threads are simply rendered as @@, @@ and @@ respectively: +Functions, userdata and threads are simply rendered as @@, @@ and @@ respectively:
 inspect({ f = print, ud = some_user_data, thread = a_thread} ) == [[{
-  f = ,
-  u = ,
-  thread = 
+  f = ,
+  u = ,
+  thread = 
 }]])
 
@@ -89,14 +89,25 @@ inspect({ f = print, ud = some_user_data, thread = a_thread} ) == [[{ If the table has a metatable, inspect will include it at the end, in a special field called @@:
-inspect(setmetatable({a=1}, {b=2}) == [[{
+inspect(setmetatable({a=1}, {b=2}) == [[<1>{
   a = 1
-   = {
+   = <2>{
     b = 2
   }
 }]])
 
+You may have noticed that all tables are preceded by an @@ string. If a table has already been printed out, @inspect@ will just print @@ the second time it finds it. This will infinite loops. + +
+a = {1,2}
+b = {3,4,a}
+a[3] = b
+inspect(a) = "<1>{ 1, 2, <2>{ 3, 4, 
} }" + + +Notice how the second appearance of @a@ was replaced by @
@ in the string above. + h1. Gotchas / Warnings This method is *not* appropiate for saving/restoring tables. It is ment to be used by the programmer mainly while debugging a program.