7 as_a_number = function(self)
10 rounded = function(self)
11 return math.floor(self + .5)
13 rounded_down = math.floor,
14 rounded_up = math.ceil,
15 to_the_nearest = function(self, rounder)
16 return rounder * math.floor(self / rounder + 0.5)
18 base16 = function(self)
19 return ("%X"):format(self)
22 number_mt.__index = number_mt
23 debug.setmetatable(0, number_mt)
26 __len = function(self)
27 return self and 1 or 0
30 as_nomsu = function(self)
31 return self and "yes" or "no"
33 as_text = function(self)
34 return self and "yes" or "no"
36 _and = function(self, cond)
39 _or = function(self, cond)
42 xor = function(self, cond)
43 return self == (not cond)
46 bool_mt.__index = bool_mt
47 debug.setmetatable(true, bool_mt)
50 as_text = function(self)
51 return (tostring(self):gsub("function", "Action"))
53 __add = function(self, other)
54 if type(self) == 'function' and type(other) == 'function' then
56 return (self(...) + other(...))
58 elseif type(self) == 'function' then
60 return (self(...) + other)
64 return (self + other(...))
68 __sub = function(self, other)
69 if type(self) == 'function' and type(other) == 'function' then
71 return (self(...) - other(...))
73 elseif type(self) == 'function' then
75 return (self(...) - other)
79 return (self - other(...))
83 __mul = function(self, other)
84 if type(self) == 'function' and type(other) == 'function' then
86 return (self(...) * other(...))
88 elseif type(self) == 'function' then
90 return (self(...) * other)
94 return (self * other(...))
98 __div = function(self, other)
99 if type(self) == 'function' and type(other) == 'function' then
101 return (self(...)(other(...)))
103 elseif type(self) == 'function' then
105 return (self(...)(other))
109 return (self(other(...)))
113 __mod = function(self, other)
114 if type(self) == 'function' and type(other) == 'function' then
116 return (self(...) % other(...))
118 elseif type(self) == 'function' then
120 return (self(...) % other)
124 return (self % other(...))
128 __band = function(self, other)
129 if type(self) == 'function' and type(other) == 'function' then
131 return (self(...) and other(...))
133 elseif type(self) == 'function' then
135 return (self(...) and other)
139 return (self and other(...))
143 __bor = function(self, other)
144 if type(self) == 'function' and type(other) == 'function' then
146 return (self(...) or other(...))
148 elseif type(self) == 'function' then
150 return (self(...) or other)
154 return (self or other(...))
158 __bxor = function(self, other)
159 if type(self) == 'function' and type(other) == 'function' then
161 return (self(...) ~= other(...))
163 elseif type(self) == 'function' then
165 return (self(...) ~= other)
169 return (self ~= other(...))
174 fn_mt.__index = fn_mt
175 debug.setmetatable((function() end), fn_mt)
176 local _last_co_i = setmetatable({ }, {
181 __type = "a Coroutine",
182 as_text = function(self)
183 return (tostring(self):gsub("thread", "Coroutine")) .. " (" .. coroutine.status(self) .. ")"
185 __len = function(self)
188 __call = coroutine.resume,
189 __inext = function(self, k)
190 local ok, val = coroutine.resume(self)
191 if coroutine.status(self) == 'dead' then
195 return (k or 0) + 1, val
198 __index = function(self, k)
199 if k == (_last_co_i[self] or 0) + 1 then
201 coroutine.resume(self, k)
205 return table.unpack(ret, 2)
213 co_mt.__next = co_mt.__inext
214 debug.setmetatable(coroutine.create(function() end), co_mt)
217 as_lua = function(self)
220 as_nomsu = function(self)
223 as_text = function(self)
227 nil_mt.__index = nil_mt
228 return debug.setmetatable(nil, nil_mt)