Skip to content

Instantly share code, notes, and snippets.

@gamefreak
Created January 4, 2011 20:42
Show Gist options
  • Save gamefreak/765382 to your computer and use it in GitHub Desktop.
Save gamefreak/765382 to your computer and use it in GitHub Desktop.
__idmt = {
__lt = function(a, b)
if a[1] == b[1] then
if a[2] == nil then print(debug.traceback("A")) end
if b[2] == nil then print(debug.traceback("B")) end
return a[2] < b[2]
else
return a[1] < b[1]
end
end;
__le = function(a, b)
if a[1] == b[1] then
return a[2] <= b[2]
else
return a[1] <= b[1]
end
end;
__eq = function(a, b)
return a[1] == b[1] and a[2] == b[2]
end;
__tostring = function(a)
return (a[0] or "nil") .. ", " .. (a[1] or "nil")
end;
}
function ObjectIterator(list)
local function jaggedListIterator(list, index)
if index[2] == nil then
index[1] = next(list, index[1])
if index[1] == nil then
return nil
end
end
local i, k = next(list[index[1]], index[2])
print("DBG", index)
index[2] = i
return index, k
end
local nlt = {nil, nil}
setmetatable(nlt, __idmt)
return jaggedListIterator, list, nlt
end
list = {
{1, 2, 3, 4},
{5, 6, 7},
{8, 9, 10, 11, 12, 13, 14},
{15},
{16, 17, 18},
{19, 20},
}
for a, b in ObjectIterator(list) do
if b ~= nil then
print(a,": ", b)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment