fork/m-overlay
git clone https://git.julia.blue/fork/m-overlay
7e0ab3b
v2.1.1b
1local utf8 =require ( "utf8" ) 2local log =require ( "log" ) 3 4function love . errorhandler ( msg ) 5love . filesystem . createDirectory ( "crashlog" ) 6 7local sanitizedmsg ={} 8for char in msg : gmatch ( utf8 . charpattern ) do 9table . insert ( sanitizedmsg , char ) 10end 11sanitizedmsg =table . concat ( sanitizedmsg ) 12 13local trace =debug . traceback ( sanitizedmsg , 3 ) 14log . error ( trace ) 15 16local f =love . filesystem . newFile ( os . date ( "crashlog/crash-%Y%m%d-%H%M%S.txt" ), "a" ) 17 18if not love . window or not love . graphics or not love . event then 19return 20end 21 22if not love . graphics . isCreated () or not love . window . isOpen () then 23local success , status =pcall ( love . window . setMode , 800 , 600 ) 24if not success or not status then 25return 26end 27end 28 29-- Reset state. 30if love . mouse then 31love . mouse . setVisible ( true ) 32love . mouse . setGrabbed ( false ) 33love . mouse . setRelativeMode ( false ) 34if love . mouse . isCursorSupported () then 35love . mouse . setCursor () 36end 37end 38if love . joystick then 39-- Stop all joystick vibrations. 40for i , v in ipairs ( love . joystick . getJoysticks ()) do 41v : setVibration () 42end 43end 44if love . audio then love . audio . stop () end 45 46love . graphics . reset () 47local font =love . graphics . setNewFont ( 14 ) 48 49love . graphics . setColor ( 255 , 255 , 255 ) 50 51love . graphics . origin () 52 53local err ={} 54 55if # sanitizedmsg ~= # msg then 56table . insert ( err , "Invalid UTF-8 string in error message." ) 57end 58 59table . insert ( err , trace ) 60 61local p =table . concat ( err , "\n" ) 62 63f : write ( p ) 64f : close () 65 66local function draw () 67if not love . graphics . isActive () then return end 68local pos =8 69love . graphics . clear ( 89 , 157 , 220 ) 70love . graphics . printf ( p , pos , pos , love . graphics . getWidth () - pos ) 71love . graphics . present () 72end 73 74local fullErrorText =p 75local function copyToClipboard () 76if not love . system then return end 77love . system . setClipboardText ( fullErrorText ) 78p =p .. "\nCopied to clipboard!" 79end 80 81if love . system then 82p =p .. "\n\nPress Ctrl+C or tap to copy this error" 83end 84 85return function () 86love . event . pump () 87 88for e , a , b , c in love . event . poll () do 89if e == "quit" then 90return 1 91elseif e == "keypressed" and a == "escape" then 92return 1 93elseif e == "keypressed" and a == "c" and love . keyboard . isDown ( "lctrl" , "rctrl" ) then 94copyToClipboard () 95elseif e == "touchpressed" then 96local name =love . window . getTitle () 97if # name == 0 or name == "Untitled" then name ="Game" end 98local buttons ={ "OK" , "Cancel" } 99if love . system then 100buttons [ 3 ] ="Copy to clipboard" 101end 102local pressed =love . window . showMessageBox ( "Quit " .. name .. "?" , "" , buttons ) 103if pressed == 1 then 104return 1 105elseif pressed == 3 then 106copyToClipboard () 107end 108end 109end 110 111draw () 112 113if love . timer then 114love . timer . sleep ( 0.1 ) 115end 116end 117 118end