-
Notifications
You must be signed in to change notification settings - Fork 0
/
monkeypatch.lua
46 lines (44 loc) · 950 Bytes
/
monkeypatch.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
do
math.tau = math.pi * 2
function math.sign(x)
return
x > 0 and 1 or
x == 0 and 0 or
x < 0 and -1
end
function math.round(x)
return math.floor(x + 0.5)
end
end
do
function list:elements() -- Convenient iterator
local i = 1
return function()
local v = self:get(i)
i = i + 1
if v ~= nil then
return v
end
end, self, 0
end
function list:find(obj) -- Same as List:has but without "and true"
return self.pointers[obj]
end
end
do
-- Augment worlds to allow world.systemName behaviour
local oldWorldNew = world.new
local newWorldMetatable = {
__index = function(self, k)
local v = rawget(self, k)
if v then return v end
local v = rawget(concord.world, k)
if v then return v end
-- Here is where it is (functionally) different from concord.world.__mt:
return self:getSystem(systems[k])
end
}
function world.new()
return setmetatable(oldWorldNew(), newWorldMetatable)
end
end