-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutil.lua
43 lines (37 loc) · 936 Bytes
/
util.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
-- util.lua
local util = {}
local parser = require('parser')
function util.newEventHandler(parent, model)
local obj = parent or require('controllers.Default')
return function(event, args)
if obj[event] then
obj[event](model, args)
else
love.event.push(event, args)
end
end
end
function util.newParsedScript(rawScript)
local parsedCommands = parser.parse(rawScript)
if not parsedCommands then
return nil
end
local parsed = {
commands = parsedCommands
}
parsed.current = parsed.commands.top
parsed.nextCommand = function()
local command = parsed.current
if command then
parsed.current = command.next
return command
else
return nil
end
end
parsed.setCommand = function(command)
parsed.current = command
end
return parsed
end
return util