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

Add LuaJ bindings #164

Closed gudzpoz closed 2 months ago

gudzpoz commented 3 months ago

This PR adds LuaJ bindings to LuaJava, hopefully serving as a placeholder for platforms without binaries (or not yet supported by jnigen). For example, iOS users may use LuaJ bindings since they are pure Java.

There are several caveats though:

  1. A fork of LuaJ is used since the original one is unmaintained. However, the fork has yet to publish a Maven artifact, and before that, we need to use JitPack.
  2. LuaJ uses Java threads (heavyweight before Loom) for Lua coroutines (generally lightweight). It can become a problem if the user uses coroutines heavily.
  3. LuaJ does not provide Lua C API, upon which this library builds. A compatible layer is added, but there are several hidden behavioral changes in stack operations:

    When a LuaJ function is called, the library does not supply a lua_State-like pointer, which means we cannot possibly manipulate the stack from within the function. This is handled by tracking the thread that created the function / any value, while standard Lua operates on the current thread.

  4. Thanks JNI, we were able to call the default function defined by interfaces. However, in LuaJ, this is not possible any more: all we have access to is Java reflection API.
  5. LuaJ uses some classes that are introduced in Java 8 API but not available in lower Android API levels. We just don't test on those Android versions. (Having trouble setting up Android desugaring.)

These should have been documented in docs/?

codecov-commenter commented 3 months ago

Codecov Report

Attention: Patch coverage is 75.00000% with 1 lines in your changes are missing coverage. Please review.

Project coverage is 94.36%. Comparing base (c5ff946) to head (3982e58).

Files Patch % Lines
.../iroiro/luajava/jsr223/LuaScriptEngineFactory.java 0.00% 0 Missing and 1 partial :warning:

:exclamation: Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #164 +/- ## ============================================ - Coverage 94.43% 94.36% -0.07% Complexity 610 610 ============================================ Files 31 31 Lines 1455 1456 +1 Branches 184 184 ============================================ Hits 1374 1374 Misses 64 64 - Partials 17 18 +1 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.