YaGames - Yandex.Games SDK for Defold

Yes! This is a great idea.

Also, you can set up a custom error handler to log Lua errors to the browser console in the release build:

local function setup_error_handler()
    if html5 and not sys.get_engine_info().is_debug then
        sys.set_error_handler(function(source, message, traceback)
            local s = source:gsub("'", "\\'"):gsub("\n", "\\n"):gsub("\r", "\\r")
            local m = message:gsub("'", "\\'"):gsub("\n", "\\n"):gsub("\r", "\\r")
            local t = traceback:gsub("'", "\\'"):gsub("\n", "\\n"):gsub("\r", "\\r")

            local pstatus, perr = pcall(html5.run, "console.error('LUA ERROR: (" .. s .. ")\\n" .. m .. "\\n" .. t .. "')")
            if not pstatus then
                -- Never happens
                print("FATAL: html5.run(..) failed: " .. perr)
            end
        end)
    end
end

-- do this in the main script of your bootstrap collection
function init(self)
    setup_error_handler()
end
6 Likes