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