1. Updated Resource Submission Rules: All model & skin resource submissions must now include an in-game screenshot. This is to help speed up the moderation process and to show how the model and/or texture looks like from the in-game camera.
    Dismiss Notice
  2. DID YOU KNOW - That you can unlock new rank icons by posting on the forums or winning contests? Click here to customize your rank or read our User Rank Policy to see a list of ranks that you can unlock. Have you won a contest and still havn't received your rank award? Then please contact the administration.
    Dismiss Notice
  3. The poll for Hive's 12th Concept Art Contest is up! Go cast your vote for your favourite genie!
    Dismiss Notice
  4. Travel to distant realms and encounter scenes unknown to the common folk. The Greatest of Adventures is upon us with the 8th Cinematic Contest. Join in on a fun ride.
    Dismiss Notice
  5. The 18th Icon Contest is ON! Choose any ingame unit and give him/her Hero abilities. Good luck to all.
    Dismiss Notice
  6. Contestants are to create a scene set in the Stone Age. Come and see what you can come up with. We wish you the best of luck!
    Dismiss Notice
  7. Colour outside the lines! Techtree Contest #13 is a go. The contest is optionally paired.
    Dismiss Notice
  8. Greetings cerebrates, our Swarm needs new spawners that will have numerous children. Join the HIVE's 31st Modeling Contest - Spawners and Spawned! The contest is optionally paired.
    Dismiss Notice
  9. Check out the Staff job openings thread.
    Dismiss Notice
Dismiss Notice
60,000 passwords have been reset on July 8, 2019. If you cannot login, read this.

[Lua] Unit ID string to integer

Discussion in 'The Lab' started by strange_loop, Jul 19, 2019.

Tags:
  1. Bribe

    Bribe

    Joined:
    Sep 26, 2009
    Messages:
    8,015
    Resources:
    25
    Maps:
    3
    Spells:
    10
    Tutorials:
    3
    JASS:
    9
    Resources:
    25
    I suppose this can be rectified by manually overwriting the Filter() native to cache the original boolexpr. Condition() probably works the same way, but is typically only utilized once in GUI triggerconditions.
     
  2. mori

    mori

    Joined:
    Jun 13, 2016
    Messages:
    336
    Resources:
    2
    Spells:
    1
    Tutorials:
    1
    Resources:
    2
    I believe if you're running in Lua mode, you can just pass a function directly, without having to wrap it into a Filter or a Condition.
     
  3. Bribe

    Bribe

    Joined:
    Sep 26, 2009
    Messages:
    8,015
    Resources:
    25
    Maps:
    3
    Spells:
    10
    Tutorials:
    3
    JASS:
    9
    Resources:
    25
    I've not tried, but that sounds like a cool thing to test. I bet there would be a performance improvement in triggerconditions linked to code rather than boolexpr if so.
     
  4. Dr Super Good

    Dr Super Good

    Spell Reviewer

    Joined:
    Jan 18, 2005
    Messages:
    25,475
    Resources:
    3
    Maps:
    1
    Spells:
    2
    Resources:
    3
    They use the standard incremental garbage collector. Nothing magical or hidden about it.

    By default it aims to complete a collection cycle around the time that the Lua virtual machine heap size has grown to double the size it was after the last collection cycle. It does the collection incrementally so as to avoid freezing the application for an extended period. The rate at which an increment traverses the heap and the rate at which full collection cycles complete can be adjusted as required. Garbage collection is client local, meaning that use of __gc metafunction is prone to OoS errors.

    Be aware that the Lua garbage collector in default operating mode runs at a rate determined by the Lua heap and not the Warcraft III heap. This is important since Warcraft III objects are not factored into the Lua heap size so even if a garbage collection cycle would free them, it may take a very long time to happen since they effectively multiply the garbage memory size without influencing the collector rate. One can work around this by setting the collector to run more frequently by setting its memory multiplier target to a smaller number. For example if the Warcraft III garbage is 3 times the Lua heap garbage then setting the collector to run at 125% heap size would yield the desired doubling in memory frequency.

    Explicitly calling collectgarbage() forces the completion of a full garbage collection cycle. It will complete any underway incremental cycle. One should much rather adjust the collection frequency parameters or instruct it to run an incremental work. The incremental work mode will tell you when the work done resulted in the completion of the current cycle. Incremental work mode is recommended in your case since it will avoid freezes, however be aware that due to heap size variances incremental mode shares the same OoS hazards as the standard garbage collector.

    Adjusting the default garbage collector parameters is the most recommended approach as Lua is smart enough to handle its own garbage collection and heap as long as one tunes it appropriately. One should only force full garbage collection cycles if one uses __gc metafunctions which are an OoS hazard, for example my Lua location/group/force garbage collector.
     
  5. Prometheus3375

    Prometheus3375

    Joined:
    Jul 20, 2018
    Messages:
    90
    Resources:
    0
    Resources:
    0
    You must wrap it, since boolexpr is expected. I also didn't test it, but some people say that wrapping is necessary or error will be thrown.
     
  6. WaterKnight

    WaterKnight

    Joined:
    Aug 18, 2009
    Messages:
    4,033
    Resources:
    5
    Maps:
    1
    Tutorials:
    4
    Resources:
    5
    @Prometheus3375 Then overwrite Filter/Condition. I had used the behavior of them before to assign unique ids to code values (functions). That's not necessary in Lua anymore, however. You can use function pointers as table keys.
     
  7. yxq1122

    yxq1122

    Joined:
    Jun 5, 2018
    Messages:
    97
    Resources:
    0
    Resources:
    0
    Can this method return a correct unit/item type ID (same as that in Jass)?

    Thanks a lot, @Bribe. You present a prototype of a Jass2Lua converter. But how about the issue of this thread? Any other good solutions?
     
  8. Bribe

    Bribe

    Joined:
    Sep 26, 2009
    Messages:
    8,015
    Resources:
    25
    Maps:
    3
    Spells:
    10
    Tutorials:
    3
    JASS:
    9
    Resources:
    25
    Just use FourCC as had been earlier recommended. This thread has been resolved for a long time.