Debian Codegraph @

dokidoki/components/exit_handler.lua

raw symbols SCIP
1 --- dokidoki.components.exit_handler
2 --- ================================
3 ---
4 --- Allows an action to be taken when an exit event is received.
5 ---
6 --- By default `kernel.abort_main_loop()` is called, assign another function to
7 --- `exit_handler.on_close` to do something else:
8 ---
9 --- function game.exit_handler.on_close()
10 --- -- do something
11 --- end
12
13 --- Implementation
14 --- --------------
15
16 local kernel = require 'dokidoki.kernel'
17 require 'glfw'
18
19 on_close = on_close or kernel.abort_main_loop
20 if trap_esc == nil then
21 trap_esc = false
22 end
23
24 game.actors.new_generic('exit_handler', function ()
25 function handle_event(event)
26 if event.type == 'quit' or
27 (trap_esc and event.type == 'key' and event.is_down and
28 event.key == glfw.KEY_ESC) then
29 on_close()
30 end
31 end
32 end)