Pazyryk
Deity
- Joined
- Jun 13, 2008
- Messages
- 3,584
Code:
> print(type( GameInfo ))
EaMain: table
> print(type( GameInfo.Units ))
EaMain: userdata
> print(type( GameInfo.Units() ))
EaMain: function
> print(type( GameInfo.Units[1] ))
EaMain: table
This has been puzzling me for a while. For one thing, there is no other Lua variable type where you can use both "()" and "[]" after the variable. Also, accessing something like GameInfo.Units["UNIT_WARRIOR"].ID is very slow, about 17x slower than looking up the same info in a simple Lua table using GameInfoTypes["UNIT_WARRIOR"]. Even though the first looks like a table access, it's really passing your request to some C++ method (the GameInfo.Units part), which then passes you a table. Apparently this isn't very fast (it's not looking up the value in the DB! that would be much much slower). The iterator function you get from GameInfo.Units() is even worse -- it's about 70x slower than setting up your own iterator in Lua. (See speed tests here; this is not an issue unless you are checking something 100s of times a turn, but keep it in mind if you are doing some lookup for every unit or every plot each turn.)
Apologies for the very technical post. Carry on now...