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