function ExampleEnemy:behavior()
while true do
self:move()
self:fire_arc()
end
end
function ExampleEnemy:fire_arc()
local theta = self:aim()
for i=-5,5 do
self:fire({speed=8, direction=theta+i*10*degrees})
end
end
If I later want the arc to have some delay between the bullets, and I insert a call to a function that yields for a certain number of frames in the loop in fire_arc, the code continues to work. If I do this same change in Python, the result is that the call to fire_arc in behavior begins to return an iterator or something and silently fails to actually fire any bullets!Lua's stackful coroutines are sufficiently cheap that it's reasonable to have tens of thousands of entity behaviors implemented as coroutines running at a time.