@quenty/ducktype 2.2.0 → 3.0.0-canary.439.eb597ee.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +8 -0
- package/package.json +3 -3
- package/src/Shared/DuckTypeUtils.lua +22 -3
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,14 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
# [3.0.0-canary.439.eb597ee.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/ducktype@2.2.0...@quenty/ducktype@3.0.0-canary.439.eb597ee.0) (2024-01-17)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package @quenty/ducktype
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
6
14
|
# [2.2.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/ducktype@2.1.0...@quenty/ducktype@2.2.0) (2024-01-08)
|
|
7
15
|
|
|
8
16
|
**Note:** Version bump only for package @quenty/ducktype
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@quenty/ducktype",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0-canary.439.eb597ee.0",
|
|
4
4
|
"description": "Utility functions to duck type a value",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Roblox",
|
|
@@ -25,10 +25,10 @@
|
|
|
25
25
|
"Quenty"
|
|
26
26
|
],
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@quenty/loader": "
|
|
28
|
+
"@quenty/loader": "8.0.0-canary.439.eb597ee.0"
|
|
29
29
|
},
|
|
30
30
|
"publishConfig": {
|
|
31
31
|
"access": "public"
|
|
32
32
|
},
|
|
33
|
-
"gitHead": "
|
|
33
|
+
"gitHead": "eb597ee01e62e4dd91190bb7abd1d1404652d5ff"
|
|
34
34
|
}
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
--[=[
|
|
2
|
+
Utility method to check interface is equivalent for two implementations
|
|
3
|
+
|
|
2
4
|
@class DuckTypeUtils
|
|
3
5
|
]=]
|
|
4
6
|
|
|
@@ -6,6 +8,13 @@ local require = require(script.Parent.loader).load(script)
|
|
|
6
8
|
|
|
7
9
|
local DuckTypeUtils = {}
|
|
8
10
|
|
|
11
|
+
--[=[
|
|
12
|
+
Returns true if a template is similar to a target
|
|
13
|
+
|
|
14
|
+
@param template table
|
|
15
|
+
@param target any
|
|
16
|
+
@return boolean
|
|
17
|
+
]=]
|
|
9
18
|
function DuckTypeUtils.isImplementation(template, target)
|
|
10
19
|
assert(type(template) == "table", "Bad template")
|
|
11
20
|
|
|
@@ -14,6 +23,17 @@ function DuckTypeUtils.isImplementation(template, target)
|
|
|
14
23
|
end
|
|
15
24
|
|
|
16
25
|
function DuckTypeUtils._checkInterface(template, target)
|
|
26
|
+
local targetMetatable = getmetatable(target)
|
|
27
|
+
local templateMetatable = getmetatable(template)
|
|
28
|
+
if targetMetatable and type(targetMetatable.__index) == "function" then
|
|
29
|
+
-- Indexing into this target could cause an error. Treat it differently and fast-fail
|
|
30
|
+
if templateMetatable then
|
|
31
|
+
return targetMetatable.__index == templateMetatable.__index
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
return false
|
|
35
|
+
end
|
|
36
|
+
|
|
17
37
|
for key, value in pairs(template) do
|
|
18
38
|
if type(value) == "function" and type(target[key]) ~= "function" then
|
|
19
39
|
return false
|
|
@@ -21,9 +41,8 @@ function DuckTypeUtils._checkInterface(template, target)
|
|
|
21
41
|
end
|
|
22
42
|
|
|
23
43
|
-- TODO: Prevent infinite recursion potential
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
return DuckTypeUtils._checkInterface(metatable.__index, target)
|
|
44
|
+
if templateMetatable and type(templateMetatable.__index) == "table" then
|
|
45
|
+
return DuckTypeUtils._checkInterface(templateMetatable.__index, target)
|
|
27
46
|
end
|
|
28
47
|
|
|
29
48
|
return true
|