aboutsummaryrefslogtreecommitdiff
path: root/unit_tests/scripts
diff options
context:
space:
mode:
authorBenoit Germain <benoit.germain@ubisoft.com>2025-09-29 17:11:58 +0200
committerBenoit Germain <benoit.germain@ubisoft.com>2025-09-29 17:11:58 +0200
commitf011dcafb0f583c89ed9971238fd83ddcbdb5438 (patch)
treee118ea27af987540fccb2cb1563cc8d9508b255c /unit_tests/scripts
parent4e109a0c12d245b155bf03cb561c01b242666395 (diff)
downloadlanes-f011dcafb0f583c89ed9971238fd83ddcbdb5438.tar.gz
lanes-f011dcafb0f583c89ed9971238fd83ddcbdb5438.tar.bz2
lanes-f011dcafb0f583c89ed9971238fd83ddcbdb5438.zip
Lift restriction on tables as table keys
As demonstrated by the unit tests, there is no problem with using a table as a table key
Diffstat (limited to 'unit_tests/scripts')
-rw-r--r--unit_tests/scripts/linda/send_receive_tables.lua41
1 files changed, 41 insertions, 0 deletions
diff --git a/unit_tests/scripts/linda/send_receive_tables.lua b/unit_tests/scripts/linda/send_receive_tables.lua
new file mode 100644
index 0000000..08b1f16
--- /dev/null
+++ b/unit_tests/scripts/linda/send_receive_tables.lua
@@ -0,0 +1,41 @@
1local lanes = require "lanes"
2
3-- a newly created linda doesn't contain anything
4local l = lanes.linda()
5
6-- send a table with subtables, both as keys and values, making sure the structure is preserved
7
8local t1 = {["name"] = "t1"}
9local t2 = {["name"] = "t2"}
10
11local t3 = {
12 ["name"] = "t3",
13 ["t1"] = t1,
14 [t1] = t2, -- table t1 as key, table t2 as value
15 ["t2"] = t2,
16 [t2] = t1 -- table t2 as key, table t1 as value
17}
18
19-- add recursivity for good measure
20t3["t3"] = t3
21t3[t3] = t3
22t1["t3"] = t3
23t2["t3"] = t3
24
25l:send("data", t3)
26local k, t = l:receive("data")
27assert(k == "data" and type(t) == "table" and t.name == "t3")
28-- when keys are strings
29assert(t["t3"] == t)
30assert(type(t["t1"]) == "table")
31assert(t["t1"].name == "t1")
32assert(type(t["t2"]) == "table")
33assert(t["t2"].name == "t2")
34assert(t["t1"].t3 == t)
35assert(t["t2"].t3 == t)
36-- when keys are tables
37assert(t[t.t1] == t.t2)
38assert(t[t.t1]["t3"] == t)
39assert(t[t.t2] == t.t1)
40assert(t[t.t2]["t3"] == t)
41assert(t[t.t3] == t.t3)