-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpira-run.lua
46 lines (34 loc) · 970 Bytes
/
pira-run.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
local curses, socket = pira.get_dependencies()
local error = function(error)
curses.endwin ()
print("Caught an error:")
print(debug.traceback(error, 2))
os.exit(2)
end
local init = function()
_G.screen = curses.initscr()
curses.cbreak()
curses.echo(false)
curses.nl(false)
curses.curs_set(0)
pira.status = true
if type(pira.load) == "function" then pira.load() end
local last_time = pira.timer.get_time()
local dt
local current_time
while pira.status == true do
if type(pira.draw) == "function" then pira.draw() end
screen:refresh()
current_time = pira.timer.get_time()
dt = current_time - last_time
last_time = current_time
pira.timer.sleep(1 / 60)
pira.input = curses.getch()
if type(pira.update) == "function" then pira.update(dt) end
screen:clear()
end
end
local run = function()
xpcall(init, error)
end
return run