-
Notifications
You must be signed in to change notification settings - Fork 26
/
operators.pluto
55 lines (50 loc) · 1.18 KB
/
operators.pluto
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
47
48
49
50
51
52
53
54
55
-- lparser.cpp's builtinoperators
local Pluto_operator_new <const> = function(mt, ...)
if mt.new then
return mt.new(...)
end
local t = {}
setmetatable(t, mt)
if not mt.__index or mt.__parent then
mt.__index = mt
end
if mt.__construct then
mt.__construct(t, ...)
end
return t
end
local Pluto_operator_extends <const> = function(c, p)
if (p_type := type(p)) != "table" then
error("expected a class or class-like table to extend, got " .. p_type)
end
for {
-- luaT_eventname
"__gc", "__mode", "__len", "__eq",
"__add", "__sub", "__mul", "__mod", "__pow",
"__div", "__idiv",
"__band", "__bor", "__bxor", "__shl", "__shr",
"__unm", "__bnot", "__lt", "__le",
"__concat", "__call", "__close",
-- misc
"__tostring"
} as mm do
if p[mm] and not c[mm] then
c[mm] = p[mm]
end
end
setmetatable(c, { __index = p })
c.__parent = p
end
local Pluto_operator_instanceof <const> = function(t, mt)
t = getmetatable(t)
while t do
if t == mt then
return true
end
t = t.__parent
end
return false
end
local Pluto_operator_spaceship <const> = function(a, b)
return a ~= b ? a < b ? -1 : +1 : 0
end