I remembered taktik posted a link to these before, but link seems forward to a GitHub root directory now? and I couldn`t find TestPatternIterators.lua there, to compare with your printout.
Anyway some good hacking! I may be back with some questions!
Original thread and quote:
https://forum.renoise.com/t/column-by-column-iterator/31113
Renoises pattern iterators are written in Lua. See https://code.google.com/p/xrnx/source/browse/trunk/UnitTests/TestPatternIterators.lua for the source
Should be relatively easy to copy and/or adopt to fit your needs?
EDIT:
Another post where he posted them up, though the formatting has been lost in the spoiler box: