Before you wrote some PHP-like functions, here's a print_r () function with the following code:
Copy Code code as follows:
function PR (t, name, indent)
Local tablelist = {}
function Table_r (t, name, indent, full)
The local id = not full and name or type (name) ~= "number" and ToString (name) or '. Name... '] '
Local tag = indent. Id.. ' = '
Local out = {}--result
If Type (t) = = "Table" Then
If TABLELIST[T] ~= nil Then
Table.insert (out, tag. '{} -- ' .. Tablelist[t]. ' (self Reference) ')
Else
tablelist[t]= full. '.' .. ID) or ID
If Next (t) then--Table not empty
Table.insert (out, tag. '{')
For key,value in pairs (t) do
Table.insert (Out,table_r) (value,key,indent. '| ', Tablelist[t])
End
Table.insert (out,indent. '}')
Else Table.insert (Out,tag. ' {} ') end
End
Else
Local val = type (t) ~= "number" and type (t) ~= "boolean" and "".. ToString (t) ... ' "' or ToString (t)
Table.insert (out, tag.. val)
End
Return Table.concat (out, ' \ n ')
End
Return Table_r (t,name or ' Value ', indent or ')
End
function Print_r (t, name)
Print (PR (t,name))
End
Local A = {x=1, y=2, label={text= ' Hans ', Color= ' Blue '}, list={' A ', ' B ', ' C '}}
Print_r (a)