yippeesoft / jnlua Goto Github PK
View Code? Open in Web Editor NEWAutomatically exported from code.google.com/p/jnlua
Automatically exported from code.google.com/p/jnlua
Convert the documentation from Confluence wiki markup to Google Code
Original issue reported on code.google.com by [email protected]
on 8 May 2011 at 3:55
In have found a mistake in the code of JNLua 1.0.3, thanks to FindBug.
Class: com.naef.jnlua.DefaultJavaReflector.java line: 441.
if (!luaState.isJavaObject(3, componentType)) {
throw new LuaRuntimeException(
String.format(
"attempt to write array of %s at index %d with %s value",
componentType.getCanonicalName(),
luaState.typeName(3)));
}
The format string have two %s and one %d, but only two string are passed in
parametter.
The missing parameter is the value of the index '3' as follow:
if (!luaState.isJavaObject(3, componentType)) {
throw new LuaRuntimeException(
String.format(
"attempt to write array of %s at index %d with %s value",
componentType.getCanonicalName(), 3,
luaState.typeName(3)));
}
Marc
Original issue reported on code.google.com by [email protected]
on 11 Feb 2013 at 3:44
For the lua code below:
javavm = require("javavm")
javavm.create("-Djava.class.path=jnlua-0.9.6.jar;osql.jar")
db = java.require("com.asql.core.DBConnection")
It will raise java.lang.ClassNotFoundException in 3rd line.
I've tried using URLClassLoader but it doesn't work. The available way is to
copy all files in osql.jar into jnlua-0.9.6.jar.
The following examples would work fine, in this case, the DriverManger would
indirectly refer to the drivers that defined in "ojdbc6.jar"
javavm = require("javavm")
javavm.create("-Djava.class.path=jnlua-1.0.2.jar;ojdbc6.jar")
driver = java.require("java.sql.DriverManager")
conn=driver:getConnection("jdbc:oracle:thin:@//localhost:1521/orcl","usr","pwd")
Original issue reported on code.google.com by [email protected]
on 24 Mar 2014 at 3:02
if I run this in the lua-commandline:
System = java.require("java.lang.System")
I get this error:
stdin:1: attempt to index global `java' (a nil value)
stack traceback:
stdin:1: in main chunk
[C]: ?
Where is the Java Module?
greeting pitti
Original issue reported on code.google.com by [email protected]
on 13 Dec 2013 at 1:43
What steps will reproduce the problem?
1. Try to build on CentOS (libjnlua.so)
What is the expected output? What do you see instead?
a compiled .so file
What version of the product are you using? On what operating system?
1.0.3
Please provide any additional information below.
completely unable to build upon CentOS 6.3. lua-devel is installed, java-jdk is
installed and all includes are found but gcc refuses to accept the code far to
many errors.
Any recommendation on how to get the native files to build would be helpful.
Original issue reported on code.google.com by [email protected]
on 22 Apr 2013 at 10:29
What steps will reproduce the problem?
1. I've followed the Getting started guide.
2. I tried to load the java module in lua with the JavaVMModule guide
3. I made a lua script with the following code:
package.cpath =
package.cpath..";./?.dll;./?.so;../lib/?.so;../lib/vc_dll/?.dll;../lib/bcc_dll/?
.dll;../lib/mingw_dll/?.dll;"
javavm = require("javavm")
javavm.create("-Djava.class.path=jnlua-0.9.5.jar")
Please note that jnlua5.1.dll, javavm.dll and jvm.dll(from jdk6) in the
package.cpath.
What is the expected output? What do you see instead?
Then I get a runtime error and the lua interpreter simply crash instead of
working just fine.
The crash happen when I try to create the java vm with the jnlua-version.jar
What version of the product are you using? On what operating system?
I'm using lua 5.1 with Windows 7 with jnlua-0.9.5
Please provide any additional information below.
The PATH was correctly setted and I followed the instruction.
Original issue reported on code.google.com by antogerva
on 18 Apr 2013 at 10:24
Using JNLua interpreter version 0.9.6 from java I got a segmentation fault.
Only under Linux 32bit.
Code to reproduce the bug:
<code>
import com.naef.jnlua.LuaState;
public class Main {
public static void main(String[] args){
System.out.println("Start");
String luaSource = "local source, line = string.rep(\"a\\n\",4500), 2 "
+ "print('string find') io.flush()"
+ "string.find(source,string.rep('[^\\n]*\\n',line))"
+ "print('string find OK')io.flush()";
System.loadLibrary("lua5.1");
LuaState state = new LuaState();
state.openLibs();
state.load(luaSource, "sample");
state.call(0, 0);
System.out.println("END");
}
}
</code>
The expected output is :
Start
string find
string find OK
END
but got:
Start
string find
Because the lua line "string.find(source,string.rep('[^\\n]*\\n',line))" crash
the JVM.
It's can be due to the size of string manipulated, because when changing the
value of the lua variable "line" to 2 instead of 4300 doesn't crash the JVM
anymore.
See attached dll used.
Original issue reported on code.google.com by [email protected]
on 13 Dec 2013 at 10:29
Attachments:
modify this method in DefaultJavaReflector
private Method getPublicSuperclassMethod(Class<?> clazz, String methodName,
Class<?>[] parameterTypes) {
Class<?> superclass = clazz.getSuperclass();
while (superclass != null) {
// Ignore non-public superclasses
// if (!Modifier.isPublic(superclass.getModifiers())) {
// continue;
// }
// zhangzhenjiang
if (!Modifier.isPublic(superclass.getModifiers())) {
return null;
}
Original issue reported on code.google.com by [email protected]
on 2 Dec 2012 at 11:13
I had the requirement to limit Lua VMs to a maximum memory usage for better
sandboxing. This is actually pretty easy thanks to Lua offering a way to supply
a custom allocator. I extended JNLua a bit to offer seamless support for this:
- Added a new constructor that takes the initially allowed maximum memory. If
this constructor is used instead of the default one, the custom allocator will
be used. If not, the default allocator will be used, so there's no impact on
performance in that case.
- Added getter and setter for allowed maximum memory:
getTotalMemory/setTotalMemory. This value can be changed at any time for an
existing Lua VM that was created with the new constructor. Due to the allocator
being decided upon VM creation this cannot be enabled afterwards.
- Added a getter for current memory consumption: getFreeMemory. This is the
exact remaining number of bytes the allocator may still use.
Keep in mind that the native library compiled with this patch will only work
with the patched LuaState class, since the native library accesses the new
fields in the LuaState class: using an older implementation will crash (field
not found). I quickly scrolled through jni.h but didn't see anything that
allows checking for the existence of a field without throwing an error.
The attached patch is for release 0.9.6. I'm sure it will be very simple to
port this to the 1.x branch, but I just don't need it so I won't.
I'm providing this patch no strings attached, use it as you see fit. Ideally
I'd hope for this to get integrated into the repository, so I don't have to
patch it whenever there's a new version - I tried to match the existing code
style as closely as possible.
Final disclaimer: I only tested this on Windows, but I don't see why it
wouldn't work on other systems (there's no platform specific code in the patch).
Original issue reported on code.google.com by fnuecke
on 19 Aug 2013 at 9:15
Attachments:
If I declare in the java code as static method
public static int getMessageIdByName(String name) {
return messageIdMap.get(name);
}
and try to call it in lua
Core:getManager():getMessageIdByName("DRAW")
I get an error:
null:17: com.naef.jnlua.LuaRuntimeException: no method of class
org.gram.engine.manager.Manager matches 'getMessageIdByName(string)'
but if it works to remove static
What version of the product are you using? On what operating system?
version - JNLua 1.04
OS - Windows 7
Original issue reported on code.google.com by [email protected]
on 26 Mar 2014 at 8:29
I am currenlty trying to compile JNLua 1.0.3 C native code. The goal is to
provide a shipped interpreter for LDT (http://eclipse.org/koneki/ldt/).
Dowloaded dll for windows works fine, under linux the compilation work fine
aswell. But on MacOs X, I have a major issue to compile the jnlua lib.
Using GCC, I have the followings errors :
gcc -c -fno-strict-aliasing -m64 -fPIC -O2 -Wall -DNDEBUG -D_REENTRANT
-DLUA_USE_LINUX
-I/Developer//SDKs/MacOSX10.6.sdk/System/Library/Frameworks/JavaVM.framework/Ver
sions/1.6.0/Headers -I/tmp/lua-5.2.1/src/ ../jnlua.c
../jnlua.c:133: error: thread-local storage not supported for this target
Some explanation can be find here:
http://lists.apple.com/archives/xcode-users/2006/Jun/msg00550.html
It seems that MacOs doesn't support thread-local storage, maybe jnlua have to
use a different way to store thread variables.
Marc
Original issue reported on code.google.com by [email protected]
on 11 Feb 2013 at 5:53
What steps will reproduce the problem?
Just do as GettingStarted
What is the expected output? What do you see instead?
The LuaConsole does not run at all
What version of the product are you using? On what operating system?
0.9.4 Windows-xp
Please provide any additional information below.
Original issue reported on code.google.com by [email protected]
on 26 Aug 2012 at 8:34
Attachments:
Hello,
I just started using JNLua in my Java project (Lua in general for that matter).
Basically, I am calling into Lua scripts to run some functions from my Java
code. Everything works great, but the problems I am having are more related to
the debug environment.
I have been trying to setup my debug environment by attaching to the running
Java process. (I am currently using Eclipse/LDT 1.0.1). The issue I have been
having is that my breakpoints are never hit. It appears the reason for this is
how I am loading the Lua script file from Java (using lua_load()):
import com.naef.jnlua.LuaState;
...
luaState.openLibs();
luaState.load(
Gdx.files.internal(scriptFileName).read(), //read() returns InputStream
Gdx.files.internal(scriptFileName).file().getName(), //getName() returns filename, "atm.lua"
"bt"); //read as binary or text
// Evaluate the chunk, thus defining the function
luaState.call(0, 0); // No arguments, no returns
...
Then when called later:
...
luaState.getGlobal("create");
luaState.pushJavaObject(entity); // Push argument #1
luaState.call(1, 0); // 1 argument, 0 return
...
In looking through the Eclipse Koneki forums, it appears that Lua files loaded
using lua_load() are considered "dynamic code" which was defined in the
documentation as code "compiled with load or loadstring and is not handled (the
debugger will step over it, like C code)"
There was one little excerpt in the forum that caught my attention in how the
developer solved his problem:
"To use an embedded script you need to load it in the style of luaL_loadfile,
pushing the filename onto the stack first with lua_pushfstring(L, "@%s",
filename); and removing it after calling luaL_loadbuffer."
I looked through the JNI bridge source (jnlua.c) and did not see any of these
functions available.
My question is whether exposing lua_pushfstring() and luaL_loadbuffer() even
works within the model of JNLua, and if so, could this be added as a feature
request? If this doesn't fit within the design of JNLua, are there any
alternatives to using lua_load() for files?
Any help would be appreciated.
Original issue reported on code.google.com by [email protected]
on 10 Dec 2013 at 9:49
What steps will reproduce the problem?
1. Run unit tests with -Xcheck:jni.
What is the expected output? What do you see instead?
Expected: no warnings.
Observed: A bunch of "WARNING in native method: JNI call made with exception
pending" log entries.
What version of the product are you using? On what operating system?
JNLua 1.0.4, Java 1.7.0_55, Windows 8.1.
Please provide any additional information below.
See [1] for a list of methods that may be called with pending exceptions. In
particular, SetLongField (indirectly) called from [2] and NewObject called from
[3] are not in that list. However, they are called in case of exceptions before
the exception is cleared with ExceptionClear [4]. Some reordering of these
calls (ExceptionClear as the first statement in the if branch, setluathread
after it and in the (new) else branch) avoids these warnings.
Note: since they are only warnings I am not quite sure if/how they influence
program logic.
[1] http://developer.android.com/training/articles/perf-jni.html#exceptions
[2]
https://code.google.com/p/jnlua/source/browse/trunk/jnlua/src/main/c/jnlua.c#217
8
[3]
https://code.google.com/p/jnlua/source/browse/trunk/jnlua/src/main/c/jnlua.c#218
7
[4]
https://code.google.com/p/jnlua/source/browse/trunk/jnlua/src/main/c/jnlua.c#219
3
Original issue reported on code.google.com by fnuecke
on 20 Aug 2014 at 12:18
When sending data between Lua and C using the Lua C API, there are two sets of
methods for moving character data, the "string" methods and the "lstring"
methods. Below is the list of lua_ and luaL_ methods that deal with "strings"
and provide both versions:
lua_pushstring / lua_pushlstring
lua_tostring / lua_tolstring
luaL_addstring / luaL_addlstring
luaL_checkstring / luaL_checklstring
luaL_optstring / luaL_optlstring
In all cases, the "string" value is referenced on the C side as a "const char
*". On the Lua side, a "string" is defined and implemented as follows:
"Strings have the usual meaning: a sequence of characters. Lua is eight-bit
clean and so strings may contain characters with any numeric value, including
embedded zeros. That means that you can store any binary data into a string."
So Lua strings exchanged with C code may be either "text" or "binary", with the
determination being made by contract between the Lua and C code. The fact that
the Lua strings may be text or binary is precisely why the lstring functions
exist.
For example, lets say that you implement an HTTP request API in C as a Lua
extension. When Lua calls that API to upload a file, it needs to pass a binary
request body, say by loading an image file into a Lua string and passing that
string to the C API. Since the C API is expecting binary content in the Lua
string, it uses the lstring functions, probably lua_tolstring, to access the
data, and processes the resulting char array as binary bytes. On an HTTP image
download, the C API would to exactly the reverse, pushing the binary content
onto the Lua stack using push_lstring, and the Lua code would then receive a
Lua string with the binary content.
Unfortunately, the LuaState string APIs supplied by jnlua do not implement the
lstring methods (though they do call them internally in the JNI bridge). The
jnlua string support methods are as follows:
String checkString( int index )
void pushString( String s )
String toString( int index )
All of those methods move data between Lua strings and Java as UTF8 encoded
text (so they assume that the Lua string is or should be UTF8 encoded text, and
encode/decode such that the Java side representation is a Java String). As far
as I can tell, there is no way to move binary data between a Lua string and
Java using the current implementation of jnlua (v1.0.2).
The solution to the above issue would be to implement versions of the three
string functions currently supported by jnlua, but that work with a Java char
array or byte array (one or the other), possibly something like:
byte[] checkStringAsBytes( int index )
void pushStringAsBytes( byte[] bytes )
byte[] toStringAsBytes( in index )
These obviously would just use the Lua C lstring functions without doing any
encoding/decoding of the data on the C/Java side.
As it is, the inability of jnlua to move binary data between Lua string and
Java is a showstopper.
Original issue reported on code.google.com by [email protected]
on 2 Oct 2012 at 11:04
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.