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

Lua libraries bugged ?

Status
Not open for further replies.
Level 12
Joined
Jan 30, 2020
Messages
875
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..... 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:
Level 12
Joined
Jan 30, 2020
Messages
875
OK.

Indeed it worked, and I am grateful.

What about finding a plain character in a string with Lua 5.3 ?

EDIT :

Ok thanks to your link I found out there was another argument missing.

So position = string.find(CharMap, ".", 1, true) does indeed work.

I feel like never using any other resource than this 5.3 manual to solve my Lua problems.

With experiment with the other functions I had issues with, thanks for your precious help !
 
Last edited:
Level 18
Joined
Jan 1, 2018
Messages
728
What about finding a plain character in a string with Lua 5.3 ?
You should be able to use string.find for this. I see you already tried this, but failed because you tried to set the optional argument 'plain', but you must also set the optional argument 'init' which comes before that. According to the documentation, the default value is 1, so you could use
Lua:
periodpos=string.find(CharMap,  '.', 1, true)
 
Level 12
Joined
Jan 30, 2020
Messages
875
Seems you answered just as I was typing :D

Thanks, I don't know why I didn't focus on this Manual, maybe because I though wrongly that wc3 didn't support v 5.3
 
Level 12
Joined
Jan 30, 2020
Messages
875
Yes thanks thats what was specified in the link given by Drake53.

I must admit using the reference manual for v5.3 just helped me fix a few library functions I did not know how to use properly.

Reason I hadn't tried math.atan before is because the old definition only took x/y as an argument.


Anyways most of my math function problems are fixed now, I have reached the last run with the last few triggers still not working.

Converting a complex map from Jass to Lua really is a nightmare, especially when you have the bad habit of waiting for the parser to tell you every single mistake you made with Jass, whereas with Lua this is a no-go.

I also am battling certain situations where the slightest mistake in declaring a global is fatal but not obvious at first sight.

Anyways thanks guys, I am getting there, and every little mistake fixed is an amazing way to learn !!!
 
Status
Not open for further replies.
Top