Difference between revisions of "love.errhand (Polski)"
Line 1: | Line 1: | ||
+ | {{deprecatedin|[[0.11.0]]|110|new=[[love.errorhandler (Polski)|love.errorhandler]]}} | ||
+ | |||
Procedura obsługi wyjątków, używana do wyświetlania błędów. | Procedura obsługi wyjątków, używana do wyświetlania błędów. | ||
== Funkcja == | == Funkcja == | ||
Line 10: | Line 12: | ||
Żadna | Żadna | ||
== Przykłady == | == Przykłady == | ||
− | {{newin|[[0.9.0]]|090|type=variant}} | + | {{newin (Polski)|[[0.10.0]]|100|type=variant}} |
+ | === Domyślna implementacja === | ||
+ | <source lang="lua"> | ||
+ | -- wypisywanie błędu na konsoli | ||
+ | local function error_printer(wiadomosc, layer) | ||
+ | print((debug.traceback("Error: " .. tostring(wiadomosc), 1+(layer or 1)):gsub("\n[^\n]+$", ""))) | ||
+ | end | ||
+ | |||
+ | function love.errhand(wiadomosc) | ||
+ | wiadomosc = tostring(wiadomosc) | ||
+ | |||
+ | error_printer(wiadomosc, 2) | ||
+ | |||
+ | -- jeśli nie istnieje okno love lub niezbędne moduły | ||
+ | -- nie jesteśmy w stanie nic więcej zrobić | ||
+ | if not love.window or not love.graphics or not love.event then | ||
+ | return | ||
+ | end | ||
+ | |||
+ | if not love.graphics.isCreated() or not love.window.isOpen() then | ||
+ | local success, status = pcall(love.window.setMode, 800, 600) | ||
+ | if not success or not status then | ||
+ | return | ||
+ | end | ||
+ | end | ||
+ | |||
+ | -- Przywrócenie domyślnych ustawień urządzeń | ||
+ | if love.mouse then | ||
+ | love.mouse.setVisible(true) | ||
+ | love.mouse.setGrabbed(false) | ||
+ | love.mouse.setRelativeMode(false) | ||
+ | end | ||
+ | if love.joystick then | ||
+ | -- Stop all joystick vibrations. | ||
+ | for i,v in ipairs(love.joystick.getJoysticks()) do | ||
+ | v:setVibration() | ||
+ | end | ||
+ | end | ||
+ | if love.audio then love.audio.stop() end | ||
+ | love.graphics.reset() | ||
+ | local font = love.graphics.setNewFont(math.floor(love.window.toPixels(14))) | ||
+ | |||
+ | love.graphics.setBackgroundColor(89, 157, 220) | ||
+ | love.graphics.setColor(255, 255, 255, 255) | ||
+ | |||
+ | local trace = debug.traceback() | ||
+ | |||
+ | love.graphics.clear(love.graphics.getBackgroundColor()) | ||
+ | love.graphics.origin() | ||
+ | |||
+ | local err = {} | ||
+ | |||
+ | table.insert(err, "Error\n") | ||
+ | table.insert(err, wiadomosc.."\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() | ||
+ | local pos = love.window.toPixels(70) | ||
+ | love.graphics.clear(love.graphics.getBackgroundColor()) | ||
+ | love.graphics.printf(p, pos, pos, love.graphics.getWidth() - pos) | ||
+ | love.graphics.present() | ||
+ | end | ||
+ | |||
+ | while true do | ||
+ | love.event.pump() | ||
+ | |||
+ | for e, a, b, c in love.event.poll() do | ||
+ | if e == "quit" then | ||
+ | return | ||
+ | elseif e == "keypressed" and a == "escape" then | ||
+ | return | ||
+ | elseif e == "touchpressed" then | ||
+ | local name = love.window.getTitle() | ||
+ | if #name == 0 or name == "Untitled" then name = "Game" end | ||
+ | local buttons = {"OK", "Cancel"} | ||
+ | local pressed = love.window.showMessageBox("Quit "..name.."?", "", buttons) | ||
+ | if pressed == 1 then | ||
+ | return | ||
+ | end | ||
+ | end | ||
+ | end | ||
+ | |||
+ | draw() | ||
+ | |||
+ | if love.timer then | ||
+ | love.timer.sleep(0.1) | ||
+ | end | ||
+ | end | ||
+ | |||
+ | end | ||
+ | </source> | ||
+ | {{newinoldin (Polski)|[[0.9.0]]|090|[[0.9.2]]|092|type=variant}} | ||
=== Domyślna implementacja === | === Domyślna implementacja === | ||
<source lang="lua"> | <source lang="lua"> | ||
Line 23: | Line 127: | ||
error_printer(wiadomosc, 2) | error_printer(wiadomosc, 2) | ||
− | -- jeśli | + | -- jeśli nie istnieje okno love lub niezbędne moduły |
-- nie jesteśmy w stanie nic więcej zrobić | -- nie jesteśmy w stanie nic więcej zrobić | ||
if not love.window or not love.graphics or not love.event then | if not love.window or not love.graphics or not love.event then | ||
Line 102: | Line 206: | ||
</source> | </source> | ||
---- | ---- | ||
− | {{oldin|[[0.9.0]]|090|type=variant|text=Ta wersja jest używana we wcześniejszych wersjach LOVE.}} | + | {{oldin (Polski)|[[0.9.0]]|090|type=variant|text=Ta wersja jest używana we wcześniejszych wersjach LOVE.}} |
=== Domyślna implementacja === | === Domyślna implementacja === | ||
<source lang="lua"> | <source lang="lua"> |
Revision as of 21:53, 26 August 2018
Deprecated in LÖVE 0.11.0 |
It is deprecated and will be removed in a future version. |
Procedura obsługi wyjątków, używana do wyświetlania błędów.
Funkcja
Sygnatura
love.errhand( wiadomosc )
Argumenty
string wiadomosc
- Wiadomość z komunikatem błędu.
Wartość zwracana
Żadna
Przykłady
Dostępne od wersji LÖVE 0.10.0 |
Ten wariant nie jest dostępny we wcześniejszych wersjach. |
Domyślna implementacja
-- wypisywanie błędu na konsoli local function error_printer(wiadomosc, layer) print((debug.traceback("Error: " .. tostring(wiadomosc), 1+(layer or 1)):gsub("\n[^\n]+$", ""))) end function love.errhand(wiadomosc) wiadomosc = tostring(wiadomosc) error_printer(wiadomosc, 2) -- jeśli nie istnieje okno love lub niezbędne moduły -- nie jesteśmy w stanie nic więcej zrobić if not love.window or not love.graphics or not love.event then return end if not love.graphics.isCreated() or not love.window.isOpen() then local success, status = pcall(love.window.setMode, 800, 600) if not success or not status then return end end -- Przywrócenie domyślnych ustawień urządzeń if love.mouse then love.mouse.setVisible(true) love.mouse.setGrabbed(false) love.mouse.setRelativeMode(false) end if love.joystick then -- Stop all joystick vibrations. for i,v in ipairs(love.joystick.getJoysticks()) do v:setVibration() end end if love.audio then love.audio.stop() end love.graphics.reset() local font = love.graphics.setNewFont(math.floor(love.window.toPixels(14))) love.graphics.setBackgroundColor(89, 157, 220) love.graphics.setColor(255, 255, 255, 255) local trace = debug.traceback() love.graphics.clear(love.graphics.getBackgroundColor()) love.graphics.origin() local err = {} table.insert(err, "Error\n") table.insert(err, wiadomosc.."\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() local pos = love.window.toPixels(70) love.graphics.clear(love.graphics.getBackgroundColor()) love.graphics.printf(p, pos, pos, love.graphics.getWidth() - pos) love.graphics.present() end while true do love.event.pump() for e, a, b, c in love.event.poll() do if e == "quit" then return elseif e == "keypressed" and a == "escape" then return elseif e == "touchpressed" then local name = love.window.getTitle() if #name == 0 or name == "Untitled" then name = "Game" end local buttons = {"OK", "Cancel"} local pressed = love.window.showMessageBox("Quit "..name.."?", "", buttons) if pressed == 1 then return end end end draw() if love.timer then love.timer.sleep(0.1) end end end
Dostępne od wersji LÖVE 0.9.0, usunięte w wersji LÖVE 0.9.2 |
Ten wariant nie jest dostępny we wcześniejszych lub późniejszych wersjach. |
Domyślna implementacja
-- wypisywanie błędu na konsoli local function error_printer(wiadomosc, layer) print((debug.traceback("Error: " .. tostring(wiadomosc), 1+(layer or 1)):gsub("\n[^\n]+$", ""))) end function love.errhand(wiadomosc) wiadomosc = tostring(wiadomosc) error_printer(wiadomosc, 2) -- jeśli nie istnieje okno love lub niezbędne moduły -- nie jesteśmy w stanie nic więcej zrobić if not love.window or not love.graphics or not love.event then return end if not love.graphics.isCreated() or not love.window.isCreated() then if not pcall(love.window.setMode, 800, 600) then return end end -- Przywrócenie domyślnych ustawień urządzeń if love.mouse then love.mouse.setVisible(true) love.mouse.setGrabbed(false) end if love.joystick then for i,v in ipairs(love.joystick.getJoysticks()) do v:setVibration() -- Przerwij wibracje wszystkich joysticków end end if love.audio then love.audio.stop() end love.graphics.reset() love.graphics.setBackgroundColor(89, 157, 220) local font = love.graphics.setNewFont(14) love.graphics.setColor(255, 255, 255, 255) local trace = debug.traceback() love.graphics.clear() love.graphics.origin() local err = {} table.insert(err, "Error\n") table.insert(err, wiadomosc.."\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 while true do love.event.pump() for e, a, b, c in love.event.poll() do if e == "quit" then return end if e == "keypressed" and a == "escape" then return end end draw() if love.timer then love.timer.sleep(0.1) end end end
Usunięte w wersji LÖVE 0.9.0 |
Ta wersja jest używana we wcześniejszych wersjach LOVE.. |
Domyślna implementacja
-- wypisywanie błędu na konsoli local function error_printer(wiadomosc, layer) print((debug.traceback("Error: " .. tostring(wiadomosc), 1+(layer or 1)):gsub("\n[^\n]+$", ""))) end function love.errhand(wiadomosc) wiadomosc = tostring(wiadomosc) error_printer(wiadomosc, 2) if not love.graphics or not love.event or not love.graphics.isCreated() then return end -- Przywrócenie domyślnych ustawień urządzeń 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, wiadomosc.."\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
Zobacz również
Inne języki
Dansk –
Deutsch –
English –
Español –
Français –
Indonesia –
Italiano –
Lietuviškai –
Magyar –
Nederlands –
Polski –
Português –
Română –
Slovenský –
Suomi –
Svenska –
Türkçe –
Česky –
Ελληνικά –
Български –
Русский –
Српски –
Українська –
עברית –
ไทย –
日本語 –
正體中文 –
简体中文 –
Tiếng Việt –
한국어
More info