LuaNET, the lua 5.1 api documentation!

Lua-Api

Core

print_r

function print_r ( t ) 
 	local print_r_cache={}
	local function sub_print_r(t,indent)
		if (print_r_cache[tostring(t)]) then
			print(indent.."*"..tostring(t))
		else
			print_r_cache[tostring(t)]=true
			if (type(t)=="table") then
				for pos,val in pairs(t) do
					if (type(val)=="table") then
						print(indent.."["..pos.."] => "..tostring(t).." {")
						sub_print_r(val,indent..string.rep(" ",string.len(pos)+8))
						print(indent..string.rep(" ",string.len(pos)+6).."}")
					else
						print(indent.."["..pos.."] => "..tostring(val))
					end
				end
			else
				print(indent..tostring(t))
			end
		end
	end
	sub_print_r(t,"  ")
end
Quite similar to PHP's print_r you can retrieve all data in a specific lua table or variable.
Code
xtab={}
xtab.foo={1,2,3}
xtab.bar={L=1,U=2,A=3}
> print_r(xtab)
--[[
 [bar] => table: 0033DAA0 {
            [U] => 2
            [L] => 1
            [A] => 3
          }
 [foo] => table: 0033DAA0 {
            [1] => 1
            [2] => 2
            [3] => 3
          }
]]

Comments

© 2007 DracoBlue :: Valid XHTML, CSS, RSS Powered by SMF 1.1.5 | SMF © 2006-2008, Simple Machines LLC | SourceNet © 2007, DracoBlue :: Page created in 0.151 seconds with 53 queries.