1. Head to the 33rd Modeling Contest Poll and drink to your heart's desire.
    Dismiss Notice
  2. Choose your means of doom in the 17th Mini Mapping Contest Poll.
    Dismiss Notice
  3. A slave to two rhythms, the 22nd Terraining Contest is here.
    Dismiss Notice
  4. The heavens smile on the old faithful. The 16th Techtree Contest has begun.
    Dismiss Notice
  5. The die is cast - the 6th Melee Mapping Contest results have been announced. Onward to the Hive Cup!
    Dismiss Notice
  6. The glory of the 20th Icon Contest is yours for the taking!
    Dismiss Notice
  7. 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, embedded jass

Discussion in 'The Lab' started by Tasyen, Oct 13, 2020.

  1. Tasyen

    Tasyen

    Joined:
    Jul 18, 2010
    Messages:
    1,661
    Resources:
    37
    Tools:
    2
    Maps:
    3
    Spells:
    11
    Tutorials:
    20
    JASS:
    1
    Resources:
    37
    According to posts from 1.31 PTR it is possible to have jass code in a Lua map. To do so one has to tell the compiler that Lua code ends now. The one adds jass code and after the jass code is done, one says that Lua continues. This is done with:
    //! endusercode

    //! beginusercode


    This embedded jass will end as Lua in the resulting map script and can be used in the Lua code. The jass has to be normal jass, no extended version but it can have any amount of global blocks.

    Example:
    Code (Lua):

    -- Lua code

    //! endusercode
    //jass code
    function MyJassFunction takes integer a, integer b returns nothing
     call BJDebugMsg("MyJassFunction: " + I2S(a)+ " " + I2S(b))
    endfunction
    //! beginusercode

    -- Lua code
    TimerStart(CreateTimer(), 0, false, function()
        MyJassFunction(4, 8)
    end)
    When that is placed into a Lua map the game will at 0s run MyJassFunction (tested in Warcraft 3 1.31 and 1.32.8). Beaware that the shown way of selfexecution is not multiplayer safe.

    Why I even know this? Or wanted to know it.
    I wanted to add custom written Lua functions to the GUI-TriggerData which only supports jass right now. If one tries without this definitions in jass the compiler throws a Lua transpiler error pointing to the custom GUI-Actions using the Lua functions which can not be found in jass.
     
  2. Bribe

    Bribe

    Joined:
    Sep 26, 2009
    Messages:
    8,364
    Resources:
    25
    Maps:
    3
    Spells:
    10
    Tutorials:
    3
    JASS:
    9
    Resources:
    25
    This makes sense why the WC3 engine now runs at half the performance it used to - because it is running a JASS2 engine and Lua engine simultaneously. How inefficient. It still would be nice to be able to convert JASS maps to Lua maps without jumping through 20 hoops.
     
  3. Tasyen

    Tasyen

    Joined:
    Jul 18, 2010
    Messages:
    1,661
    Resources:
    37
    Tools:
    2
    Maps:
    3
    Spells:
    11
    Tutorials:
    20
    JASS:
    1
    Resources:
    37
    That is a missunderstanding, this only affects the Trigger Editor. The resulting map script will be Lua only with the jass script being transpiled to Lua.