← Back to Gists

print table contents

📝 Lua
jortiz532
jortiz532 · Level 9 ·

This snippet prints all key-value pairs in a Lua table, making it easy to inspect the table's contents during debugging.

Lua
function printtable(t) for k, v in pairs(t) do print(tostring(k) .. ": " .. tostring(v)) end
end

Comments

1
shawn_henry99 shawn_henry99

@gregorytrujillo @gregory_trujillo that snippet works great for flat tables, but have you run into issues with nested tables where it just prints "table: 0x..." instead of recursing?