mirror of
				https://github.com/Ukendio/jecs.git
				synced 2025-11-04 02:49:18 +00:00 
			
		
		
		
	Properly type EmptyQuery
This commit is contained in:
		
							parent
							
								
									150afc46e4
								
							
						
					
					
						commit
						48cc4dc7d5
					
				
					 1 changed files with 31 additions and 19 deletions
				
			
		| 
						 | 
				
			
			@ -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
 | 
			
		||||
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)
 | 
			
		||||
 | 
			
		||||
export type Query = typeof(EmptyQuery)
 | 
			
		||||
 | 
			
		||||
type CompatibleArchetype = { archetype: Archetype, indices: { number } }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
local world_query: (World, ...i53) -> Query
 | 
			
		||||
do
 | 
			
		||||
 | 
			
		||||
    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 indices: { { number } }
 | 
			
		||||
   	local compatibleArchetypes: { Archetype }
 | 
			
		||||
   	local length
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in a new issue