Hello there !
I have nearly finished converting my map to Lua. It was a hard task and the main reason is Lua's complete flexibility with variables. It can be a clear advantage in many situations, but overall it makes debugging the tiniest typos a nightmare, unless using VSCode with appropriate plugins - unfortunately I am so used to Notepad++ that, for the sake of time, I still always come back to it for my script editing.
Anyways, besides the horrors that can make your map completely bug with a simple typo, I have encountered a much more serious issue with Lua : The Standard Libraries !!!
Of course, many Lua functions from the libraries actually work like a charm !
But many of them, especially in the math or string libraries gave me a hard time, especially as I just started learning the language.
Here are simple examples :
math.atan2 -> this one, allowing to calculate the angle between a point and its origin, crashes any thread I try to add it to.
Worse, you can never tell which function is going to work or not.
math.sqrt or math.pi (ok thats not really a function) or a few others are among those one can freely use in a wc3 map.
This forced me to roll back to some Jass natives like Atan2 and quite a few others.
Hell after so many bugs I encountered, I am not even sure math.floor does actually work properly, there are cases when I had to use R2I !!! (and not because of negative values)
The latest surprise I just encountered is about the string library.
That also gave me nightmares. for example, when trying to find a character in a string. Well for a start, for Lua searching for a character in a string is too much to ask.
No of course, when you see a fly and want to get rid of it, the only way to do it is definitely a rocket launcher, is it not, my dear Lua ???
First Lua doesn't understand what a character is. Wait that is wrong, Lua knows what a byte is... great, but that is not helping.
So back to the problem : to find a character in a string, you actually have to find a pattern (that will in fact be your character), in your string, and string.find() will actually return the positions of your pattern.
Fair enough let's do it then. Let's find the character "." in my string....
- Wait, no you can't !
What ?
- Yes you can't. Because "." is a pattern that in fact means any character !
Wonderful so what do we do ?
- You have to escape your character
Okays, rings a bell, escaping characters was an obligation in web development, so I should not be loss.
But really, is there no easier way? How can such a simple task become so complicated with such a flexible language ?
- Actually you can do something else !
Mmmm ?
- In fact string.find can take another boolean argument. it is meant for plain text search in the string !
You couldn't say that before of course ? Anyways, thanks I'll try that straight away !!!
Ok let's see.....
THREAD CRASH !!!!!!
WTF ?
I don't know man, I only use Lua for Wow interfaces. Have to go, GL HF !!
GG Lua...
OK let's escape then.....
Funny scenario or not, how are we supposed to guess what Lua "library natives" will work or not, and worse how are we supposed to find out what syntax or number of arguments are allowed or not?
Anyone has had better success ?
I had planned on working on a complex project involving a lot of maths and string parsing, but it seems using Lua for that will be pure suicide in wc3...
Is there anyone fluent enough in wc3 Lua here to advise us on what we should do?
Note : It is also disappointing as most Jass natives are much slower than the Lua versions as far as I have seen with the benchmarks. Would be nice if the standard libraries would work properly.
Side note : I would also like to know how to replace some natives or functions already declared like it seems Lua allows us to do.
EDIT : About math.atan2, i also tried with math.atan that didn't help, als the greats thing about math.atan2 or Atan2 in Jass is that if takes both point coordinates x and y as separate arguments to handle the case when y is 0.
Jass might be slow as a dying snail, but at least you can rely on all its natives... at least when you stay away from the UI API
I have nearly finished converting my map to Lua. It was a hard task and the main reason is Lua's complete flexibility with variables. It can be a clear advantage in many situations, but overall it makes debugging the tiniest typos a nightmare, unless using VSCode with appropriate plugins - unfortunately I am so used to Notepad++ that, for the sake of time, I still always come back to it for my script editing.
Anyways, besides the horrors that can make your map completely bug with a simple typo, I have encountered a much more serious issue with Lua : The Standard Libraries !!!
Of course, many Lua functions from the libraries actually work like a charm !
But many of them, especially in the math or string libraries gave me a hard time, especially as I just started learning the language.
Here are simple examples :
math.atan2 -> this one, allowing to calculate the angle between a point and its origin, crashes any thread I try to add it to.
Worse, you can never tell which function is going to work or not.
math.sqrt or math.pi (ok thats not really a function) or a few others are among those one can freely use in a wc3 map.
This forced me to roll back to some Jass natives like Atan2 and quite a few others.
Hell after so many bugs I encountered, I am not even sure math.floor does actually work properly, there are cases when I had to use R2I !!! (and not because of negative values)
The latest surprise I just encountered is about the string library.
That also gave me nightmares. for example, when trying to find a character in a string. Well for a start, for Lua searching for a character in a string is too much to ask.
No of course, when you see a fly and want to get rid of it, the only way to do it is definitely a rocket launcher, is it not, my dear Lua ???
First Lua doesn't understand what a character is. Wait that is wrong, Lua knows what a byte is... great, but that is not helping.
So back to the problem : to find a character in a string, you actually have to find a pattern (that will in fact be your character), in your string, and string.find() will actually return the positions of your pattern.
Fair enough let's do it then. Let's find the character "." in my string....
- Wait, no you can't !
What ?
- Yes you can't. Because "." is a pattern that in fact means any character !
Wonderful so what do we do ?
- You have to escape your character
Okays, rings a bell, escaping characters was an obligation in web development, so I should not be loss.
But really, is there no easier way? How can such a simple task become so complicated with such a flexible language ?
- Actually you can do something else !
Mmmm ?
- In fact string.find can take another boolean argument. it is meant for plain text search in the string !
You couldn't say that before of course ? Anyways, thanks I'll try that straight away !!!
Ok let's see.....
periodpos=string.find(CharMap, '.', true)
hop Test map yes !!!!THREAD CRASH !!!!!!
WTF ?
I don't know man, I only use Lua for Wow interfaces. Have to go, GL HF !!
GG Lua...
OK let's escape then.....
Funny scenario or not, how are we supposed to guess what Lua "library natives" will work or not, and worse how are we supposed to find out what syntax or number of arguments are allowed or not?
Anyone has had better success ?
I had planned on working on a complex project involving a lot of maths and string parsing, but it seems using Lua for that will be pure suicide in wc3...
Is there anyone fluent enough in wc3 Lua here to advise us on what we should do?
Note : It is also disappointing as most Jass natives are much slower than the Lua versions as far as I have seen with the benchmarks. Would be nice if the standard libraries would work properly.
Side note : I would also like to know how to replace some natives or functions already declared like it seems Lua allows us to do.
EDIT : About math.atan2, i also tried with math.atan that didn't help, als the greats thing about math.atan2 or Atan2 in Jass is that if takes both point coordinates x and y as separate arguments to handle the case when y is 0.
Jass might be slow as a dying snail, but at least you can rely on all its natives... at least when you stay away from the UI API
Last edited: