The EmptyQuery instance will iterate on itself instead of an empty table, leading to unintended side effects like the following:
Note that this iteration appears to be exactly what is inside the EmptyQuery object
small example of the code behind this repro:
for e, cframe, bul in world:query(transform_component, bullet) do
print(e, cframe, bul)
end
In no sense is this expected behavior, and this behavior can be changed to what is expected by modifying the EmptyQuery object as follows:
local EmptyQuery = {
--------REMOVE-------------
__iter = iterNoop -- by the way, this function doesn't exist?
------------------------------
next = noop,
replace = noop,
without = function(self)
return self
end
}
-----------ADD--------------
setmetatable(EmptyQuery, {__iter = noop})
------------------------------
An alternative that also works:
local EmptyQuery = {
__iter = noop,
next = noop,
replace = noop,
without = function(self)
return self
end
}
setmetatable(EmptyQuery, EmptyQuery)
The EmptyQuery instance will iterate on itself instead of an empty table, leading to unintended side effects like the following:
Note that this iteration appears to be exactly what is inside the
EmptyQuery
objectsmall example of the code behind this repro:
In no sense is this expected behavior, and this behavior can be changed to what is expected by modifying the EmptyQuery object as follows:
An alternative that also works: