Skip to content

Instantly share code, notes, and snippets.

View britzl's full-sized avatar
💭
Making Defold even better!

Björn Ritzl britzl

💭
Making Defold even better!
View GitHub Profile
@britzl
britzl / prettyprint.lua
Created April 2, 2014 21:27
Example of how to override print and pretty-print tables
-- keep the original print()
local _print = print
local indentation = ""
--- Pretty print a value
-- If the value is a table it's content will be printed as well (recursively)
local function pretty_print(value)
local t = type(value)
if t ~= "table" then
@britzl
britzl / errorhandler.lua
Created April 2, 2014 20:08
Example of how to wrap script entry points to be able to do custom error handling
local function on_error(err)
print("In custom error handler:", err)
-- something went wrong, handle error here
-- report to client health for instance
-- print(debug.traceback())
-- dump tables
end
local function do_something(a_number)
-- if this check fails it will be caught by the error handler
@britzl
britzl / traceback.lua
Created April 2, 2014 16:15
Example of how debug.traceback() works
local function a()
print(debug.traceback())
end
local function b()
a()
end
local function c()
b()