Share your favourite helper functions
Posted: Tue Nov 13, 2012 5:07 am
I've found that building up a library of helper functions can really speed up programming and debugging in Löve/Lua.
I've called them "helper functions" in the title, but basically any techniques, modules, functions etc. that you use a lot and have saved you a lot of time would be great. Share them! :D
I'll start:
Coloured Logging Function
Prints out the filename and line where the log command was called. This coupled with Kikito's ansicolors has made debugging a lot easier for me. You can find where that print statement is hiding in a large project, and visually trace through the code.
You can make a key toggle helper.DEBUG_ON to see how your game performs without all the STDOUT spam slowing it down.
It looks like:
I've called them "helper functions" in the title, but basically any techniques, modules, functions etc. that you use a lot and have saved you a lot of time would be great. Share them! :D
I'll start:
Coloured Logging Function
Prints out the filename and line where the log command was called. This coupled with Kikito's ansicolors has made debugging a lot easier for me. You can find where that print statement is hiding in a large project, and visually trace through the code.
You can make a key toggle helper.DEBUG_ON to see how your game performs without all the STDOUT spam slowing it down.
It looks like:
Code: Select all
local colors = require("ansicolors")
helper.DEBUG_ON = true
function log(...)
if not helper.DEBUG_ON then return end
local info = debug.getinfo(2, "Sl")
if info then
print(string.format(colors("%{cyan}[%s]:%{green}%d%{reset}"), info.short_src, info.currentline), ...)
else
print(...)
end
end
-- Call it with:
log("Some result is ", result)