summaryrefslogtreecommitdiff
path: root/meta/whimsical/builtin.lua
blob: 6521bb4b2a46a107aa096a8758d90ea86e50cb18 (plain)
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
---@meta _

--[[@@@
---@inner class -> {
    self.istruly = true
    self.truly   = self
    self.falsy   = Class 'never'
    self.view    = self.name
}
---@inner integer -> {
    self.istruly = true
    self.truly   = self
    self.falsy   = Class 'never'
    self.view    = tostring(self.value)
}
---@inner string -> {
    self.istruly = true
    self.truly   = self
    self.falsy   = Class 'never'
    self.view    = cat.util.viewString(self.value, self.quotation)
}
---@inner union -> {
    self.istruly = function (subs)
        local istruly = subs[1].istruly
        if istruly == nil then
            return nil
        end
        if istruly == true then
            for i = 2, #subs do
                if subs[i].istruly ~= true then
                    return nil
                end
            end
            return true
        else
            for i = 2, #subs do
                if subs[i].istruly ~= false then
                    return nil
                end
            end
            return false
        end
        return nil
    end
    self.truly = function (subs)
        local union = Union()
        for i = 1, #subs do
            union:add(subs[i].truly)
        end
        if union:len() == 0 then
            return Class 'never'
        end
        if union:len() == 1 then
            return union:first()
        end
        return union
    end
    self.falsy = function (subs)
        local union = Union()
        for i = 1, #subs do
            union:add(subs[i].falsy)
        end
        if union:len() == 0 then
            return Class 'never'
        end
        if union:len() == 1 then
            return union:first()
        end
        return union
    end
    self.view = function (subs)
        local views = {}
        for i = 1, #subs do
            views[i] = subs[i].view
        end
        if #views == 0 then
            return 'never'
        end
        return table.concat(views, '|')
    end
}
---@class nil -> {
    self.istruly = false
    self.truly   = Class 'never'
    self.falsy   = self
}
---@class never -> {
    self.istruly = nil
}
---@class true -> {
    self.istruly = true
    self.truly   = self
    self.falsy   = Class 'never'
}
---@class false -> {
    self.istruly = false
    self.truly   = Class 'never'
    self.falsy   = self
}
---@class any: { [unknown]: any } -> {
    self.istruly = nil
    self.truly   = Class 'truly'
    self.falsy   = Class 'false' | Class 'nil'
}
---@class truly: { [unknown]: any }
---@class unknown: truly | false
---@class boolean: true | false
---@class number
---@class thread
---@class table: { [unknown]: any }
---@class table<K, V>: { [K]: V }
---@class string: stringlib
---@class userdata: { [unknown]: any }
---@class lightuserdata
---@class function: fun(...): ...
]]