1. We have added a Gift Upgrades feature that allows you to gift an account upgrade to another member, just in time for the holiday season. You can see the gift option when going to the Account Upgrades screen, or on any user profile screen.
    Dismiss Notice

GameInfo.Units is type userdata

Discussion in 'Civ5 - Creation & Customization' started by Pazyryk, Feb 4, 2013.

  1. Pazyryk

    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...
     
  2. Pazyryk

    Pazyryk Deity

    Joined:
    Jun 13, 2008
    Messages:
    3,584
    This just proves that Lua can be faster than C++. (The same way my Honda Civic can be faster than a Formula One. ;))
     
  3. General Tso

    General Tso Panzer General

    Joined:
    Oct 12, 2007
    Messages:
    1,547
    Location:
    U. S. of A.
    At least until the formula one driver actually presses the gas pedal. :lol:

    (I know that you where only joking but I couldn't help myself. :mischief:)
     
  4. Irkalla

    Irkalla ENTP POWWWEEEEEER

    Joined:
    Sep 25, 2012
    Messages:
    1,009
    Location:
    Way down around Vicksburg
    I'll keep this in mind when I go through optimizing Sparta. Every little bit helps.
     
  5. whoward69

    whoward69 DLL Minion

    Joined:
    May 30, 2011
    Messages:
    8,532
    Location:
    Near Portsmouth, UK
    But if you put the F1 driver in the Civic and the Civic driver in the F1 car, then the Civic WILL be faster. Which just goes to prove that it's not the capabilities/speed of the cars (programming languages) which are important but the relevant skills of the drivers (programmers)
     

Share This Page