|
JavaVMModule
Java VM Module
The JNLua Java VM module is a Lua module written in C that allows a Lua process to create a Java Virtual Machine and run Java code in that machine. In essence, the Java VM module supports bootstrapping JNLua from the Lua side. PrerequisitesIn order to use the Java VM module, the following prerequsites must be met:
ExampleThe following Lua code provides an example of using the Java VM module: javavm = require("javavm")
javavm.create("-Djava.class.path=jnlua-1.0.2.jar")
System = java.require("java.lang.System")
System.out:println("Hello, world!")
javavm.destroy()LimitationsThe JNI specification allows for only one Java virtual machine to be concurrently attached to a thread. Therefore, the Java VM module supports only one virtual machine at any point in time. In practice, Java virtual machine implementations can be even more restrictive and allow only one Java virtual machine to be created for the lifetime of a process, i.e. even after the Java virtual machine has been destroyed, subsequent attempts of creating a new Java virtual machine fail. FunctionsThe Java VM module provides the following functions. javavm.createSyntax: vm = javavm.create({ option }) The function creates a Java virtual machine using the options provided and returns the virtual machine. In addition, the JNLua Java Module is loaded into the Lua state. If there already is a virtual machine, the function raises an error. Example: javavm.create("-Djava.class.path=jnlua-1.0.1.jar")javavm.getSyntax: vm = javavm.get() The function returns the current virtual machine, or nil if there is none. javavm.destroySyntax: success = javavm.destroy() The function destroys the current virtual machine and returns a boolean indicating whether the operation was successful. Calling the function when there is no current virtual machine returns false. |