Enhance printTable with a label

Tips on how to write a feature request:

  1. Describe your reason for requesting this feature. What problems are you running into?
    Add an optional label to printTable(table). e.g.:
printTable("Characters", characterTable)
  1. How would this request improve your experience developing for Playdate?

It will make the debugging output more readable. e.g.

===Characters===
{
	[Bowser] = {
		[name] = Bowser,
		[side] = Baddie,
	},
	[Mario] = {
		[name] = Mario,
		[side] = Goodie,
	},
}
  1. Include any other details you have relating to this request.
    I added the === because I think it makes it clear that its a title. Just personal preference though.
4 Likes

I think that having the printTable function as bare as possible might be better for clarity of the output. And secondly, you can already pass several arguments into both print and printTable functions (and they don’t even need to be all tables in the second case). It will print them all on one line. I like to use prints with values interspersed with labels like this:

print("x", x, "y", y)
--> x 16 y 22

printTable("Characters", t)
--> Characters {
-->   ...
--> }

It won’t format the title nicely, it just drops it into the output. However, you can define a global function to improve on that for your own purposes

function printTableDX(title, t)
	printTable("=== " .. title .. " ===", t)
end

 -- less fancy name, like "pt()" may be helpful, too :D
3 Likes