All pastes #102915 Raw Edit

Something

public text v1 · immutable
#102915 ·published 2006-07-27 23:51 UTC
rendered paste body
function TestIter(t)
	local i = 0
	local n = table.getn(t)
	return function()
		i = i + 1
		if i <= n then return t[i] end
	end
end

table1 = {"A", "B", "C"}
table1["A"] = "hello"
table1["B"] = "lua"
table1["C"] = "world"

table2 = {"A", "B", "C"}
table2["A"] = {}
table2["A"].x = "hello"
table2["B"] = {}
table2["B"].x = "lua"
table2["C"] = {}
table2["C"].x = "world"

function Squishy:Test()
	for obj in TestIter(table1) do
		print(obj) -- works
	end
	for obj in TestIter(table2) do
		print(obj.x) -- attempt to index local `obj' (a string value)
	end
end