• 🏆 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!

...then I found the automatic JASS to LUA converter.

Status
Not open for further replies.
Level 12
Joined
Jan 30, 2020
Messages
875
Hello there !

As some of you already know, especially as I often come here to ask for help when I am hitting difficulties, I am currently converting my map from Jass2 to Lua.

I have gone quite far, and only a few functions remain problematic, not mentioning the upcoming hidden bugs I have not yet encountered.

This is a hard task, especially when you are so used to and comfortable with Jass, because this one gives you very bad habits and negligence about variables types and initialization. Indeed, in Jass, if you misconsider the variable type or if you don't properly initialize it, it will throw you an error straight away telling you what is wrong.

In Lua, there is no such thing as variable types. In fact only values have a type, and if you don't pay attention, and you do the tiniest mistake when it comes to dealing with your variables, you will, as I did and still do, have a really tough time finding out why nothing works, or why your map crashes for unexpected reasons.

I am not complaining, these endless hours of struggling with converting my triggers and functions to Lua have been immensely instructive, and in fact, the code in Lua looks so much cleaner , even though I have not yet even tried to switch to Object Oriented programming or even scratched the surface of the overall possibilities Lua has to offer.


Yet, while I was comparing the 2 version of my maps a couple of hours ago, first one being the latest Jass2 version and the second one the latest state of my conversion, with the multiple changes and additions I have made besides the Jass2->Lua conversion (If you don't distract your mind from code from time to time, you will suffer^^), I have accidentally found that World Editor does not only have an integrated GUI to Lua converter, but also a Jass2 to Lua Transpiler.

To be honest I don't know how I invoked it.

I had both Jass2 and Lua versions of my map open in World Editor, and was exporting both map scripts in order to compare them.

Then I found out that when I tried to save my Jass2 map script, WE created a Lua version of the script !!!!

Out of curiosity, I saved my Jass map to a different name to preserve the original, disabled all my triggers (custom scripts), changed the map scripting language from JASS to LUA in the map options.

Then I grabbed all the converted functions and triggers one by one from the converted Lua map script with Notepad++ and pasted them each one by one to replace the corresponding Jass2 versions.


And guess what... the WHOLE MAP works perfectly in Lua. Not a bug, not a glitch !!!

There was only a small issue with the Map Init that was in fact a vJass scope. Fixed it with the lazy solution : GUI trigger with Map Initialization event and calling my map init function in actions.

For some reason I remember someone here saying there was a Jass to Lua transpiler that only had issues with vJass (was it you @Dr Super Good ?). By the way, I found it accidentally, but how do you invoke it at will ?

Anyways, the downside is that the converted Lua code, although functional, is definitely looking too "Jassy" and messy, so I will keep up my conversion work. This said, if I ever get stuck and fed up, I can now steal the working converted functions...

The finality of this post is to let people know about the transpiler, because I had no idea it was there, and still have no idea how to use it when needed. So if you want to switch to Lua, there is a very quick way that only takes a few minutes...
 
Last edited:
Why convert the map to Lua if you coded in vjass before? Especially if you dont use OOP anyway.

Granted, I dont get the Lua hypetrain, simply because I dont like programming languages that dont have type safety.

But yes, this might be a solution for those who still want to use old resources with Lua.
 
Level 12
Joined
Jan 30, 2020
Messages
875
Hello ^^

Well I have always wanted to switch to something better than Jass.

Jass is a terrible language, and in all fairness vJass being just a smart layer on top of it did not help that much as it could not overcome all the limitations of Jass.
I will be honest, I don't like Lua. I mean I have used many different languages when I was a developer a few years back, and although I didn't have such a large choice as today in terms of efficient languages, I still had much pleasure coding in things like Jasascript or even JavaScript or PHPOO or Java or even a little bit of C#.

Hell as for event triggered languages, I even had hundred times more fun with ActionScript 3.0 than with Jass.

If I chose Lua, I only did it after a long hesitation and after considering all the things I have noticed or been told :
- Lua is faster
- Lua's virtual machine is more efficient and more stable overall than Jass virtual machine
- Lua is extremely flexible, and its Tables are really powerful.
- Lua can be object oriented (thanks to tables it seems)
- Lua is the most used scripting language in the whole gaming industry's modding community

Now I admit I much prefer strongly typed languages, and by very far. I like to know what kind of data is referenced by my variables, and I even like when the constraints with types are strongly imposed. Only in such circumstances can I feel like I am in my comfort zone as a developer.

- I was very tempted with Wurst as it seemed to offer everything I ever wanted, except I realized it was, just like vJass, an extra layer above Jass2, and that it was then transpiled to Jass and then using Jass Virtual Machine.
- There is an option in Wurst to transpile to Lua rather than Jass, but it seems still buggy when I look at requests on the GitHub Repo.
- Wurst doesn't seem to still be actively maintained, and that is worrying in the long term.

If Wurst would have been up to date and would use the Lua Virtual Machine properly, I would have chosen it with no hesitation, and I would have been delighted.



Note : performance is very important for my Map, and will be for my next project, because they all imply situations quite heavy for the game engine, so choosing the fastest available virtual machine to execute my scripts creates much less overhead for the game engine.
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,198
For some reason I remember someone here saying there was a Jass to Lua transpiler that only had issues with vJass (was it you @Dr Super Good ?). By the way, I found it accidentally, but how do you invoke it at will ?
It is used internally by World Editor. GUI triggers save to JASS2 and then the transpiler is used to convert them to Lua if the virtual machine is set to Lua. Currently there is no way to invoke it at will.

Many people have requested that it be used automatically. Apparently the developers are looking into this in some form or another, but if the feature materializes only time will tell.
 
Why convert the map to Lua if you coded in vjass before? Especially if you dont use OOP anyway.

Granted, I dont get the Lua hypetrain, simply because I dont like programming languages that dont have type safety.

But yes, this might be a solution for those who still want to use old resources with Lua.

Its quite easy to get type safety by using transpilers such as TypeScriptToLua. Lua is vastly superior to JASS and with the aforementioned transpiler you get all of the features of Lua with a static typed language.
 
Level 12
Joined
Jan 30, 2020
Messages
875
@Dr Super Good : yes thats what I thought, I won't need it anymore, but I should try to reproduce what I did in order to help future switchers.

I believe it is easier to start with a working Lua code and then slowly optimize it when learning Lua.
I have to admit it would have saved me quite a few nightmares if I had known :)

@TriggerHappy : I think already heard about TypeScript as an evolution of JavaScript, does it share a part of its syntax ? Ig it is strongly typed as the name might indicate, I am really interested.
Is there a TypeScript -> Lua transpiler that you would recommend ?

Thanks for the input guys !
 
@TriggerHappy : I think already heard about TypeScript as an evolution of JavaScript, does it share a part of its syntax ? Ig it is strongly typed as the name might indicate, I am really interested.
Is there a TypeScript -> Lua transpiler that you would recommend ?

TypeScript is basically JavaScript with static typing. I have a very easy to setup template with some nice features such as wrappers for most handle types, compile time functionality, etc..

cipherxof/wc3-ts-template

Many people are using it and it's quite stable, although not perfect. I am personally using it for my ORPG and it has been a godsend.

chat4.gif
 
Level 12
Joined
Jan 30, 2020
Messages
875
Thank you ever so much.

This template seems to be exactly what I was looking for.
I will do some testing and I have the strong feeling I will use this for my new upcoming project.

... amazing UI by the way, clean and beautiful !
 
Status
Not open for further replies.
Top