Difference between revisions of "love.errhand"

(Created page with "== Function == === Synopsis === <source lang="lua"> love.errhand( msg ) </source> === Arguments === {{param|string|msg|The error message.}} === Returns === Nothing. == Examples =...")
 
m (Added to callbacks category)
Line 76: Line 76:
 
</source>
 
</source>
 
== See Also ==
 
== See Also ==
 +
[[Category:Callbacks]]
 
* [[parent::love]]
 
* [[parent::love]]
 
{{#set:Description=}}
 
{{#set:Description=}}
 
== Other Languages ==
 
== Other Languages ==
 
{{i18n|love.errhand}}
 
{{i18n|love.errhand}}

Revision as of 04:09, 11 August 2013

Function

Synopsis

love.errhand( msg )

Arguments

string msg
The error message.

Returns

Nothing.

Examples

The default function used if you don't supply your own.

function love.errhand(msg)
	msg = tostring(msg)

	error_printer(msg, 2)

	if not love.graphics or not love.event or not love.graphics.isCreated() then
		return
	end

	-- Load.
	if love.audio then love.audio.stop() end
	love.graphics.reset()
	love.graphics.setBackgroundColor(89, 157, 220)
	local font = love.graphics.newFont(14)
	love.graphics.setFont(font)

	love.graphics.setColor(255, 255, 255, 255)

	local trace = debug.traceback()

	love.graphics.clear()

	local err = {}

	table.insert(err, "Error\n")
	table.insert(err, msg.."\n\n")

	for l in string.gmatch(trace, "(.-)\n") do
		if not string.match(l, "boot.lua") then
			l = string.gsub(l, "stack traceback:", "Traceback\n")
			table.insert(err, l)
		end
	end

	local p = table.concat(err, "\n")

	p = string.gsub(p, "\t", "")
	p = string.gsub(p, "%[string \"(.-)\"%]", "%1")

	local function draw()
		love.graphics.clear()
		love.graphics.printf(p, 70, 70, love.graphics.getWidth() - 70)
		love.graphics.present()
	end

	draw()

	local e, a, b, c
	while true do
		e, a, b, c = love.event.wait()

		if e == "quit" then
			return
		end
		if e == "keypressed" and a == "escape" then
			return
		end

		draw()

	end

end

See Also

Other Languages