mirror of
https://github.com/Ukendio/jecs.git
synced 2025-07-04 13:59:17 +00:00
Explicit error for query:next
This commit is contained in:
parent
d5baf52977
commit
d7bda01fa7
2 changed files with 22 additions and 9 deletions
|
@ -813,7 +813,7 @@ do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function world_query_next(): any
|
local function world_query_iter_next(): any
|
||||||
local entityId = entities[i]
|
local entityId = entities[i]
|
||||||
while entityId == nil do
|
while entityId == nil do
|
||||||
lastArchetype += 1
|
lastArchetype += 1
|
||||||
|
@ -1048,9 +1048,17 @@ do
|
||||||
if not drain then
|
if not drain then
|
||||||
query_init(query)
|
query_init(query)
|
||||||
end
|
end
|
||||||
return world_query_next
|
return world_query_iter_next
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function world_query_next()
|
||||||
|
if not drain then
|
||||||
|
error("Did you forget to call query:drain()?")
|
||||||
|
end
|
||||||
|
return world_query_iter_next()
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
local it = {
|
local it = {
|
||||||
__iter = world_query_iter,
|
__iter = world_query_iter,
|
||||||
drain = world_query_drain,
|
drain = world_query_drain,
|
||||||
|
|
|
@ -296,14 +296,19 @@ TEST("world:query()", function()
|
||||||
world:set(eAB, A, true)
|
world:set(eAB, A, true)
|
||||||
world:set(eAB, B, true)
|
world:set(eAB, B, true)
|
||||||
|
|
||||||
local q = world:query(A)
|
local q = world:query(A):drain()
|
||||||
|
|
||||||
local e, data = q:next()
|
local e, data = q.next()
|
||||||
while e do
|
while e do
|
||||||
if e ~= eA and e ~= eAB then
|
if e == eA then
|
||||||
|
CHECK(data)
|
||||||
|
elseif e == eAB then
|
||||||
|
CHECK(data)
|
||||||
|
else
|
||||||
CHECK(false)
|
CHECK(false)
|
||||||
end
|
end
|
||||||
e, data = q:next()
|
|
||||||
|
e, data = q.next()
|
||||||
end
|
end
|
||||||
CHECK(true)
|
CHECK(true)
|
||||||
end
|
end
|
||||||
|
@ -743,7 +748,7 @@ do
|
||||||
added = true
|
added = true
|
||||||
local q = world:query(T):without(PreviousT):drain()
|
local q = world:query(T):without(PreviousT):drain()
|
||||||
return function()
|
return function()
|
||||||
local id, data = q:next()
|
local id, data = q.next()
|
||||||
if not id then
|
if not id then
|
||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
|
@ -762,7 +767,7 @@ do
|
||||||
local q = world:query(T, PreviousT):drain()
|
local q = world:query(T, PreviousT):drain()
|
||||||
|
|
||||||
return function()
|
return function()
|
||||||
local id, new, old = q:next()
|
local id, new, old = q.next()
|
||||||
while true do
|
while true do
|
||||||
if not id then
|
if not id then
|
||||||
return nil
|
return nil
|
||||||
|
@ -788,7 +793,7 @@ do
|
||||||
|
|
||||||
local q = world:query(PreviousT):without(T):drain()
|
local q = world:query(PreviousT):without(T):drain()
|
||||||
return function()
|
return function()
|
||||||
local id = q:next()
|
local id = q.next()
|
||||||
if id then
|
if id then
|
||||||
world:remove(id, PreviousT)
|
world:remove(id, PreviousT)
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue