lua-users home
lua-l archive

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


Hello all,

I'm having a problem with a recursive function in Lua; I'm sure it's a silly
mistake, but it's eluding me at the moment.  Given the following code:


mytab = {a = 1, b = 2, c = {ca = 5, cb = 7, cc = 9}, d = 3, e = {ea = 12, eb
= {eea = 69, eeb = 72}, ec = 48}}

function savetab(t)
	for i, v in t do
		if type(v) == "table" then
			savetab(v)
			return
		else
			print ("Savetab: "..i.."="..v)
		end
	end
end

savetab(mytab)


I get the following for output:

Savetab:  a=1
Savetab:  ca=5
Savetab:  cc=9
Savetab:  cb=7


Looks like it's stopping after the first nested table it encounters...any
idea why?

Thanks,

--jsm