@quenty/tuple 1.0.1-canary.478.34e8ede.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 +11 -0
- package/LICENSE.md +21 -0
- package/README.md +23 -0
- package/default.project.json +7 -0
- package/package.json +34 -0
- package/src/Shared/Tuple.lua +79 -0
- package/src/Shared/Tuple.story.lua +32 -0
- package/src/node_modules.project.json +7 -0
- package/test/default.project.json +12 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# Change Log
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
|
+
|
|
6
|
+
## 1.0.1-canary.478.34e8ede.0 (2024-08-27)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Features
|
|
10
|
+
|
|
11
|
+
* Add tuple package and fix tie signal ([134f90c](https://github.com/Quenty/NevermoreEngine/commit/134f90c03b265b9d2232198475ca27f4d5e87071))
|
package/LICENSE.md
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2014-2024 James Onnen (Quenty)
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
## Tuple
|
|
2
|
+
|
|
3
|
+
<div align="center">
|
|
4
|
+
<a href="http://quenty.github.io/NevermoreEngine/">
|
|
5
|
+
<img src="https://github.com/Quenty/NevermoreEngine/actions/workflows/docs.yml/badge.svg" alt="Documentation status" />
|
|
6
|
+
</a>
|
|
7
|
+
<a href="https://discord.gg/mhtGUS8">
|
|
8
|
+
<img src="https://img.shields.io/discord/385151591524597761?color=5865F2&label=discord&logo=discord&logoColor=white" alt="Discord" />
|
|
9
|
+
</a>
|
|
10
|
+
<a href="https://github.com/Quenty/NevermoreEngine/actions">
|
|
11
|
+
<img src="https://github.com/Quenty/NevermoreEngine/actions/workflows/build.yml/badge.svg" alt="Build and release status" />
|
|
12
|
+
</a>
|
|
13
|
+
</div>
|
|
14
|
+
|
|
15
|
+
Tuple utility package
|
|
16
|
+
|
|
17
|
+
<div align="center"><a href="https://quenty.github.io/NevermoreEngine/api/TupleUtils">View docs →</a></div>
|
|
18
|
+
|
|
19
|
+
## Installation
|
|
20
|
+
|
|
21
|
+
```
|
|
22
|
+
npm install @quenty/tuple --save
|
|
23
|
+
```
|
package/package.json
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@quenty/tuple",
|
|
3
|
+
"version": "1.0.1-canary.478.34e8ede.0",
|
|
4
|
+
"description": "Tuple utility package",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"Roblox",
|
|
7
|
+
"Nevermore",
|
|
8
|
+
"Lua",
|
|
9
|
+
"tuple"
|
|
10
|
+
],
|
|
11
|
+
"bugs": {
|
|
12
|
+
"url": "https://github.com/Quenty/NevermoreEngine/issues"
|
|
13
|
+
},
|
|
14
|
+
"repository": {
|
|
15
|
+
"type": "git",
|
|
16
|
+
"url": "https://github.com/Quenty/NevermoreEngine.git",
|
|
17
|
+
"directory": "src/tuple/"
|
|
18
|
+
},
|
|
19
|
+
"funding": {
|
|
20
|
+
"type": "patreon",
|
|
21
|
+
"url": "https://www.patreon.com/quenty"
|
|
22
|
+
},
|
|
23
|
+
"license": "MIT",
|
|
24
|
+
"contributors": [
|
|
25
|
+
"Quenty"
|
|
26
|
+
],
|
|
27
|
+
"dependencies": {
|
|
28
|
+
"@quenty/loader": "10.3.1-canary.478.34e8ede.0"
|
|
29
|
+
},
|
|
30
|
+
"publishConfig": {
|
|
31
|
+
"access": "public"
|
|
32
|
+
},
|
|
33
|
+
"gitHead": "34e8edee97fa93a0a5bd84442b85826082444f2a"
|
|
34
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
--[=[
|
|
2
|
+
Tuple class for Lua
|
|
3
|
+
|
|
4
|
+
@class Tuple
|
|
5
|
+
]=]
|
|
6
|
+
|
|
7
|
+
local Tuple = {}
|
|
8
|
+
Tuple.ClassName = "Tuple"
|
|
9
|
+
Tuple.__index = Tuple
|
|
10
|
+
|
|
11
|
+
function Tuple.new(...)
|
|
12
|
+
return setmetatable(table.pack(...), Tuple)
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
function Tuple.isTuple(value)
|
|
16
|
+
return getmetatable(value) == Tuple
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
--[=[
|
|
20
|
+
Unpacks the tuple
|
|
21
|
+
|
|
22
|
+
@return T
|
|
23
|
+
]=]
|
|
24
|
+
function Tuple:Unpack()
|
|
25
|
+
return table.unpack(self, 1, self.n)
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
--[=[
|
|
29
|
+
Converts to array
|
|
30
|
+
|
|
31
|
+
@return { T }
|
|
32
|
+
]=]
|
|
33
|
+
function Tuple:ToArray()
|
|
34
|
+
return { self:Unpack() }
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
function Tuple:__tostring()
|
|
38
|
+
return table.concat(self, ", ")
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
function Tuple:__len()
|
|
42
|
+
return self.n
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
function Tuple:__eq(other)
|
|
46
|
+
if not Tuple.isTuple(other) then
|
|
47
|
+
return false
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
if self.n ~= other.n then
|
|
51
|
+
return false
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
for i=1, self.n do
|
|
55
|
+
if self[i] ~= other[i] then
|
|
56
|
+
return false
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
return true
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
function Tuple:__add(other)
|
|
64
|
+
assert(Tuple.isTuple(other), "Can only add tuples")
|
|
65
|
+
|
|
66
|
+
local result = Tuple.new(self:Unpack())
|
|
67
|
+
local count = self.n
|
|
68
|
+
for i=1, other.n do
|
|
69
|
+
result[count + i] = other[i]
|
|
70
|
+
end
|
|
71
|
+
result.n = count + other.n
|
|
72
|
+
return result
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
function Tuple:__call()
|
|
76
|
+
return table.unpack(self, 1, self.n)
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
return Tuple
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
--[[
|
|
2
|
+
@class Tuple.story
|
|
3
|
+
]]
|
|
4
|
+
|
|
5
|
+
local require = require(game:GetService("ServerScriptService"):FindFirstChild("LoaderUtils", true).Parent).bootstrapStory(script)
|
|
6
|
+
|
|
7
|
+
local Tuple = require("Tuple")
|
|
8
|
+
|
|
9
|
+
return function(_target)
|
|
10
|
+
local a = Tuple.new(1, 2, 3)
|
|
11
|
+
local b = Tuple.new(1, 2, 3)
|
|
12
|
+
local c = Tuple.new(3, 4, "d")
|
|
13
|
+
|
|
14
|
+
assert(tostring(a) == "1, 2, 3", "Bad a")
|
|
15
|
+
assert(tostring(c) == "3, 4, d", "Bad c")
|
|
16
|
+
assert(#a == 3, "Bad a")
|
|
17
|
+
assert(a == b, "a == b")
|
|
18
|
+
assert(b == b, "b == b")
|
|
19
|
+
assert(a ~= c, "b == b")
|
|
20
|
+
|
|
21
|
+
-- Addition
|
|
22
|
+
assert(tostring(a + c) == "1, 2, 3, 3, 4, d", "Bad addition")
|
|
23
|
+
assert(#a:ToArray() == 3, "Bad toArray")
|
|
24
|
+
|
|
25
|
+
local lookupTable = {}
|
|
26
|
+
lookupTable[a] = true
|
|
27
|
+
|
|
28
|
+
assert(lookupTable[b] == false, "Lookup should not be equivalent")
|
|
29
|
+
|
|
30
|
+
return function()
|
|
31
|
+
end
|
|
32
|
+
end
|