• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

Map Transpiler

Status
Not open for further replies.
Level 18
Joined
Jan 1, 2018
Messages
728
Have you ever wanted to play a map in lua mode but couldn't, because it was made with jass?

Well today is your lucky day, because now you can make those maps playable in lua, using my new tool. And yes, I'm totally copy-pasting this silly description from my other tool because why not.

Things to know before you use this:
  • Requires .NET 5.0: Download .NET 5.0 Runtime
  • Only works on windows because making a tool for a 20 year old game requires a 20 year old GUI library.
  • Requires common.j and Blizzard.j, which are automatically taken from '$Documents$\Warcraft III\JassHelper'. These files will be automatically created in this location when you enable JassHelper in the world editor.
  • DOES NOT transpile your triggers. This tool only sets the language in war3map.w3i to lua and converts the (scripts\)war3map.j file to war3map.lua, nothing more.
This project is open source, you can find it here.
 

Attachments

  • Map Transpiler v0.2.0.zip
    6.3 MB · Views: 110
Last edited:
Level 18
Joined
Jan 1, 2018
Messages
728
Not sure if anyone is interested in this tool (the +reps say yes but the replies say no), but I have rewrittem my JASS parser from scratch (using this library) and it's a lot faster now (running a benchmark on parsing common.j, the old parser took 368ms while the new parser did it in 61ms).
Since I also rewrote the syntax classes from scratch, I still need to rewrite the transpiler methods as well. I will probably upload a new version sometime next week/month.
 
Level 18
Joined
Jan 1, 2018
Messages
728
I have uploaded a new version of the tool, and also updated the first post a bit.
v0.2.0 changelog:
  • Uses a new jass parser which has the following benefits:
    • Greatly improved performance (~6 times as fast, ~90% less memory usage);
    • Aware of operator precedence, which helps correctly transpile binary expressions that should use string concatenation or integer division.
I also discovered some cases where the script behaves differently in lua than in jass, which can potentially cause issues:
  • Difference in result of SubString native;
  • Different handling of string concatenation when either of the operands is null.
These problems can be fixed (mostly) by including the following code in the map script:
Lua:
local oldSubString = SubString
SubString = function(source, start, _end)
    if start > StringLength(source) then
        return nil
    end
    return oldSubString(source, start, _end)
end

local mt = getmetatable("")
mt.__concat = function(left, right) return (left or "") .. (right or "") end

Note that concatting nil and nil will still crash in lua (while this returns null in jass).

A later version of the tool will have the option to automatically include these fixes when transpiling the map script.
 
Level 13
Joined
Oct 18, 2013
Messages
691
Title:
MAP TRANSPILER
Description:
  • DOES NOT transpile your triggers. This tool only sets the language in war3map.w3i to lua and converts the (scripts\)war3map.j file to war3map.lua, nothing more.
Me:

confucius intensifies
 
Level 18
Joined
Jan 1, 2018
Messages
728
Title:
MAP TRANSPILER
Description:
  • DOES NOT transpile your triggers. This tool only sets the language in war3map.w3i to lua and converts the (scripts\)war3map.j file to war3map.lua, nothing more.
Me:

confucius intensifies
If your triggers are 100% GUI only it's fine, but custom script actions and custom text triggers do not get transpiled.
For example if you use 'call RemoveLocation(udg_Location)', in lua there is no 'call' keyword, so this custom script action does not compile anymore when the map's script language is changed from jass to lua.
Basically, this tool is not (yet) meant to be used on a map if you want to continue editing it in the world editor afterwards.
 

Bribe

Code Moderator
Level 50
Joined
Sep 26, 2009
Messages
9,467
I’ve thought of a very good use case for a language post-processor, if this took a Lua source and if you made some modifications to help inline some GUI function calls.

Currently, GUI if/then/else statements and ForGroup creates a new function at the top of the Actions function. With a small modification, your system could inline those, thereby allowing local variables declared within the actions of the GUI triggers to be inlined.

This would allow a system like DamageEngine to call a GUI function with parameters “GetTriggerUnit” and the like, which are then overriding everything referencing it in the GUI trigger including if/then/else blocks and would potentially persist after a “wait” (if coroutines are used tactically).

Then again, it is probably too much of a chore as it eliminates the ability to quickly test something from within World Editor. Too bad we can’t use plugins like we used to in JNGP.
 
Level 18
Joined
Jan 1, 2018
Messages
728
I’ve thought of a very good use case for a language post-processor, if this took a Lua source and if you made some modifications to help inline some GUI function calls.

Currently, GUI if/then/else statements and ForGroup creates a new function at the top of the Actions function. With a small modification, your system could inline those, thereby allowing local variables declared within the actions of the GUI triggers to be inlined.

This would allow a system like DamageEngine to call a GUI function with parameters “GetTriggerUnit” and the like, which are then overriding everything referencing it in the GUI trigger including if/then/else blocks and would potentially persist after a “wait” (if coroutines are used tactically).

Then again, it is probably too much of a chore as it eliminates the ability to quickly test something from within World Editor. Too bad we can’t use plugins like we used to in JNGP.
I'm not really sure how this relates to what my tool does.
The main reason I made this / the underlying library is to convert jass maps to lua, so that I could play them (eventually, in a very VERY far future) in my own wc3 engine (think warsmash), so I don't have to create a jass interpreter (I can parse jass but i cannot run it), but I do have a working solution for lua already.
 
Level 18
Joined
Jan 1, 2018
Messages
728
I've just corrected that. Not sure if JassHelper ignores the error, but it shouldn't.
I tested it in world editor with jasshelper enabled and didn't get an error, which is why I asked.

If you are working on a vJass parser, is there some part of the project you think could be delegated to me? I do feel that vJass2Lua has basically hit a wall in terms of what regex spam can do.
I haven't uploaded anything yet but I'm hoping to do so this weekend when I can parse all test libraries and have cleaned up the code, then you'll be able to find the project here: https://github.com/Drake53/War3Net/tree/master/src/War3Net.CodeAnalysis.VJass
Note that it currently still 404's obviously.

I don't think I'll need any help with the coding part, I already have the basics in place, which is enough to parse the majority of the libraries that I'm using to test the parser: War3Net/tests/War3Net.TestTools.UnitTesting/TestData/VJass/Libraries at master · Drake53/War3Net
If you want to contribute the most useful would be if you can find any vJASS code that my parser cannot parse, or parses incorrectly.
 

Bribe

Code Moderator
Level 50
Joined
Sep 26, 2009
Messages
9,467
I tested it in world editor with jasshelper enabled and didn't get an error, which is why I asked.


I haven't uploaded anything yet but I'm hoping to do so this weekend when I can parse all test libraries and have cleaned up the code, then you'll be able to find the project here: https://github.com/Drake53/War3Net/tree/master/src/War3Net.CodeAnalysis.VJass
Note that it currently still 404's obviously.

I don't think I'll need any help with the coding part, I already have the basics in place, which is enough to parse the majority of the libraries that I'm using to test the parser: War3Net/tests/War3Net.TestTools.UnitTesting/TestData/VJass/Libraries at master · Drake53/War3Net
If you want to contribute the most useful would be if you can find any vJASS code that my parser cannot parse, or parses incorrectly.
Sounds like you've got a solid plan. Does your parser work with the JassHelper output code (e.g. structs to parallel arrays) or does it preserve the object-oriented syntax of the source (encapsulation)? Do you plan to leave textmacros packed or unpacked?
 
Level 18
Joined
Jan 1, 2018
Messages
728
Sounds like you've got a solid plan. Does your parser work with the JassHelper output code (e.g. structs to parallel arrays) or does it preserve the object-oriented syntax of the source (encapsulation)? Do you plan to leave textmacros packed or unpacked?
I'm writing the parser from scratch (somewhat based on my existing JASS parser, but due to certain differences I'm trying to keep most things separate), so not using JassHelper.
The parser will only make an AST of the source, so preprocessor directives like textmacros and imports will not be processed, though I'll probably add some kind of Preprocess() method to handle these.
 

Bribe

Code Moderator
Level 50
Joined
Sep 26, 2009
Messages
9,467
Sorry to sound like a total noob here, but I installed .NET 6.0 (assuming that yours isn't limited to just 5.0) and downloaded your .zip file, but I have no idea what to do next. I think some steps are missing, for example I think I am supposed to use .NET to compile it, however I have never compiled an .exe file before and I am not sure how to do that with your provided files. Having those steps documented would be most welcome.
 
Level 18
Joined
Jan 1, 2018
Messages
728
Sorry to sound like a total noob here, but I installed .NET 6.0 (assuming that yours isn't limited to just 5.0) and downloaded your .zip file, but I have no idea what to do next. I think some steps are missing, for example I think I am supposed to use .NET to compile it, however I have never compiled an .exe file before and I am not sure how to do that with your provided files. Having those steps documented would be most welcome.
I don't think you can run .NET 5.0 applications with the .NET 6.0 runtime.
You don't have to compile anything, the .exe is framework-dependent so if you have the correct runtime installed it will run.
 
Status
Not open for further replies.
Top