<URL: http://bugs.freeciv.org/Ticket/Display.html?id=40644 >

> [cazf...@gmail.com - Thu Jan 08 20:25:03 2009]:
> 
>  Attached patch adds support to iterate though players, cities, and
> units to lua scripting.
> 
>  I decided not to use iterator objects with all the memory handling
> they would require.

It would be nice if one could do

for player in game:players() do
  print player:name()    -- or whatever
end

Lua has a lot of great features for implementing iteration
cleanly and efficiently: closures, generic for, coroutines,
and object oriented syntax (see http://www.lua.org/pil/).
It would be a shame not to make the best use of them. ;)

> Instead, script can call iterate_[players|cities|units]()
> and that emits script signal for each item of the type.

I don't think making a call to script_signal_emit during
every iteration of the loop is very efficient. Considering
that there could be hundreds of cities and units, and that
iteration is a very basic, often used algorithm, this could
result in a significant performance penalty.

Add to that that the X_iterate_safe macros make a stack
array copy of the entire list. This seems like a large
price to pay just to allow users to destroy objects while
they are being iterated over. :(


Of course I could be wrong; I have not actually profiled
the code with general test cases to see where the real
bottleneck would be...


-----------------------------------------------------------------------
俺に物体を投げるのはよせ!

_______________________________________________
Freeciv-dev mailing list
Freeciv-dev@gna.org
https://mail.gna.org/listinfo/freeciv-dev

Reply via email to