wurstscript / WurstScript

Programming language and toolkit to create Warcraft III Maps
https://wurstlang.org
Apache License 2.0
226 stars 28 forks source link

lua: use BJDebugMsg for error messages if not using ErrorHandling package #996

Closed Jampi0n closed 3 years ago

Jampi0n commented 3 years ago

In lua, init blocks result in incorrect map scripts, if the package ErrorHandling is not used. In particular, the print function inside the error function will be "$debugPrint". The $ character causes the map to not load.

This change is based on the jass expression translation here: ExprTranslation.java

This change only has an effect if ErrorHandling is not used. Then the call to "$debugPrint" is replaced with "BJDebugMsg" like in the jass expression translator.

Frotty commented 3 years ago

Just for information, why wouldn't you use the ErrorHandling package?

Jampi0n commented 3 years ago

I tried to construct minimal examples to reproduce errors. Using NoWurst the generated map script is smaller and easier to debug. In this case I tried to come up with the example of #994 and noticed that the map doesn't load without _Handles. Then I did more tests and noticed, that it's because of ErrorHandling.

For normal maps I always use ErrorHandling.

Frotty commented 3 years ago

How exactly does this check whether debugPrint is available?

Jampi0n commented 3 years ago

The intermediate program already checks whether ErrorHandling is available. imError is the function which calls the error function. It searches for the error function with findErrorFunc, which returns the error function from ErrorHandling if available. Otherwise a default error function will be used. This default function also contains a call to $debugPrint. The translation from $debugPrint to BJDebugMsg was missing in lua. It exists in JASS as you can see in the link I posted above.