gudzpoz / luajava

Lua for Java on Windows, Mac OS X, Linux, Android. 5.1, 5.2, 5.3, 5.4, LuaJ or LuaJIT.
https://gudzpoz.github.io/luajava/
Other
122 stars 14 forks source link

Lua errors are "silent" #168

Closed Saturn745 closed 2 months ago

Saturn745 commented 2 months ago

Describe the bug All Lua errors/exceptions are "silent"

To Reproduce Steps to reproduce the behavior: Make any valid error such as calling a Java method without the right arguments, call a Java method which throws an exception, or a syntax error

Current behavior Nothing happens, no errors at all.

Expected behavior Some sort of error/exception on what went wrong (bad syntax, Java exception throw, etc)

Platform:

Additional context N/A

gudzpoz commented 2 months ago

Can you please provide more context? The following triggers Lua errors for me:

$ java -jar /tmp/example-all.jar -l 5.4
Running Lua 5.4
Use license() to print licensing info.
>>> S = java.import("java.lang.String")
>>> S(1)
no matching constructor found
>>> S():toString(1)
no matching method found
>>> ok = pcall(function() S():toString(1) end); print(ok)
false

If you are using the Java API, currently you will need to check the return value of functions like Lua#run for Lua errors, similar to lua_dostring in Lua C API.

But, yes, having to check the return value every time is rather bothersome. Probably a reworking of the API is needed for this.

Saturn745 commented 2 months ago

Yes I am using the Java API. Forgot to mention that.

Saturn745 commented 2 months ago

If you are using the Java API, currently you will need to check the return value of functions like Lua#run for Lua errors, similar to lua_dostring in Lua C API.

Thanks this pointed me in the right direction. I got it working now.