wurstscript / WurstScript

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

Ingame errors with -lua #885

Closed Jampi0n closed 2 years ago

Jampi0n commented 5 years ago

I tried the -lua run argument in my map and it produced errors during the initialization. One of the issues I found is, that functions can return nil instead of the specified type, possibly leading to errors, when using the returned value.

code to reproduce: https://bin.wurstlang.org/ajosinetib.wurst

Could be related to #869

Jampi0n commented 4 years ago

I managed to change my map, so it works in lua. The most prevalent issue is mentioned above. In particular this construct does not work: let tmp = HashMap.get(key) if tmp != null This can be fixed using HashMap.has(key) before.

Additionally using null as string does not work.

For the first issue, there is likely no good solution, other than updating the code and check whether the key exists first. I assume null strings can work by simply replacing null with "", when compiling to lua (is there a difference between null and "" in jass?)

The standard library uses the HashMap as shown above, so it can lead to issues. It also uses null as string, so at the moment FrameHandle.wurst cannot initialize.

peq commented 4 years ago

Thanks for the report.

The thing with nulls and strings is something I thought was working. We have some test cases testing different combinations of using null here: https://github.com/wurstscript/WurstScript/blob/d79f738cfee4d10e288097755d17b165985c3c39/de.peeeq.wurstscript/src/test/java/tests/wurstscript/tests/BugTests.java#L1083-L1123

Can you show an example where null as string does not work?

I'll also look at the HashMap problem. Maybe that will already fixed by the upcoming changes in #931 .

Jampi0n commented 4 years ago

Using the FrameHandle package leads to an error, because it uses let mouseCage = createFrame("FRAME", "SetMousePositionCage", GAME_UI, null, 0) in line 389. Here, null is used as parameter for a native function that expects a string.

So using that package, you get an error with the string. For example with this code: https://bin.wurstlang.org/viyirecelo.wurst

On a related note, I found an issue when I tried to create a minimal example with the string problem. If I add the imports NoWurst and Framehandle to minimize the produced code, the map doesn't start in lua mode (JASS works fine). I only get the screen with the lordaeron lion. Code: https://bin.wurstlang.org/epuhotezaj.wurst

Frotty commented 2 years ago

seems resolved.