Skip to content

Commit 7cd08e9

Browse files
committed
chore: Lua5.5 basic support
1 parent 2f42d80 commit 7cd08e9

5 files changed

Lines changed: 185 additions & 2 deletions

File tree

c/lua52/src/main/c/luajava_lua52.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ JNIEXPORT jint JNICALL Java_org_eu_smileyik_luajava_LuaState__1rawlen(
3636
JNIEnv *env, jobject jobj, jobject cptr, jint idx) {
3737
lua_State *L = getStateFromCPtr(env, cptr);
3838
if (!L) return 0;
39-
lua_absindex;
4039
return (jint) lua_rawlen(L, idx);
4140
}
4241

c/lua55/build.gradle

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
plugins {
2+
id 'c'
3+
}
4+
5+
group = 'org.keplerproject'
6+
version = '1.0-SNAPSHOT'
7+
8+
def LUA_MAJOR_VERSION = "Lua55"
9+
def LUA_VERSION = "lua-5.5.0"
10+
def LUA_HOME = layout.buildDirectory.dir("$LUA_VERSION").getOrNull()
11+
def LUA_SRC = layout.buildDirectory.dir("$LUA_VERSION/src").getOrNull()
12+
13+
if (!layout.buildDirectory.asFile.get().exists()) {
14+
layout.buildDirectory.asFile.get().mkdir()
15+
}
16+
17+
repositories {
18+
mavenCentral()
19+
}
20+
21+
model {
22+
platforms {
23+
x86 {
24+
architecture "x86"
25+
}
26+
x64 {
27+
architecture "x86_64"
28+
}
29+
arm64 {
30+
architecture "aarch64"
31+
}
32+
}
33+
}
34+
35+
model {
36+
components {
37+
"$LUA_VERSION"(NativeLibrarySpec) {
38+
targetPlatform myTargetPlatform
39+
sources {
40+
c {
41+
exportedHeaders {
42+
srcDir "${LUA_SRC}"
43+
}
44+
}
45+
}
46+
}
47+
48+
"luajava4${LUA_MAJOR_VERSION}"(NativeLibrarySpec) {
49+
targetPlatform myTargetPlatform
50+
sources {
51+
c {
52+
lib library: "$LUA_VERSION", linkage: 'static'
53+
exportedHeaders {
54+
srcDir project(':c').layout.projectDirectory.dir('src/main/c')
55+
srcDir project(':c:lua52').layout.projectDirectory.dir('src/main/c')
56+
srcDir project(':c:lua53').layout.projectDirectory.dir('src/main/c')
57+
srcDir project(':c:lua54').layout.projectDirectory.dir('src/main/c')
58+
srcDir "src/main/c"
59+
srcDir "src/main/compatible"
60+
srcDir layout.buildDirectory.dir('headers')
61+
srcDir "${System.properties['java.home']}/include"
62+
srcDir "${System.properties['java.home']}/include/linux"
63+
srcDir "${System.properties['java.home']}/include/win32"
64+
srcDir "${System.properties['java.home']}/include/darwin"
65+
}
66+
source {
67+
srcDir project(':c').layout.projectDirectory.dir('src/main/c')
68+
srcDir project(':c:lua52').layout.projectDirectory.dir('src/main/c')
69+
srcDir project(':c:lua53').layout.projectDirectory.dir('src/main/c')
70+
srcDir "src/main/c"
71+
include "**/*.c"
72+
}
73+
}
74+
}
75+
76+
binaries.all {
77+
checkedBy $.tasks.buildLua
78+
checkedBy $.tasks.generateHeader
79+
80+
if (toolChain in VisualCpp) {
81+
cppCompiler.define 'WIN64'
82+
cppCompiler.define "LUAJAVA_VERSION", "\"$LUAJAVA_VERSION\""
83+
linker.args "lua.lib", "/LIBPATH:${LUA_SRC}"
84+
} else {
85+
cCompiler.define "LUAJAVA_VERSION", "\"$LUAJAVA_VERSION\""
86+
linker.args "-L${LUA_SRC}", '-llua', *additionLinkerArgs
87+
}
88+
}
89+
}
90+
}
91+
}
92+
93+
tasks.register('generateHeader') {
94+
group("luajava")
95+
generateCHeader(layout.buildDirectory.get())
96+
}
97+
98+
tasks.register("buildLua") {
99+
group("lua")
100+
downloadLua(LUA_VERSION, layout.buildDirectory.get())
101+
decompressLuaSource(LUA_VERSION, layout.buildDirectory.get(), LUA_HOME)
102+
doBuildLua(LUA_SRC)
103+
}
104+
105+
build {
106+
doLast {
107+
copyOutput(LUA_MAJOR_VERSION, LUA_VERSION, LUA_SRC)
108+
}
109+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/******************************************************************************
2+
* compatible_lua54.h, SmileYik, 2025-12-23
3+
* Copyright (c) 2025 Smile Yik
4+
*
5+
* Permission is hereby granted, free of charge, to any person obtaining a copy
6+
* of this software and associated documentation files (the "Software"), to deal
7+
* in the Software without restriction, including without limitation the rights
8+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
* copies of the Software, and to permit persons to whom the Software is
10+
* furnished to do so, subject to the following conditions:
11+
*
12+
* The above copyright notice and this permission notice shall be included in all
13+
* copies or substantial portions of the Software.
14+
*
15+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
* SOFTWARE.
22+
******************************************************************************/
23+
24+
#ifndef LUA_JAVA_COMPATIBLE_LUA54_HEADER
25+
#define LUA_JAVA_COMPATIBLE_LUA54_HEADER
26+
27+
#include "compatible_lua52.h"
28+
#include "compatible_lua53.h"
29+
#include "compatible_lua55.h"
30+
31+
#ifdef LUAJAVA_ENABLE_METHOD_RESUME_LUA_52
32+
#undef LUAJAVA_ENABLE_METHOD_RESUME_LUA_52
33+
#endif
34+
#define LUAJAVA_ENABLE_METHOD_RESUME_LUA_54
35+
36+
#endif // LUA_JAVA_COMPATIBLE_LUA54_HEADER
37+
38+
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/******************************************************************************
2+
* compatible.h, SmileYik, 2025-12-23
3+
* Copyright (c) 2025 Smile Yik
4+
*
5+
* Permission is hereby granted, free of charge, to any person obtaining a copy
6+
* of this software and associated documentation files (the "Software"), to deal
7+
* in the Software without restriction, including without limitation the rights
8+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
* copies of the Software, and to permit persons to whom the Software is
10+
* furnished to do so, subject to the following conditions:
11+
*
12+
* The above copyright notice and this permission notice shall be included in all
13+
* copies or substantial portions of the Software.
14+
*
15+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
* SOFTWARE.
22+
******************************************************************************/
23+
24+
#ifndef LUA_JAVA_COMPATIBLE_HEADER
25+
#define LUA_JAVA_COMPATIBLE_HEADER
26+
27+
#include "compatible_lua55.h"
28+
29+
#ifdef LUA_RIDX_GLOBALS
30+
#define LUAJAVA_LUA_RIDX_GLOBALS LUA_RIDX_GLOBALS
31+
#else
32+
#define LUAJAVA_LUA_RIDX_GLOBALS LUA_GLOBALSINDEX
33+
#endif
34+
35+
#endif // LUA_JAVA_COMPATIBLE_HEADER

settings.gradle

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,6 @@ findProject(':c:lua52')?.name = 'lua52'
88
include 'c:lua53'
99
findProject(':c:lua53')?.name = 'lua53'
1010
include 'c:lua54'
11-
findProject(':c:lua54')?.name = 'lua54'
11+
findProject(':c:lua54')?.name = 'lua54'
12+
include 'c:lua55'
13+
findProject(':c:lua55')?.name = 'lua55'

0 commit comments

Comments
 (0)