-- Stuff to load before everything else --[[ rewrite traceback function to map file names and line numbers to moonscript ]] local require_order = {} local old_traceback = debug.traceback debug.traceback = function(...) local orig_traceback = old_traceback(...) local noprint = {} return orig_traceback:gsub("([%w/_]+%.lua):(%d+):",function(filename, linenum) --If our file is not moonscript, we won't have a debug file local debugfile = am.load_string(filename .. ".X") if not debugfile then return filename .. ":" .. linenum .. ":" end debugfile = debugfile .. "\n" for line in debugfile:gmatch("([^\n]+)\n") do local _,_,pos,lua,moon = line:find("(%d+)%s+(%d+):%b[] >> (%d+)") if pos and lua and moon and tonumber(linenum) == tonumber(lua) then filename = filename:gsub(".lua$",".moon") linenum = moon break end end return string.format("%s:%d:", filename, linenum) end) .. "\nRequire order: [" .. table.concat(require_order, ",\n") .. "]" end local old_require = require local required = {} require = function(...) args = {...} if not required[args[1]] then required[args[1]] = true table.insert(require_order, args[1]) end return old_require(...) end --[[ Display where print statements are comming from local oldprint = print print = function(...) oldprint(...) oldprint(debug.traceback()) end ]] -- Override tostring to display more info about the table local old_tostring = tostring local numtabs = 0 local printed_tables = {} local function tostring_helper(el) assert(type(el) == "table", "Tried to call helper with something that was not a table, it was a " .. type(el)) local mt = getmetatable(el) if mt and mt.__tostring then return mt.__tostring(el) elseif printed_tables[el] == true then return old_tostring(el) else printed_tables[el] = true numtabs = numtabs + 1 local strbuilder = {"{"} for k,v in pairs(el) do local key,value if type(k) == "table" then key = tostring_helper(k) else key = old_tostring(k) end if type(v) == "table" then value = tostring_helper(v) else value = old_tostring(v) end strbuilder[#strbuilder + 1] = string.format("%s%s : %s", string.rep("\t",numtabs), key, value) end strbuilder[#strbuilder + 1] = string.rep("\t",numtabs - 1) .. "}" numtabs = numtabs - 1 return table.concat(strbuilder,"\n") end end function tostring(el) printed_tables = {} if type(el) == "table" then return tostring_helper(el) end return old_tostring(el) end