Skip to content

Commit

Permalink
Merge pull request #193 from ccarrasc/lua-compat
Browse files Browse the repository at this point in the history
feat: enable LUA_COMPAT for Lua 5.2, 5.3, and 5.4
  • Loading branch information
gudzpoz authored Jul 12, 2024
2 parents 8d0e003 + 6f8aafd commit a0361df
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 0 deletions.
20 changes: 20 additions & 0 deletions example/suite/src/main/java/party/iroiro/luajava/LuaTestSuite.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ public void test() {
L.openLibraries();
LuaScriptSuite.addAssertThrows(L);
test64BitInteger();
testCompat();
testCoroutineDeadlock();
testDump();
testException();
Expand Down Expand Up @@ -117,6 +118,25 @@ private void testPCall() {
}
}

private void testCompat() {
L.run("return _VERSION");
String version = L.toString(-1);

switch (version) {
case "Lua 5.4": // LUA_COMPAT_5_3
case "Lua 5.3": // LUA_COMPAT_5_2
L.openLibrary("math");
L.run("return math.pow(2, 2)");
assertEquals(4, L.toInteger(-1));
break;
case "Lua 5.2": // LUA_COMPAT_ALL
L.openLibrary("math");
L.run("return math.log10(1)");
assertEquals(0, L.toInteger(-1));
break;
}
}

private void testCoroutineDeadlock() {
Thread t = new Thread(() -> {
try (T L = constructor.get()) {
Expand Down
2 changes: 2 additions & 0 deletions lua52/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ jnigen {
sharedLibName = 'lua52'

all {
cFlags += ' -DLUA_COMPAT_ALL'
cppFlags += ' -DLUA_COMPAT_ALL'
headerDirs = ['../../jni/luajava', 'mod', 'lua52']
cppExcludes = ['lua52/**/*']
cExcludes = ['lua52/**/*']
Expand Down
2 changes: 2 additions & 0 deletions lua53/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ jnigen {
sharedLibName = 'lua53'

all {
cFlags += ' -DLUA_COMPAT_5_2'
cppFlags += ' -DLUA_COMPAT_5_2'
headerDirs = ['../../jni/luajava', 'mod', 'lua53']
cppExcludes = ['lua53/**/*']
cExcludes = ['lua53/**/*']
Expand Down
2 changes: 2 additions & 0 deletions lua54/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ jnigen {
sharedLibName = 'lua54'

all {
cFlags += ' -DLUA_COMPAT_5_3'
cppFlags += ' -DLUA_COMPAT_5_3'
headerDirs = ['../../jni/luajava', 'mod', 'lua54']
cppExcludes = ['lua54/**/*']
cExcludes = ['lua54/**/*']
Expand Down

0 comments on commit a0361df

Please sign in to comment.