A tip about printing

Something we have started to do is in our globals.lua we have these functions

function print_line(...)
	print(debug.getinfo(2).short_src .. ":" .. debug.getinfo(2).currentline)
	print(...)
end
function pprint_line(...)
	print(debug.getinfo(2).short_src .. ":" .. debug.getinfo(2).currentline)
	pprint(...)
end

We now use these instead of the normal print / pprint generally as first they have a clickable link in the console to go to the line in the file that is printing, and second when hunting for prints that are not needed anymore it is much easier to find where they are instead of trying to search through files where there may be many commented prints.

You can also monkey patch the builtin prints with these versions to find stray prints.

23 Likes

This is MINDBLOWING :exploding_head:

Thanks for the tip! First on the todo list for tomorrow.

4 Likes

So simple and elegant! Thank you.

3 Likes

Great tip! Just keep in mind that debug.getinfo() is pretty slow so don’t pepper your code with it!

3 Likes

I thought print(...) will ignored in the release build? Nope?

We don’t actually remove the print statements from the Lua scripts. We just won’t print out anything in the console.

Also, I think he meant that it may be performance heavy during development.

1 Like