diff --git a/build.gradle b/build.gradle
index ee88c213..6f87a894 100644
--- a/build.gradle
+++ b/build.gradle
@@ -1,5 +1,5 @@
group 'party.iroiro.luajava'
-version (System.getenv('IS_RELEASE') == 'true' ? '3.1.2' : '3.1.2-SNAPSHOT')
+version(System.getenv('IS_RELEASE') == 'true' ? '3.1.3' : '3.1.3-SNAPSHOT')
buildscript {
repositories {
@@ -41,14 +41,22 @@ apply from: 'publish.gradle'
apply from: 'jacoco.gradle'
task allJavadoc(type: Javadoc) {
- source subprojects.findAll { !['example', 'android', 'android-test'].contains(it.name) }
- .collect {
- it.sourceSets.main.allJava
- }
- classpath = files(subprojects.findAll { !['example', 'android', 'android-test'].contains(it.name) }
- .collect {
- it.sourceSets.main.compileClasspath
- })
- exclude '**/party/iroiro/luajava/util/**'
+ Set
+ * See
+ * See
+ * See
+ * See
+ * See
+ * See
+ * See
+ * See
+ * See
+ * See
+ * See
+ * See lua_dump
+ * lua_State*
pointer
+ * @return see description
+ */
+ protected native Object luaJ_dumptobuffer(long ptr); /*
+ lua_State * L = (lua_State *) ptr;
+
+ jobject returnValueReceiver = (jobject) luaJ_dumptobuffer((lua_State *) L);
+ return returnValueReceiver;
+ */
+
+
+ /**
+ * A wrapper function
+ *
+ * lua_tolstring
+ * lua_State*
pointer
+ * @param index the stack position of the element
+ * @return see description
+ */
+ protected native Object luaJ_tobuffer(long ptr, int index); /*
+ lua_State * L = (lua_State *) ptr;
+
+ jobject returnValueReceiver = (jobject) luaJ_tobuffer((lua_State *) L, (int) index);
+ return returnValueReceiver;
+ */
+
+
+ /**
+ * A wrapper function
+ *
+ * lua_tolstring
+ * lua_State*
pointer
+ * @param index the stack position of the element
+ * @return see description
+ */
+ protected native Object luaJ_todirectbuffer(long ptr, int index); /*
+ lua_State * L = (lua_State *) ptr;
+
+ jobject returnValueReceiver = (jobject) luaJ_todirectbuffer((lua_State *) L, (int) index);
+ return returnValueReceiver;
+ */
+
+
}
\ No newline at end of file
diff --git a/lua52/jni/mod/luacomp.h b/lua52/jni/mod/luacomp.h
index b876994d..5f857bb0 100644
--- a/lua52/jni/mod/luacomp.h
+++ b/lua52/jni/mod/luacomp.h
@@ -70,4 +70,8 @@ static int luaJ_initloader(lua_State * L) {
return luaJ_insertloader(L, "searchers");
}
+static int luaJ_dump (lua_State *L, lua_Writer writer, void *data) {
+ return lua_dump (L, writer, data);
+}
+
#endif /* !LUACOMP_H */
diff --git a/lua52/src/main/java/party/iroiro/luajava/Lua52Natives.java b/lua52/src/main/java/party/iroiro/luajava/Lua52Natives.java
index 2798ee53..d88e4696 100644
--- a/lua52/src/main/java/party/iroiro/luajava/Lua52Natives.java
+++ b/lua52/src/main/java/party/iroiro/luajava/Lua52Natives.java
@@ -4502,4 +4502,60 @@ protected Lua52Natives() throws IllegalStateException {
*/
+ /**
+ * A wrapper function
+ *
+ * lua_dump
+ * lua_State*
pointer
+ * @return see description
+ */
+ protected native Object luaJ_dumptobuffer(long ptr); /*
+ lua_State * L = (lua_State *) ptr;
+
+ jobject returnValueReceiver = (jobject) luaJ_dumptobuffer((lua_State *) L);
+ return returnValueReceiver;
+ */
+
+
+ /**
+ * A wrapper function
+ *
+ * lua_tolstring
+ * lua_State*
pointer
+ * @param index the stack position of the element
+ * @return see description
+ */
+ protected native Object luaJ_tobuffer(long ptr, int index); /*
+ lua_State * L = (lua_State *) ptr;
+
+ jobject returnValueReceiver = (jobject) luaJ_tobuffer((lua_State *) L, (int) index);
+ return returnValueReceiver;
+ */
+
+
+ /**
+ * A wrapper function
+ *
+ * lua_tolstring
+ * lua_State*
pointer
+ * @param index the stack position of the element
+ * @return see description
+ */
+ protected native Object luaJ_todirectbuffer(long ptr, int index); /*
+ lua_State * L = (lua_State *) ptr;
+
+ jobject returnValueReceiver = (jobject) luaJ_todirectbuffer((lua_State *) L, (int) index);
+ return returnValueReceiver;
+ */
+
+
}
\ No newline at end of file
diff --git a/lua53/jni/mod/luacomp.h b/lua53/jni/mod/luacomp.h
index b876994d..6734f23a 100644
--- a/lua53/jni/mod/luacomp.h
+++ b/lua53/jni/mod/luacomp.h
@@ -70,4 +70,8 @@ static int luaJ_initloader(lua_State * L) {
return luaJ_insertloader(L, "searchers");
}
+static int luaJ_dump (lua_State *L, lua_Writer writer, void *data) {
+ return lua_dump (L, writer, data, true);
+}
+
#endif /* !LUACOMP_H */
diff --git a/lua53/src/main/java/party/iroiro/luajava/Lua53Natives.java b/lua53/src/main/java/party/iroiro/luajava/Lua53Natives.java
index 47c01941..1815a7fa 100644
--- a/lua53/src/main/java/party/iroiro/luajava/Lua53Natives.java
+++ b/lua53/src/main/java/party/iroiro/luajava/Lua53Natives.java
@@ -4679,4 +4679,60 @@ protected Lua53Natives() throws IllegalStateException {
*/
+ /**
+ * A wrapper function
+ *
+ * lua_dump
+ * lua_State*
pointer
+ * @return see description
+ */
+ protected native Object luaJ_dumptobuffer(long ptr); /*
+ lua_State * L = (lua_State *) ptr;
+
+ jobject returnValueReceiver = (jobject) luaJ_dumptobuffer((lua_State *) L);
+ return returnValueReceiver;
+ */
+
+
+ /**
+ * A wrapper function
+ *
+ * lua_tolstring
+ * lua_State*
pointer
+ * @param index the stack position of the element
+ * @return see description
+ */
+ protected native Object luaJ_tobuffer(long ptr, int index); /*
+ lua_State * L = (lua_State *) ptr;
+
+ jobject returnValueReceiver = (jobject) luaJ_tobuffer((lua_State *) L, (int) index);
+ return returnValueReceiver;
+ */
+
+
+ /**
+ * A wrapper function
+ *
+ * lua_tolstring
+ * lua_State*
pointer
+ * @param index the stack position of the element
+ * @return see description
+ */
+ protected native Object luaJ_todirectbuffer(long ptr, int index); /*
+ lua_State * L = (lua_State *) ptr;
+
+ jobject returnValueReceiver = (jobject) luaJ_todirectbuffer((lua_State *) L, (int) index);
+ return returnValueReceiver;
+ */
+
+
}
\ No newline at end of file
diff --git a/lua54/jni/mod/luacomp.h b/lua54/jni/mod/luacomp.h
index 38898ff6..cc1c1176 100644
--- a/lua54/jni/mod/luacomp.h
+++ b/lua54/jni/mod/luacomp.h
@@ -71,4 +71,8 @@ static int luaJ_initloader(lua_State * L) {
return luaJ_insertloader(L, "searchers");
}
+static int luaJ_dump (lua_State *L, lua_Writer writer, void *data) {
+ return lua_dump (L, writer, data, true);
+}
+
#endif /* !LUACOMP_H */
diff --git a/lua54/src/main/java/party/iroiro/luajava/Lua54Natives.java b/lua54/src/main/java/party/iroiro/luajava/Lua54Natives.java
index c05a29f2..aa5e4f2a 100644
--- a/lua54/src/main/java/party/iroiro/luajava/Lua54Natives.java
+++ b/lua54/src/main/java/party/iroiro/luajava/Lua54Natives.java
@@ -4736,4 +4736,60 @@ protected Lua54Natives() throws IllegalStateException {
*/
+ /**
+ * A wrapper function
+ *
+ * lua_dump
+ * lua_State*
pointer
+ * @return see description
+ */
+ protected native Object luaJ_dumptobuffer(long ptr); /*
+ lua_State * L = (lua_State *) ptr;
+
+ jobject returnValueReceiver = (jobject) luaJ_dumptobuffer((lua_State *) L);
+ return returnValueReceiver;
+ */
+
+
+ /**
+ * A wrapper function
+ *
+ * lua_tolstring
+ * lua_State*
pointer
+ * @param index the stack position of the element
+ * @return see description
+ */
+ protected native Object luaJ_tobuffer(long ptr, int index); /*
+ lua_State * L = (lua_State *) ptr;
+
+ jobject returnValueReceiver = (jobject) luaJ_tobuffer((lua_State *) L, (int) index);
+ return returnValueReceiver;
+ */
+
+
+ /**
+ * A wrapper function
+ *
+ * lua_tolstring
+ * lua_State*
pointer
+ * @param index the stack position of the element
+ * @return see description
+ */
+ protected native Object luaJ_todirectbuffer(long ptr, int index); /*
+ lua_State * L = (lua_State *) ptr;
+
+ jobject returnValueReceiver = (jobject) luaJ_todirectbuffer((lua_State *) L, (int) index);
+ return returnValueReceiver;
+ */
+
+
}
\ No newline at end of file
diff --git a/luajava/build.gradle b/luajava/build.gradle
index c33e706d..5711c7e6 100644
--- a/luajava/build.gradle
+++ b/luajava/build.gradle
@@ -13,7 +13,7 @@ version = rootProject.version
dependencies {
implementation 'com.badlogicgames.gdx:gdx-jnigen-loader:2.3.1'
- implementation 'com.google.errorprone:error_prone_annotations:2.14.0'
+ implementation 'com.google.errorprone:error_prone_annotations:2.15.0'
implementation 'org.jetbrains:annotations:23.0.0'
}
diff --git a/luajava/src/main/java/party/iroiro/luajava/AbstractLua.java b/luajava/src/main/java/party/iroiro/luajava/AbstractLua.java
index 9ec781a6..79baf6b1 100644
--- a/luajava/src/main/java/party/iroiro/luajava/AbstractLua.java
+++ b/luajava/src/main/java/party/iroiro/luajava/AbstractLua.java
@@ -37,6 +37,7 @@
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import java.nio.Buffer;
+import java.nio.ByteBuffer;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
@@ -350,6 +351,21 @@ public boolean toBoolean(int index) {
return C.lua_tostring(L, index);
}
+ @Override
+ public @Nullable ByteBuffer toBuffer(int index) {
+ return (ByteBuffer) C.luaJ_tobuffer(L, index);
+ }
+
+ @Override
+ public @Nullable ByteBuffer toDirectBuffer(int index) {
+ ByteBuffer buffer = (ByteBuffer) C.luaJ_todirectbuffer(L, index);
+ if (buffer == null) {
+ return null;
+ } else {
+ return buffer.asReadOnlyBuffer();
+ }
+ }
+
@Override
public @Nullable Object toJavaObject(int index) {
return C.luaJ_toobject(L, index);
@@ -563,6 +579,11 @@ public LuaError run(Buffer buffer, String name) {
}
}
+ @Override
+ public ByteBuffer dump() {
+ return (ByteBuffer) C.luaJ_dumptobuffer(L);
+ }
+
@Override
public LuaError pCall(int nArgs, int nResults) {
checkStack(Math.max(nResults - nArgs - 1, 0));
diff --git a/luajava/src/main/java/party/iroiro/luajava/JuaAPI.java b/luajava/src/main/java/party/iroiro/luajava/JuaAPI.java
index f78c6e61..bde25af2 100644
--- a/luajava/src/main/java/party/iroiro/luajava/JuaAPI.java
+++ b/luajava/src/main/java/party/iroiro/luajava/JuaAPI.java
@@ -28,6 +28,7 @@
import party.iroiro.luajava.value.LuaValue;
import java.lang.reflect.*;
+import java.nio.ByteBuffer;
import java.util.*;
import java.util.regex.Pattern;
@@ -38,6 +39,17 @@
*
+ * You may want to use this instead of {@link #toString(int)} when the string is binary + * (e.g., those returned by {@code string.dump} and contains null characters). + *
+ * + * @param index the stack index + * @return the created buffer + */ + @Nullable ByteBuffer toBuffer(int index); + + /** + * Creates a read-only direct {@link java.nio.ByteBuffer} from the string at the specific index + * + *+ * The memory of this buffer is managed by Lua. + * So you should never use the buffer after poping the corresponding value + * from the Lua stack. + *
+ * + * @param index the stack index + * @return the created read-only buffer + */ + @Nullable ByteBuffer toDirectBuffer(int index); + /** * Get the element at the specified stack position, if the element is a Java object / array / class * @@ -580,6 +608,20 @@ public interface Lua extends AutoCloseable { */ LuaError run(Buffer buffer, String name); + /** + * Dumps a function as a binary chunk + * + *+ * Receives a Lua function on the top of the stack + * and produces a binary chunk that, + * if loaded again, results in a function equivalent to the one dumped. + *
+ * + * @return the binary chunk, null if an error occurred + */ + @Nullable + ByteBuffer dump(); + /** * Calls a function in protected mode * diff --git a/luajava/src/main/java/party/iroiro/luajava/LuaNative.java b/luajava/src/main/java/party/iroiro/luajava/LuaNative.java index 2eebfb01..3e310ddf 100644 --- a/luajava/src/main/java/party/iroiro/luajava/LuaNative.java +++ b/luajava/src/main/java/party/iroiro/luajava/LuaNative.java @@ -1281,6 +1281,71 @@ public abstract class LuaNative { */ protected abstract long lua_touserdata(long ptr, int index); + /** + * Wrapper oflua_dump
+ *
+ *
+ * [-0, +0, m]
+ *
+ *
+ *
+ * int lua_dump (lua_State *L, lua_Writer writer, void *data);
+ *
+ *
+ *
+ * Dumps a function as a binary chunk.
+ * Receives a Lua function on the top of the stack
+ * and produces a binary chunk that,
+ * if loaded again, results in a function equivalent to the one dumped.
+ * As it produces parts of the chunk,
+ * lua_dump
+ * calls function writer (see lua_Writer
)
+ * with the given data to write them.
+ *
+ * The value returned is the error code returned by the last call to the writer; + * 0 means no errors. + *
+ * + *+ * This function does not pop the Lua function from the stack. + *
+ * + * @param ptr thelua_State*
pointer
+ * @return a nullable {@link java.nio.ByteBuffer} containing the dumped binary
+ */
+ protected abstract Object luaJ_dumptobuffer(long ptr);
+
+ /**
+ * Creates a {@link java.nio.ByteBuffer} from the string at the specific index
+ *
+ * + * This method copies the content of the string into a buffer managed by Java, + * and you are safe to pop the string from Lua stack. + *
+ * + * @param ptr thelua_State*
pointer
+ * @param index the stack position of the element
+ * @return a nullable {@link java.nio.ByteBuffer} containing the string
+ */
+ protected abstract Object luaJ_tobuffer(long ptr, int index);
+
+ /**
+ * Creates a direct {@link java.nio.ByteBuffer} backed by the string at the stack index
+ *
+ * + * This method creates a buffer that directly accesses the memory managed by Lua. + * You are not expected to modify the content of the buffer, + * and the buffer will become invalid after the string. + *
+ * + * @param ptr thelua_State*
pointer
+ * @param index the stack position of the element
+ * @return a nullable {@link java.nio.ByteBuffer} containing the string
+ */
+ protected abstract Object luaJ_todirectbuffer(long ptr, int index);
+
/**
* A wrapper function
*
diff --git a/luajit/jni/mod/luacomp.h b/luajit/jni/mod/luacomp.h
index 66f7e2a2..00767359 100644
--- a/luajit/jni/mod/luacomp.h
+++ b/luajit/jni/mod/luacomp.h
@@ -70,4 +70,8 @@ static int luaJ_initloader(lua_State * L) {
return luaJ_insertloader(L, "loaders");
}
+static int luaJ_dump (lua_State *L, lua_Writer writer, void *data) {
+ return lua_dump (L, writer, data);
+}
+
#endif /* !LUACOMP_H */
\ No newline at end of file
diff --git a/luajit/src/main/java/party/iroiro/luajava/LuaJitNatives.java b/luajit/src/main/java/party/iroiro/luajava/LuaJitNatives.java
index e6a2c1ac..f58374a6 100644
--- a/luajit/src/main/java/party/iroiro/luajava/LuaJitNatives.java
+++ b/luajit/src/main/java/party/iroiro/luajava/LuaJitNatives.java
@@ -3696,9 +3696,65 @@ protected LuaJitNatives() throws IllegalStateException {
*/
protected native void luaJ_gc(long ptr); /*
lua_State * L = (lua_State *) ptr;
-
+
luaJ_gc((lua_State *) L);
*/
+ /**
+ * A wrapper function
+ *
+ *
+ * See lua_dump
+ *
lua_State*
pointer
+ * @return see description
+ */
+ protected native Object luaJ_dumptobuffer(long ptr); /*
+ lua_State * L = (lua_State *) ptr;
+
+ jobject returnValueReceiver = (jobject) luaJ_dumptobuffer((lua_State *) L);
+ return returnValueReceiver;
+ */
+
+
+ /**
+ * A wrapper function
+ *
+ *
+ * See lua_tolstring
+ *
lua_State*
pointer
+ * @param index the stack position of the element
+ * @return see description
+ */
+ protected native Object luaJ_tobuffer(long ptr, int index); /*
+ lua_State * L = (lua_State *) ptr;
+
+ jobject returnValueReceiver = (jobject) luaJ_tobuffer((lua_State *) L, (int) index);
+ return returnValueReceiver;
+ */
+
+
+ /**
+ * A wrapper function
+ *
+ *
+ * See lua_tolstring
+ *
lua_State*
pointer
+ * @param index the stack position of the element
+ * @return see description
+ */
+ protected native Object luaJ_todirectbuffer(long ptr, int index); /*
+ lua_State * L = (lua_State *) ptr;
+
+ jobject returnValueReceiver = (jobject) luaJ_todirectbuffer((lua_State *) L, (int) index);
+ return returnValueReceiver;
+ */
+
+
}
\ No newline at end of file
diff --git a/scripts/comm-abstract.py b/scripts/comm-abstract.py
index 6caf75a1..019668dd 100644
--- a/scripts/comm-abstract.py
+++ b/scripts/comm-abstract.py
@@ -1,7 +1,6 @@
#!/bin/python
-# python scripts/comm-abstract.py \
-# lua*/src/main/java/party/iroiro/luajava/*Natives*
+# python scripts/comm-abstract.py lua*/src/main/java/party/iroiro/luajava/*Natives*
import sys
import re
diff --git a/scripts/comm-abstract.sh b/scripts/comm-abstract.sh
deleted file mode 100644
index bb1783ce..00000000
--- a/scripts/comm-abstract.sh
+++ /dev/null
@@ -1,21 +0,0 @@
-#!/bin/bash
-
-# bash jni/scripts/comm-abstract.sh > src/main/java/party/iroiro/jua/LuaNative.java
-
-COMM12=`comm -12 <(grep '^ protected' lua51/src/main/java/party/iroiro/jua/Lua51Natives.java| sort) <(grep '^ protected' lua52/src/main/java/party/iroiro/jua/Lua52Natives.java| sort)`
-COMM123=`comm -12 <(echo "$COMM12") <(grep '^ protected' lua53/src/main/java/party/iroiro/jua/Lua53Natives.java| sort)`
-COMM1234=`comm -12 <(echo "$COMM123") <(grep '^ protected' lua54/src/main/java/party/iroiro/jua/Lua54Natives.java| sort)`
-echo "package party.iroiro.jua;"
-echo
-echo "import java.nio.Buffer;"
-echo
-echo "/**"
-echo " * Generated from the common parts of Lua5.[1..4]
"
-echo " */"
-echo '@SuppressWarnings("unused")'
-echo "public abstract class LuaNative {"
-echo
-echo "$COMM1234" | sed -e 's/native/abstract/' -e 's# /\*#\n#'
-# Param name differs
-echo " protected abstract void lua_rawseti(long ptr, int index, int i);"
-echo "}"
diff --git a/scripts/jnigen-lua.html b/scripts/jnigen-lua.html
deleted file mode 100644
index 3c47d7d2..00000000
--- a/scripts/jnigen-lua.html
+++ /dev/null
@@ -1,96 +0,0 @@
-
-
-
-
-
-
- lua_dump
',
+ 'signature': {
+ 'return': 'jobject',
+ 'params': [
+ ['lua_State *', 'L'],
+ ],
+ },
+ })
+ functions.append({
+ 'name': 'luaJ_tobuffer',
+ 'description': 'See lua_tolstring
',
+ 'signature': {
+ 'return': 'jobject',
+ 'params': [
+ ['lua_State *', 'L'],
+ ['int', 'index'],
+ ],
+ },
+ })
+ functions.append({
+ 'name': 'luaJ_todirectbuffer',
+ 'description': 'See lua_tolstring
',
+ 'signature': {
+ 'return': 'jobject',
+ 'params': [
+ ['lua_State *', 'L'],
+ ['int', 'index'],
+ ],
+ },
+ })
def getWhole(luaVersion, package):