r/lua • u/RelizForN • Feb 02 '26
My favorite part about coding in Lua..
..is having to write a custom function to print tables so I can actually debug.
I especially love watching that function get more complex than the project I'm trying to debug with it cause I want to use nested tables.
33
Upvotes
4
u/ggchappell Feb 02 '26 edited Feb 02 '26
But once you've written it, you never need to write it again. Right?
FWIW, here's my print-something function. Feel free to critique and/or improve.
3
u/RelizForN Feb 02 '26
This is just a joke in good faith, maybe Lua wasn't built for doing data analysis, and maybe I'm a newbie who doesn't know how to handle the language yet and overrelies on tables (bad habit from Python) but I still love using it
11
u/smtp_pro Feb 02 '26
https://github.com/kikito/inspect.lua
1
u/Denneisk Feb 02 '26
I am a bit curious just how complex these tables could really be to give you so much trouble.
9
u/[deleted] Feb 02 '26
step 1) VS code
step 2) https://github.com/tomblind/local-lua-debugger-vscode
step 3) look at locals and globals
step 4) delete post
step 5) ???
step 6) profit
3
u/collectgarbage Feb 02 '26
I think we have all written that function. It’s a Lua right of passage.
2
u/vitiral Feb 02 '26
Agreed, why I can't live without my handy dandy fmt module
https://civboot.github.io/lua/fmt.html
Also https://civboot.github.io/lua/ds.html#ds.log
1
u/Old_County5271 Feb 02 '26
I don't know if its penlight or stdlib that replaces print so it prints everything
1
u/xoner2 Feb 03 '26
Ah, yes indeed the recursive-table-pretty-printer is essential in the toolbox. There's lots already written but they never do exactly what we want so we write one personal:
I based mine on serpent. My beef with it is it does depth-first-search, so I modified it to be breadth-first, looks prettier. I still use serpent for serialization.