Skip to content

Commit d7bda01

Browse files
committed
Explicit error for query:next
1 parent d5baf52 commit d7bda01

File tree

2 files changed

+22
-9
lines changed

2 files changed

+22
-9
lines changed

src/init.luau

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -813,7 +813,7 @@ do
813813
end
814814
end
815815

816-
local function world_query_next(): any
816+
local function world_query_iter_next(): any
817817
local entityId = entities[i]
818818
while entityId == nil do
819819
lastArchetype += 1
@@ -1048,9 +1048,17 @@ do
10481048
if not drain then
10491049
query_init(query)
10501050
end
1051-
return world_query_next
1051+
return world_query_iter_next
10521052
end
10531053

1054+
local function world_query_next()
1055+
if not drain then
1056+
error("Did you forget to call query:drain()?")
1057+
end
1058+
return world_query_iter_next()
1059+
end
1060+
1061+
10541062
local it = {
10551063
__iter = world_query_iter,
10561064
drain = world_query_drain,

test/tests.luau

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -296,14 +296,19 @@ TEST("world:query()", function()
296296
world:set(eAB, A, true)
297297
world:set(eAB, B, true)
298298

299-
local q = world:query(A)
299+
local q = world:query(A):drain()
300300

301-
local e, data = q:next()
301+
local e, data = q.next()
302302
while e do
303-
if e ~= eA and e ~= eAB then
303+
if e == eA then
304+
CHECK(data)
305+
elseif e == eAB then
306+
CHECK(data)
307+
else
304308
CHECK(false)
305309
end
306-
e, data = q:next()
310+
311+
e, data = q.next()
307312
end
308313
CHECK(true)
309314
end
@@ -743,7 +748,7 @@ do
743748
added = true
744749
local q = world:query(T):without(PreviousT):drain()
745750
return function()
746-
local id, data = q:next()
751+
local id, data = q.next()
747752
if not id then
748753
return nil
749754
end
@@ -762,7 +767,7 @@ do
762767
local q = world:query(T, PreviousT):drain()
763768

764769
return function()
765-
local id, new, old = q:next()
770+
local id, new, old = q.next()
766771
while true do
767772
if not id then
768773
return nil
@@ -788,7 +793,7 @@ do
788793

789794
local q = world:query(PreviousT):without(T):drain()
790795
return function()
791-
local id = q:next()
796+
local id = q.next()
792797
if id then
793798
world:remove(id, PreviousT)
794799
end

0 commit comments

Comments
 (0)