Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local t =
- {
- one =
- {
- state = "storage",
- locat = {station = 1, row = 5, collum = 3}
- prior = 3,
- descr = "This is description 1!"
- },
- two =
- {
- state = "storage",
- locat = {station = 1, row = 5, collum = 4}
- prior = 1,
- descr = "This is description 2!"
- },
- three =
- {
- state = "track",
- locat = {station = 1, row = 5, collum = 5}
- prior = 2,
- descr = "This is description 3!"
- }
- }
- local function storage(t)
- local curr = 0
- local toDo = {}
- --populate toDo table
- for i, j in pairs(t) do
- if j["state"] == "storage" then
- toDo[#toDo + 1] = i
- end
- end
- table.sort(toDo)
- --iterator stuff
- return function()
- curr = curr + 1
- --stop condition
- if curr <= #toDo then
- --for loop parameters return
- return toDo[curr], t[toDo[curr]]
- else
- return nil
- end
- end
- end
- for name, data in storage(t) do
- print(name..": "..data["descr"])
- end
Advertisement
Add Comment
Please, Sign In to add comment