mirror of
				https://github.com/Ukendio/jecs.git
				synced 2025-11-03 18:39:19 +00:00 
			
		
		
		
	Make iterators simple functions
	
		
			
	
		
	
	
		
	
		
			Some checks are pending
		
		
	
	
	
				
					
				
			
		
			Some checks are pending
		
		
	
	
This commit is contained in:
		
							parent
							
								
									169ec09ed5
								
							
						
					
					
						commit
						23540e5919
					
				
					 1 changed files with 25 additions and 14 deletions
				
			
		| 
						 | 
				
			
			@ -51,20 +51,18 @@ local function observers_new(world, query, callback)
 | 
			
		|||
		world:changed(term, emplaced)
 | 
			
		||||
 	end
 | 
			
		||||
 | 
			
		||||
  	return setmetatable({}, {
 | 
			
		||||
   		__iter = function()
 | 
			
		||||
     		local row = i
 | 
			
		||||
     		return function()
 | 
			
		||||
       			if row == 0 then
 | 
			
		||||
          			i = 0
 | 
			
		||||
             		table.clear(entities)
 | 
			
		||||
          		end
 | 
			
		||||
            	local entity = entities[row]
 | 
			
		||||
             	row -= 1
 | 
			
		||||
              	return entity
 | 
			
		||||
			end
 | 
			
		||||
	    end
 | 
			
		||||
   	})
 | 
			
		||||
  	return function()
 | 
			
		||||
  		local row = i
 | 
			
		||||
  		return function()
 | 
			
		||||
     			if row == 0 then
 | 
			
		||||
         			i = 0
 | 
			
		||||
          		table.clear(entities)
 | 
			
		||||
      		end
 | 
			
		||||
           	local entity = entities[row]
 | 
			
		||||
           	row -= 1
 | 
			
		||||
           	return entity
 | 
			
		||||
		end
 | 
			
		||||
    end
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
local function join(world, component)
 | 
			
		||||
| 
						 | 
				
			
			@ -152,6 +150,19 @@ local function monitors_new(world, query, callback)
 | 
			
		|||
		world:added(term, emplaced)
 | 
			
		||||
		world:removed(term, removed)
 | 
			
		||||
 	end
 | 
			
		||||
 | 
			
		||||
	return function()
 | 
			
		||||
		local row = i
 | 
			
		||||
		return function()
 | 
			
		||||
			if row == 0 then
 | 
			
		||||
				i = 0
 | 
			
		||||
				table.clear(entities)
 | 
			
		||||
			end
 | 
			
		||||
			local entity = entities[row]
 | 
			
		||||
			row -= 1
 | 
			
		||||
			return entity
 | 
			
		||||
		end
 | 
			
		||||
	end
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
local function observers_add(world: jecs.World): PatchedWorld
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in a new issue