summaryrefslogtreecommitdiff
path: root/script-beta/without-check-nil.lua
blob: cc7da9d473cc742d9670409e4438cc052a7fce2b (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
117
118
119
120
121
122
123
124
125
126
local m = {}

local mt = {}
mt.__add      = function (a, b)
    if a == nil then a = 0 end
    if b == nil then b = 0 end
    return a + b
end
mt.__sub      = function (a, b)
    if a == nil then a = 0 end
    if b == nil then b = 0 end
    return a - b
end
mt.__mul      = function (a, b)
    if a == nil then a = 0 end
    if b == nil then b = 0 end
    return a * b
end
mt.__div      = function (a, b)
    if a == nil then a = 0 end
    if b == nil then b = 0 end
    return a / b
end
mt.__mod      = function (a, b)
    if a == nil then a = 0 end
    if b == nil then b = 0 end
    return a % b
end
mt.__pow      = function (a, b)
    if a == nil then a = 0 end
    if b == nil then b = 0 end
    return a ^ b
end
mt.__unm      = function ()
    return 0
end
mt.__concat   = function (a, b)
    if a == nil then a = '' end
    if b == nil then b = '' end
    return a .. b
end
mt.__len      = function ()
    return 0
end
mt.__lt       = function (a, b)
    if a == nil then a = 0 end
    if b == nil then b = 0 end
    return a < b
end
mt.__le       = function (a, b)
    if a == nil then a = 0 end
    if b == nil then b = 0 end
    return a <= b
end
mt.__index    = function () end
mt.__newindex = function () end
mt.__call     = function () end
mt.__pairs    = function () end
mt.__ipairs   = function () end
if _VERSION == 'Lua 5.3' or _VERSION == 'Lua 5.4' then
    mt.__idiv      = load[[
        local a, b = ...
        if a == nil then a = 0 end
        if b == nil then b = 0 end
        return a // b
    ]]
    mt.__band      = load[[
        local a, b = ...
        if a == nil then a = 0 end
        if b == nil then b = 0 end
        return a & b
    ]]
    mt.__bor       = load[[
        local a, b = ...
        if a == nil then a = 0 end
        if b == nil then b = 0 end
        return a | b
    ]]
    mt.__bxor      = load[[
        local a, b = ...
        if a == nil then a = 0 end
        if b == nil then b = 0 end
        return a ~ b
    ]]
    mt.__bnot      = load[[
        return ~ 0
    ]]
    mt.__shl       = load[[
        local a, b = ...
        if a == nil then a = 0 end
        if b == nil then b = 0 end
        return a << b
    ]]
    mt.__shr       = load[[
        local a, b = ...
        if a == nil then a = 0 end
        if b == nil then b = 0 end
        return a >> b
    ]]
end

for event, func in pairs(mt) do
    mt[event] = function (...)
        local watch = m.watch
        if not watch then
            return func(...)
        end
        local care, result = watch(event, ...)
        if not care then
            return func(...)
        end
        return result
    end
end

function m.enable()
    debug.setmetatable(nil, mt)
end

function m.disable()
    if debug.getmetatable(nil) == mt then
        debug.setmetatable(nil, nil)
    end
end

return m