|#variables| , @table id, @table row, @table size , pretty print rows iterator, pretty print row index |_| Define our tables |#table, singles| , 1st |#table, doubles| , 1st, 2nd |#table, triples| , 1st, 2nd, 3rd |_| ports for reading the size of a table |#port, on get table size , needs, @get table size , reads, @table id| , @table size, @no such table |#port body, on get table size, lua| if self.tables[table_id] then counters["@table size"] = #self.tables[table_id] else counters["@no such table"] = 1 end |_| Read data from the command line and pump it into a table. |#port, on read singles, needs, @read singles| |#port body, on read singles, lua| local input = io.read("*a") for left, right in input:gmatch("(%d+)") do self.tables:push_row("singles", { ["1st"] = tonumber(left) or 0 } ) end |#port, on read doubles, needs, @read doubles| |#port body, on read doubles, lua| local input = io.read("*a") for left, right in input:gmatch("(%d+),%s*(%d+)") do self.tables:push_row("doubles", { ["1st"] = tonumber(left) or 0 , ["2nd"] = tonumber(right) or 0 } ) end |#port, on read triples, needs, @read triples| |#port body, on read triples, lua| local input = io.read("*a") for left, right in input:gmatch("(%d+),%s*(%d+),%s*(%d+)") do self.tables:push_row("triples", { ["1st"] = tonumber(left) or 0 , ["2nd"] = tonumber(right) or 0 , ["3rd"] = tonumber(right) or 0 } ) end |_| A generic operations over a table |#port, on pretty print row , needs, @pretty print row, , reads, @table id, @table row| |#port body, on pretty print row, lua| local rows = self.tables[table_id] local row = rows[table_row] io.write(rows.name .. " #" .. tostring(table_row) .. ": ") local mapping = self.tables.mappings[rows.name] local assembled_row = {} for key, index in pairs(mapping) do assembled_row[key] = row[index] end pprint(assembled_row) |_| loop to pretty print the rows of any table |pretty print rows| , clear (@table row) , get table size for (pretty print rows) , pretty printing rows |get table size for (pretty print rows)| , @get table size , move (@table size) to (pretty print rows iterator) |pretty printing rows, pretty print rows iterator| , pretty print row index , copy (pretty print row index) to (@table row) , pretty print row , next pretty print rows |pretty printing rows| |pretty print row| , @pretty print row |next pretty print rows| , pretty printing rows |pretty print row index| || 1st: read singles , 2nd: pretty print singles , 3rd: read doubles , 4th: pretty print doubles , 5th: read triples , 6th: pretty print triples |1st: read singles| , @read singles |2nd: pretty print singles| , select (singles) table , pretty print rows |3rd: read doubles| , @read doubles |4th: pretty print doubles| , select (doubles) table , pretty print rows |5th: read triples| , @read triples |6th: pretty print triples| , select (triples) table , pretty print rows