Log In  
Follow
PoorCosmo

This is some code I wrote to nicely stringify tables. This code started life as a printh() replacement that output directly to the console, but I rewrote it as seen below so it can be used in other contexts.

The strngfy() function can produce either indented, multi-line code, or single-line compact output. Both scalar values and tables are supported as both keys and values.

The rptsp() and tcnt() functions are support functions used by strngfy(), but they also have utility as stand-alone functions.

The code is probably not particularly elegant, but it works for the scenarios I tested. There are some comments in the code to help users get started. All lines fit within the line-width of Pico-8's built-in editor.

The code is 238 tokens.

I'm new to both Pico-8 and Lua, so if I did something the hard way, or missed some tricks, or if you find bugs, let me know.

Updates

  • 04/25/2023
    • Updated function to format function types in table
  • 04/30/2023
    • Same thing for booleans. Code is now 246 tokens.

[ Continue Reading.. ]

2
1 comment