• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

vJass2Lua WebApp (powered by JavaScript) - now supports ZINC!

This bundle is marked as pending. It has not been reviewed by a staff member yet.
This webapp can nearly instantly convert a JASS or vJass script file into a Lua script, using JavaScript.

Compared to cJass2Lua, this parses a script file thousands of times faster, and is very easy to add onto and tweak as needed. The input script can be reverted just by clicking the "Revert to vJass" button (note that this does not convert a script from Lua to vJass, it just converts it back to what it was given).

It converts all known JASS scripts into Lua.

It converts almost all vJass and Zinc scripts into Lua, including textmacros that take arguments. Textmacros and modules that would normally inline into a function (like Nestharus's CTL resources) will not be parsed correctly since Lua has no way to literally "macro in" text. Some minor syntax changes are needed to make things work with Lua, but the terminology stays roughly familiar.

How to run:

1a) Go to https://bribefromthehive.github.io/vJass2Lua and skip to step 3
OR
1b) Download the attached .zip file or copy the source from GitHub: https://github.com/BribeFromTheHive/vJass2Lua/blob/main/index.html
2) Open the HTML file in a web browser.
3) Paste in some vJass or Zinc (make sure Zinc has included the //! zinc ... //! endzinc tags - if you forgot them, just tick the box at the bottom to add them for you and paste your code in-between).
4) The vJass code is instantly converted to Lua and copied to your clipboard accordingly (no clicking required).
5) Paste the Lua script into an editor (World Editor/Text editor).
Contents

vJass2Lua - automatic script converter (Binary)

Level 20
Joined
Jan 3, 2022
Messages
355
@Dat-C3 Function calls in Jass are extremely slow. Other than that, don't expect any "mind blowing" performance improvements. You should be in the clear that you better be a very good Lua programmer to debug any problems you encounter due to conversion. I had converted war3map.j to Lua using Blizzard's own transpiler and encountered a bug with real number handling being different between Lua and Jass (loop number + 0.1 repeated 100 times).
The greatest advantage of Lua is the ease of use and more convenient language features.
@note Performance numbers:
  • 10000 regular function calls in Jass: 3ms (300ns/call)
  • 10000 regular function calls in Lua: 0.07ms (6.9ns/call)
  • 10000 "ExecuteFunc" calls in Jass: ~50ms (5µs/call)
Result: plain Lua is ~43.5x and ~724x faster respectively.
Source: Unryze's test results using this code and his UjAPI (Jass on 1.26a; Lua on 1.32.10 and 1.26a).
 
That could be an apples-to-oranges comparison. The best way to bench it is to run FPS numbers and increase the number of repetitions on the heavier resource to achieve less than 60FPS, then increase the repetitions of the lighter resource to achieve the same FPS. The ratio between the numbers measures the performance benefit.
 
Damn, I've been sleeping for too long.
I wonder if it would ever be possible to convert hashtables into tables automatically. But this is already legendary :)
It's possible to have vJass2Lua zap away hashtable API, I did the same but only behind the scenes for Lua. Please raise an issue for it here so I don't lose track.
 
Level 20
Joined
Aug 13, 2013
Messages
1,696
i'm currently using the tool to convert lots of gui converted to text jass into lua just to make the map triggers compatible to the other scripts (because i don't have much time to rewrite all of them lol) i already have TotalInitialization however im getting such error:
1707916264379.png
here's the converted code:
Lua:
function Trig_Initialization_Actions()
    -- -------------------------------------------------------------------------------------------------
    -- Camera Improvements
    CinematicFadeBJ( bj_CINEFADETYPE_FADEOUT, 0.00, "ReplaceableTextures\\CameraMasks\\Black_mask.blp", 0.00, 0.00, 0.00, 0.00 )
    CameraSetSmoothingFactorBJ( 1.50 )
    SetCameraFieldForPlayer( Player(0), CAMERA_FIELD_TARGET_DISTANCE, 2000.00, 0.00 )
    -- -------------------------------------------------------------------------------------------------
    -- Game Environment
    SetTimeOfDay( 15.00 )
    -- -------------------------------------------------------------------------------------------------
end

--===========================================================================
function InitTrig_Initialization()
    gg_trg_Initialization = CreateTrigger(  )
    TriggerAddAction( gg_trg_Initialization, Trig_Initialization_Actions )
end


--Conversion by vJass2Lua v0.A.2.3
is there something i miss or need to modify etc... or it's not possible with the tool to convert a vanilla gui/jass into lua?
 
Level 20
Joined
Aug 13, 2013
Messages
1,696
done rechecking each and every code multiple times to ensure no jass scripts lying around somewhere else in my map and to only find out the culprit --- one should've also convert the triggers into scripts file instead? (since i convert them from gui to jass in trigger as text i just thought it'll also work replacing jass into lua code seamlessly inside the trigger text too) ;_;

i disabled the triggers first and enabled them after the conversion then saved the map which brings up the errors (i enabled the trigger which contains lua code through "Enabled" checkbox and seems like it puts the code inside "InitCustomTriggers" function declared in jass syntax which makes the compiler thinks i'm still in jass mode probably)

i just created a new script per converted trigger which made the errors gone for now

however, another thing is after managing them to be inside the scripts and not triggers i can't make them to work for ex:
Lua:
function Trig_Test_Dialogs_Actions()
    -- -
    DialogClearBJ( udg_Test_Dialog )
    DialogSetMessageBJ( udg_Test_Dialog, "TRIGSTR_098" )
    -- -
    DialogAddButtonBJ( udg_Test_Dialog, "TRIGSTR_099" )
    udg_Test_DialogButton[1] = GetLastCreatedButtonBJ()
    DialogAddButtonBJ( udg_Test_Dialog, "TRIGSTR_100" )
    udg_Test_DialogButton[2] = GetLastCreatedButtonBJ()
    -- -
    DialogDisplayBJ( true, udg_Test_Dialog, Player(0) )
    -- -
    DialogClearBJ( udg_Test_Dialog_Race )
    DialogSetMessageBJ( udg_Test_Dialog_Race, "TRIGSTR_101" )
    -- -
    DialogAddButtonBJ( udg_Test_Dialog_Race, "TRIGSTR_102" )
    udg_Test_DialogButton[3] = GetLastCreatedButtonBJ()
    DialogAddButtonBJ( udg_Test_Dialog_Race, "TRIGSTR_103" )
    udg_Test_DialogButton[4] = GetLastCreatedButtonBJ()
    DialogAddButtonBJ( udg_Test_Dialog_Race, "TRIGSTR_104" )
    udg_Test_DialogButton[5] = GetLastCreatedButtonBJ()
    DialogAddButtonBJ( udg_Test_Dialog_Race, "TRIGSTR_105" )
    udg_Test_DialogButton[6] = GetLastCreatedButtonBJ()
    -- -
    udg_Test_Footman_Type[4] = FourCC('ogru')
    udg_Test_Footman_Type[5] = FourCC('esen')
    udg_Test_Footman_Type[6] = FourCC('ugho')
    udg_Test_Rifleman_Type[4] = FourCC('ohun')
    udg_Test_Rifleman_Type[5] = FourCC('earc')
    udg_Test_Rifleman_Type[6] = FourCC('ucry')
    udg_Test_Knight_Type[4] = FourCC('orai')
    udg_Test_Knight_Type[5] = FourCC('edcm')
    udg_Test_Knight_Type[6] = FourCC('uabo')
    udg_Test_Mortar_Type[4] = FourCC('ocat')
    udg_Test_Mortar_Type[5] = FourCC('ebal')
    udg_Test_Mortar_Type[6] = FourCC('umtw')
    udg_Test_Flying_Type[4] = FourCC('otbr')
    udg_Test_Flying_Type[5] = FourCC('ehip')
    udg_Test_Flying_Type[6] = FourCC('ugar')
    udg_Test_Gryphon_Type[4] = FourCC('owyv')
    udg_Test_Gryphon_Type[5] = FourCC('echm')
    udg_Test_Gryphon_Type[6] = FourCC('ufro')
    udg_Test_Priest_Type[4] = FourCC('oshm')
    udg_Test_Priest_Type[5] = FourCC('edot')
    udg_Test_Priest_Type[6] = FourCC('unec')
    udg_Test_Sorceress_Type[4] = FourCC('odoc')
    udg_Test_Sorceress_Type[5] = FourCC('edoc')
    udg_Test_Sorceress_Type[6] = FourCC('uban')
    udg_Test_Siege_Type[4] = FourCC('otau')
    udg_Test_Siege_Type[5] = FourCC('emtg')
    udg_Test_Siege_Type[6] = FourCC('uobs')
    udg_Test_Breaker_Type[4] = FourCC('ospm')
    udg_Test_Breaker_Type[5] = FourCC('edry')
    udg_Test_Breaker_Type[6] = FourCC('ubsp')
    udg_Test_Peasant_Type[4] = FourCC('opeo')
    udg_Test_Peasant_Type[5] = FourCC('ewsp')
    udg_Test_Peasant_Type[6] = FourCC('uaco')
    udg_Test_Hero_Type[4] = FourCC('Othr')
    udg_Test_Hero_Type[5] = FourCC('Etyr')
    udg_Test_Hero_Type[6] = FourCC('Uear')
    udg_Test_Town_Type[4] = FourCC('ogre')
    udg_Test_Town_Type[5] = FourCC('etol')
    udg_Test_Town_Type[6] = FourCC('unpl')
    udg_Test_Keep_Type[4] = FourCC('ostr')
    udg_Test_Keep_Type[5] = FourCC('etoa')
    udg_Test_Keep_Type[6] = FourCC('unp1')
    udg_Test_Castle_Type[4] = FourCC('ofrt')
    udg_Test_Castle_Type[5] = FourCC('etoe')
    udg_Test_Castle_Type[6] = FourCC('unp2')
    udg_Test_Farm_Type[4] = FourCC('otrb')
    udg_Test_Farm_Type[5] = FourCC('emow')
    udg_Test_Farm_Type[6] = FourCC('uzig')
    udg_Test_Altar_Type[4] = FourCC('oalt')
    udg_Test_Altar_Type[5] = FourCC('eate')
    udg_Test_Altar_Type[6] = FourCC('uaod')
    udg_Test_Barracks_Type[4] = FourCC('obar')
    udg_Test_Barracks_Type[5] = FourCC('eaom')
    udg_Test_Barracks_Type[6] = FourCC('usep')
    udg_Test_Lumber_Type[4] = FourCC('ofor')
    udg_Test_Lumber_Type[5] = FourCC('edob')
    udg_Test_Lumber_Type[6] = FourCC('ugrv')
    udg_Test_Blacksmith_Type[4] = FourCC('ofor')
    udg_Test_Blacksmith_Type[5] = FourCC('edob')
    udg_Test_Blacksmith_Type[6] = FourCC('ugrv')
    udg_Test_Workshop_Type[4] = FourCC('obea')
    udg_Test_Workshop_Type[5] = FourCC('eaoe')
    udg_Test_Workshop_Type[6] = FourCC('uslh')
    udg_Test_Sanctum_Type[4] = FourCC('osld')
    udg_Test_Sanctum_Type[5] = FourCC('eaow')
    udg_Test_Sanctum_Type[6] = FourCC('utod')
    udg_Test_Scout_Type[4] = FourCC('npgf')
    udg_Test_Scout_Type[5] = FourCC('nfv2')
    udg_Test_Scout_Type[6] = FourCC('ngni')
    udg_Test_Guard_Type[4] = FourCC('owtw')
    udg_Test_Guard_Type[5] = FourCC('etrp')
    udg_Test_Guard_Type[6] = FourCC('uzg1')
    udg_Test_Vault_Type[4] = FourCC('ovln')
    udg_Test_Vault_Type[5] = FourCC('eden')
    udg_Test_Vault_Type[6] = FourCC('utom')
    -- -
    -- -
end

--===========================================================================
function InitTrig_Test_Dialogs()
    gg_trg_Test_Dialogs = CreateTrigger(  )
    TriggerRegisterTimerEventSingle( gg_trg_Test_Dialogs, 0.00 )
    TriggerAddAction( gg_trg_Test_Dialogs, Trig_Test_Dialogs_Actions )
end

--Conversion by vJass2Lua v0.A.2.3

the converted scripts just work after doing something like:
Lua:
OnInit.trig(function()
    gg_trg_Test_Dialogs = CreateTrigger(  )
    TriggerRegisterTimerEventSingle( gg_trg_Test_Dialogs, 0.00 )
    TriggerAddAction( gg_trg_Test_Dialogs, Trig_Test_Dialogs_Actions )
end)
which makes me think one should modify all of the converted scripts trigger initialization one by one after the conversion right or i'm doing it the wrong way?
 
Level 20
Joined
Jan 3, 2022
Messages
355
@FUJI I can't tell you off top of my head the entire procedure step by step, how to go forward. But I will explain how WorldEditor works:
  • GUI Triggers are still converted to Jass even if you are in Lua mode
  • This Jass code is ran through Jass2Lua (same for Preload files)
  • Any custom code (read "your code") is exempt from the above conversion by the editor. It does that by surrounding it in "beginusercode / endusercode" directives
This means to convert a semi-GUI map to Lua, you must update all custom code parts yourself. Since the editor considers all custom code chunks to be Lua, you cannot use vJass directly there. I haven't tried escaping it with endusercode though. What I did instead, rip out the vJass that was converted to Jass from the war3map.j file and convert that Jass to Lua.

I haven't come around to test more in this area to write a proper guide. Good luck
 
Level 20
Joined
Aug 13, 2013
Messages
1,696
@FUJI I can't tell you off top of my head the entire procedure step by step, how to go forward. But I will explain how WorldEditor works:
  • GUI Triggers are still converted to Jass even if you are in Lua mode
  • This Jass code is ran through Jass2Lua (same for Preload files)
  • Any custom code (read "your code") is exempt from the above conversion by the editor. It does that by surrounding it in "beginusercode / endusercode" directives
This means to convert a semi-GUI map to Lua, you must update all custom code parts yourself. Since the editor considers all custom code chunks to be Lua, you cannot use vJass directly there. I haven't tried escaping it with endusercode though. What I did instead, rip out the vJass that was converted to Jass from the war3map.j file and convert that Jass to Lua.

I haven't come around to test more in this area to write a proper guide. Good luck
thank you so much for these info @Luashine i just thought i can easily convert those triggers in gui/jass map to be compatible in lua mode without me touching the resulting codes of which the @Bribe 's converter gives.

i guess better off modifying those converted scripts just a little to save time than rewriting all of them. :pir:
 
Level 2
Joined
Oct 29, 2024
Messages
7
Hey, it seems that for me, any line with slash (\) in it, messes up the parser. For example:
JASS:
        private string write_buffer = "\n"
        private integer file_idx = 0
Becomes
JASS:
    local write_buffer        = "\n"
    private integer file_idx = 0
and many many lines after this one are also not parsed, until another slash is reached or something.
I tried replacing the slashes with double slashes which seems to be doing the trick, but it's too hard to convert them back after parsing.
Am I doing something wrong?

A minimal example that doesn't seem to work:
JASS:
function a4 takes nothing returns nothing
    local string a2 = "\n"
    local string a3 = ""
endfunction
Changing the "\n" to "\\n" fixes the problem
 
Last edited:
Top