Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add LuaJ bindings #164

Merged
merged 12 commits into from
Apr 24, 2024
Merged

Add LuaJ bindings #164

merged 12 commits into from
Apr 24, 2024

Conversation

gudzpoz
Copy link
Owner

@gudzpoz gudzpoz commented Mar 29, 2024

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
Copy link

codecov-commenter commented Mar 29, 2024

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 ⚠️

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

Additional details and impacted files
@@             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     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@gudzpoz gudzpoz force-pushed the luaj-backend branch 3 times, most recently from 8c0fb97 to f7dcfae Compare March 29, 2024 10:47
@gudzpoz gudzpoz marked this pull request as ready for review April 17, 2024 08:35
@gudzpoz gudzpoz merged commit 7bd2822 into main Apr 24, 2024
14 checks passed
@gudzpoz gudzpoz deleted the luaj-backend branch April 27, 2024 08:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants