Skip to content

Commit

Permalink
Properly type EmptyQuery
Browse files Browse the repository at this point in the history
  • Loading branch information
Ukendio committed Jul 14, 2024
1 parent 150afc4 commit 48cc4dc
Showing 1 changed file with 30 additions and 18 deletions.
48 changes: 30 additions & 18 deletions src/init.luau
Original file line number Diff line number Diff line change
Expand Up @@ -662,31 +662,43 @@ local function world_get(world: World, entityId: i53, a: i53, b: i53?, c: i53?,
end
end

local function noop()
return nil
end

local EmptyQuery = {
__iter = function()
return noop
end,
next = noop,
replace = noop,
without = function(self)
return self
end
type Item = () -> (number, ...any)
export type Query = typeof({
__iter = function(): Item
return function()
return 1
end
end,
}) & {
next: Item,
replace: (Query, ...any) -> (),
without: (Query) -> Query
}

setmetatable(EmptyQuery, EmptyQuery)
type CompatibleArchetype = { archetype: Archetype, indices: { number } }

export type Query = typeof(EmptyQuery)
local world_query: (World, ...i53) -> Query
do

type CompatibleArchetype = { archetype: Archetype, indices: { number } }
local noop: Item = function()
return nil :: any
end

local EmptyQuery: Query = {
__iter = function(): Item
return function()
return 1
end
end,
next = noop :: Item,
replace = noop :: (Query, ...any) -> (),
without = function(self: Query, ...)
return self
end
}

setmetatable(EmptyQuery, EmptyQuery)

local world_query: (World, ...i53) -> Query
do
local indices: { { number } }
local compatibleArchetypes: { Archetype }
local length
Expand Down

0 comments on commit 48cc4dc

Please sign in to comment.