Skip to content

Commit 96c9156

Browse files
committed
get rid of leaked abstraction
1 parent 0bdb879 commit 96c9156

File tree

13 files changed

+40
-222
lines changed

13 files changed

+40
-222
lines changed

assets/tests/iter/hashmap.lua

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,17 @@ local res = world.get_resource(res_type)
33

44
local map = res.string_map
55

6+
local iterator = map:iter()
67
local count = 0
78
local found_keys = {}
89

9-
--- Iterate over PartialReflect refs using pairs
10-
for key, value in pairs(map) do
10+
local result = iterator()
11+
while result ~= nil do
12+
local key = result[1]
13+
local value = result[2]
1114
count = count + 1
1215
found_keys[key] = value
16+
result = iterator()
1317
end
1418

1519
assert(count == 2, "Expected 2 entries, got " .. count)

assets/tests/iter_clone/hashmap_ipairs.lua renamed to assets/tests/iter/hashmap_ipairs.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ local map = res.string_map
66
local count = 0
77
local found_keys = {}
88

9-
-- ipairs_clone on a map returns (index, [key, value]) where value is a list
10-
for i, entry in map:ipairs_clone() do
9+
-- ipairs on a map returns (index, [key, value]) where value is a list
10+
for i, entry in map:ipairs() do
1111
assert(i == count + 1, "Index should be sequential: expected " .. (count + 1) .. ", got " .. i)
1212

1313
-- entry should be a list with [key, value]

assets/tests/iter_clone/hashmap_pairs.lua renamed to assets/tests/iter/hashmap_pairs.lua

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@ local map = res.string_map
66
local count = 0
77
local found_keys = {}
88

9-
-- Use pairs_clone to loop over Reflect values
10-
for key, value in map:pairs_clone() do
9+
for key, value in map:pairs() do
1110
count = count + 1
1211
found_keys[key] = value
1312
end

assets/tests/iter/vec.lua

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
local res_type = world.get_type_by_name("TestResourceWithVariousFields")
22
local res = world.get_resource(res_type)
33

4-
iterated_vals = {}
5-
for v in pairs(res.vec_usize) do
6-
iterated_vals[#iterated_vals + 1] = v
4+
local iterated_vals = {}
5+
local iterator = res.vec_usize:iter()
6+
local result = iterator()
7+
while result ~= nil do
8+
iterated_vals[#iterated_vals + 1] = result
9+
result = iterator()
710
end
11+
812
assert(#iterated_vals == 5, "Length is not 5")
913
assert(iterated_vals[1] == 1, "First value is not 1")
1014
assert(iterated_vals[2] == 2, "Second value is not 2")

assets/tests/iter/vec.rhai

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,16 @@ let res_type = world.get_type_by_name.call("TestResourceWithVariousFields");
22
let res = world.get_resource.call(res_type);
33

44
let iterated_vals = [];
5+
let iterator = res.vec_usize.iter();
56

6-
for v in res.vec_usize {
7-
iterated_vals.push(v);
7+
loop {
8+
let result = iterator.next();
9+
10+
if result == () {
11+
break;
12+
}
13+
14+
iterated_vals.push(result);
815
}
916

1017
assert(iterated_vals.len == 5, "Length is not 5");

assets/tests/iter_clone/vec_ipairs.lua renamed to assets/tests/iter/vec_ipairs.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ local res_type = world.get_type_by_name("TestResourceWithVariousFields")
22
local res = world.get_resource(res_type)
33

44
local iterated_vals = {}
5-
for i, v in res.vec_usize:ipairs_clone() do
5+
for i, v in res.vec_usize:ipairs() do
66
assert(i == #iterated_vals + 1, "Index mismatch: expected " .. (#iterated_vals + 1) .. ", got " .. i)
77
iterated_vals[#iterated_vals + 1] = v
88
end

assets/tests/iter_clone/vec_pairs.lua renamed to assets/tests/iter/vec_pairs.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ local res_type = world.get_type_by_name("TestResourceWithVariousFields")
22
local res = world.get_resource(res_type)
33

44
local iterated_vals = {}
5-
for v in res.vec_usize:pairs_clone() do
5+
for v in res.vec_usize:pairs() do
66
iterated_vals[#iterated_vals + 1] = v
77
end
88

assets/tests/iter_clone/hashmap.lua

Lines changed: 0 additions & 21 deletions
This file was deleted.

assets/tests/iter_clone/hashmap.rhai

Lines changed: 0 additions & 31 deletions
This file was deleted.

assets/tests/iter_clone/vec.lua

Lines changed: 0 additions & 17 deletions
This file was deleted.

0 commit comments

Comments
 (0)