-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathRef.lua
78 lines (60 loc) · 1.32 KB
/
Ref.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
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
--[[
Ref.lua
Strong & Weak References
Copyright (c) 2021 psiberx
]]
local Ref = { version = '1.0.0' }
---@type inkScriptWeakHashMap
local weakMap
---@type inkScriptHashMap
local strongMap
---@param o IScriptable
---@return boolean
function Ref.IsDefined(o)
return IsDefined(o)
end
---@param o IScriptable
---@return boolean
function Ref.IsExpired(o)
return not IsDefined(o)
end
---@param a IScriptable
---@param b IScriptable
---@return boolean
function Ref.Equals(a, b)
return Game['OperatorEqual;IScriptableIScriptable;Bool'](a, b)
end
---@param a IScriptable
---@param b IScriptable
---@return boolean
function Ref.NotEquals(a, b)
return Game['OperatorNotEqual;IScriptableIScriptable;Bool'](a, b)
end
---@param o IScriptable
---@return IScriptable
function Ref.Weak(o)
if not weakMap then
weakMap = inkScriptWeakHashMap.new()
weakMap:Insert(0, nil)
end
weakMap:Set(0, o)
return weakMap:Get(0)
end
---@param o IScriptable
---@return IScriptable
function Ref.Strong(o)
if not strongMap then
strongMap = inkScriptHashMap.new()
strongMap:Insert(0, nil)
end
strongMap:Set(0, o)
local ref = strongMap:Get(0)
strongMap:Set(0, nil)
return ref
end
---@param o IScriptable
---@return Int32
function Ref.Hash(o)
return CalcSeed(o)
end
return Ref