46
README.md
46
README.md
@@ -13,7 +13,10 @@ on.<br>
|
||||
</div>
|
||||
|
||||
<h1>Getting Started with LuaJ</h1>
|
||||
James Roseborough, Ian Farmer, Version 3.0.1
|
||||
|
||||
|
||||
<h1>Getting Started with LuaJ</h1>
|
||||
James Roseborough, Ian Farmer, Version 3.0.2
|
||||
<p>
|
||||
<small>
|
||||
Copyright © 2009-2014 Luaj.org.
|
||||
@@ -117,7 +120,7 @@ in comparison with the standard C distribution.
|
||||
<td>16.794</td>
|
||||
<td>11.274</td>
|
||||
<td>Java</td>
|
||||
<td>java -cp luaj-jse-3.0.1.jar;bcel-5.2.jar lua <b>-b</b> fannkuch.lua 10</td></tr>
|
||||
<td>java -cp luaj-jse-3.0.2.jar;bcel-5.2.jar lua <b>-b</b> fannkuch.lua 10</td></tr>
|
||||
<tr valign="top">
|
||||
<td></td>
|
||||
<td></td>
|
||||
@@ -127,7 +130,7 @@ in comparison with the standard C distribution.
|
||||
<td>36.894</td>
|
||||
<td>15.163</td>
|
||||
<td></td>
|
||||
<td>java -cp luaj-jse-3.0.1.jar lua -n fannkuch.lua 10</td></tr>
|
||||
<td>java -cp luaj-jse-3.0.2.jar lua -n fannkuch.lua 10</td></tr>
|
||||
<tr valign="top">
|
||||
<td>lua</td>
|
||||
<td>5.1.4</td>
|
||||
@@ -183,7 +186,7 @@ It is also faster than Java-lua implementations Jill, Kahlua, and Mochalua for a
|
||||
From the main distribution directory line type:
|
||||
|
||||
<pre>
|
||||
java -cp lib/luaj-jse-3.0.1.jar lua examples/lua/hello.lua
|
||||
java -cp lib/luaj-jse-3.0.2.jar lua examples/lua/hello.lua
|
||||
</pre>
|
||||
|
||||
<p>
|
||||
@@ -195,7 +198,7 @@ You should see the following output:
|
||||
To see how luaj can be used to acccess most Java API's including swing, try:
|
||||
|
||||
<pre>
|
||||
java -cp lib/luaj-jse-3.0.1.jar lua examples/lua/swingapp.lua
|
||||
java -cp lib/luaj-jse-3.0.2.jar lua examples/lua/swingapp.lua
|
||||
</pre>
|
||||
|
||||
<p>
|
||||
@@ -210,8 +213,8 @@ Links to sources:<pre>
|
||||
From the main distribution directory line type:
|
||||
|
||||
<pre>
|
||||
java -cp lib/luaj-jse-3.0.1.jar luac examples/lua/hello.lua
|
||||
java -cp lib/luaj-jse-3.0.1.jar lua luac.out
|
||||
java -cp lib/luaj-jse-3.0.2.jar luac examples/lua/hello.lua
|
||||
java -cp lib/luaj-jse-3.0.2.jar lua luac.out
|
||||
</pre>
|
||||
|
||||
<p>
|
||||
@@ -225,8 +228,8 @@ Luaj can compile lua sources or binaries directly to java bytecode if the bcel l
|
||||
|
||||
<pre>
|
||||
ant bcel-lib
|
||||
java -cp "lib/luaj-jse-3.0.1.jar;lib/bcel-5.2.jar" luajc -s examples/lua -d . hello.lua
|
||||
java -cp "lib/luaj-jse-3.0.1.jar;." lua -l hello
|
||||
java -cp "lib/luaj-jse-3.0.2.jar;lib/bcel-5.2.jar" luajc -s examples/lua -d . hello.lua
|
||||
java -cp "lib/luaj-jse-3.0.2.jar;." lua -l hello
|
||||
</pre>
|
||||
|
||||
<p>
|
||||
@@ -237,7 +240,7 @@ but the compiled classes must be in the class path at runtime, unless runtime ji
|
||||
<p>
|
||||
Lua scripts can also be run directly in this mode without precompiling using the <em>lua</em> command with the <b><em>-b</em></b> option and providing the <em>bcel</em> library in the class path:
|
||||
<pre>
|
||||
java -cp "lib/luaj-jse-3.0.1.jar;lib/bcel-5.2.jar" lua -b examples/lua/hello.lua
|
||||
java -cp "lib/luaj-jse-3.0.2.jar;lib/bcel-5.2.jar" lua -b examples/lua/hello.lua
|
||||
</pre>
|
||||
|
||||
|
||||
@@ -281,7 +284,7 @@ A simple example may be found in
|
||||
</pre>
|
||||
|
||||
<p>
|
||||
You must include the library <b>lib/luaj-jse-3.0.1.jar</b> in your class path.
|
||||
You must include the library <b>lib/luaj-jse-3.0.2.jar</b> in your class path.
|
||||
|
||||
<h2>Run a script in a MIDlet</h2>
|
||||
|
||||
@@ -308,7 +311,7 @@ A simple example may be found in
|
||||
</pre>
|
||||
|
||||
<p>
|
||||
You must include the library <b>lib/luaj-jme-3.0.1.jar</b> in your midlet jar.
|
||||
You must include the library <b>lib/luaj-jme-3.0.2.jar</b> in your midlet jar.
|
||||
|
||||
<p>
|
||||
An ant script to build and run the midlet is in
|
||||
@@ -338,7 +341,7 @@ You can also look up the engine by language "lua" or mimetypes "text/lua" or "ap
|
||||
All standard aspects of script engines including compiled statements are supported.
|
||||
|
||||
<p>
|
||||
You must include the library <b>lib/luaj-jse-3.0.1.jar</b> in your class path.
|
||||
You must include the library <b>lib/luaj-jse-3.0.2.jar</b> in your class path.
|
||||
|
||||
<p>
|
||||
A working example may be found in
|
||||
@@ -349,8 +352,8 @@ A working example may be found in
|
||||
To compile and run it using Java 1.6 or higher:
|
||||
|
||||
<pre>
|
||||
javac -cp lib/luaj-jse-3.0.1.jar examples/jse/ScriptEngineSample.java
|
||||
java -cp "lib/luaj-jse-3.0.1.jar;examples/jse" ScriptEngineSample
|
||||
javac -cp lib/luaj-jse-3.0.2.jar examples/jse/ScriptEngineSample.java
|
||||
java -cp "lib/luaj-jse-3.0.2.jar;examples/jse" ScriptEngineSample
|
||||
</pre>
|
||||
|
||||
<h2>Excluding the lua bytecode compiler</h2>
|
||||
@@ -590,7 +593,7 @@ The following lua script will open a swing frame on Java SE:
|
||||
See a longer sample in <em>examples/lua/swingapp.lua</em> for details, including a simple animation loop, rendering graphics, mouse and key handling, and image loading.
|
||||
Or try running it using:
|
||||
<pre>
|
||||
java -cp lib/luaj-jse-3.0.1.jar lua examples/lua/swingapp.lua
|
||||
java -cp lib/luaj-jse-3.0.2.jar lua examples/lua/swingapp.lua
|
||||
</pre>
|
||||
|
||||
<p>
|
||||
@@ -839,7 +842,7 @@ For JSE projects, add this dependency for the luaj-jse jar:
|
||||
<dependency>
|
||||
<groupId>org.luaj</groupId>
|
||||
<artifactId>luaj-jse</artifactId>
|
||||
<version>3.0.1</version>
|
||||
<version>3.0.2</version>
|
||||
</dependency>
|
||||
</pre>
|
||||
while for JME projects, use the luaj-jme jar:
|
||||
@@ -847,7 +850,7 @@ while for JME projects, use the luaj-jme jar:
|
||||
<dependency>
|
||||
<groupId>org.luaj</groupId>
|
||||
<artifactId>luaj-jme</artifactId>
|
||||
<version>3.0.1</version>
|
||||
<version>3.0.2</version>
|
||||
</dependency>
|
||||
</pre>
|
||||
|
||||
@@ -877,7 +880,7 @@ Unit test scripts can be found in these locations
|
||||
test/lua/*.lua
|
||||
test/lua/errors/*.lua
|
||||
test/lua/perf/*.lua
|
||||
test/lua/luaj3.0.1-tests.zip
|
||||
test/lua/luaj3.0.2-tests.zip
|
||||
</pre>
|
||||
|
||||
<h2>Code coverage</h2>
|
||||
@@ -1014,6 +1017,11 @@ and at <a href="http://luaj.sourceforge.net/api/2.0/index.html">http://luaj.sour
|
||||
<li>Move online docs to <a href="http://luaj.org/luaj/3.0/api/index.html">http://luaj.org/luaj/3.0/api/</a></li>
|
||||
<li>Fix os.time() conversions for pm times.</li>
|
||||
|
||||
<tr valign="top"><td> <b>3.0.2</b></td><td><ul>
|
||||
<li>Fix JsePlatform.luaMain() to provide an "arg" table in the chunk's environment.</li>
|
||||
<li>Let JsePlatform.luaMain() return values returned by the main chunk.</li>
|
||||
<li>Add synchronization to CoerceJavaToLua.COERCIONS map.</li>
|
||||
|
||||
</ul></td></tr>
|
||||
</table></td></tr></table>
|
||||
|
||||
|
||||
@@ -97,14 +97,19 @@ public class LuaClosure extends LuaFunction {
|
||||
*/
|
||||
public LuaClosure(Prototype p, LuaValue env) {
|
||||
this.p = p;
|
||||
this.initupvalue1(env);
|
||||
globals = env instanceof Globals? (Globals) env: null;
|
||||
}
|
||||
|
||||
public void initupvalue1(LuaValue env) {
|
||||
if (p.upvalues == null || p.upvalues.length == 0)
|
||||
this.upValues = NOUPVALUES;
|
||||
else {
|
||||
this.upValues = new UpValue[p.upvalues.length];
|
||||
this.upValues[0] = new UpValue(new LuaValue[] {env}, 0);
|
||||
}
|
||||
globals = env instanceof Globals? (Globals) env: null;
|
||||
}
|
||||
|
||||
|
||||
public boolean isclosure() {
|
||||
return true;
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
******************************************************************************/
|
||||
package org.luaj.vm2.lib.jse;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -133,7 +134,7 @@ public class CoerceJavaToLua {
|
||||
}
|
||||
|
||||
|
||||
static final Map COERCIONS = new HashMap();
|
||||
static final Map COERCIONS = Collections.synchronizedMap(new HashMap());
|
||||
|
||||
static {
|
||||
Coercion boolCoercion = new BoolCoercion() ;
|
||||
|
||||
@@ -25,6 +25,7 @@ import org.luaj.vm2.Globals;
|
||||
import org.luaj.vm2.LoadState;
|
||||
import org.luaj.vm2.LuaThread;
|
||||
import org.luaj.vm2.LuaValue;
|
||||
import org.luaj.vm2.Varargs;
|
||||
import org.luaj.vm2.compiler.LuaC;
|
||||
import org.luaj.vm2.lib.Bit32Lib;
|
||||
import org.luaj.vm2.lib.CoroutineLib;
|
||||
@@ -124,10 +125,11 @@ public class JsePlatform {
|
||||
|
||||
|
||||
/** Simple wrapper for invoking a lua function with command line arguments.
|
||||
* The supplied function is first given a new Globals object,
|
||||
* then the program is run with arguments.
|
||||
* The supplied function is first given a new Globals object as its environment
|
||||
* then the program is run with arguments.
|
||||
* @return {@link Varargs} containing any values returned by mainChunk.
|
||||
*/
|
||||
public static void luaMain(LuaValue mainChunk, String[] args) {
|
||||
public static Varargs luaMain(LuaValue mainChunk, String[] args) {
|
||||
Globals g = standardGlobals();
|
||||
int n = args.length;
|
||||
LuaValue[] vargs = new LuaValue[args.length];
|
||||
@@ -137,6 +139,6 @@ public class JsePlatform {
|
||||
arg.set("n", n);
|
||||
g.set("arg", arg);
|
||||
mainChunk.initupvalue1(g);
|
||||
mainChunk.invoke(LuaValue.varargsOf(vargs));
|
||||
return mainChunk.invoke(LuaValue.varargsOf(vargs));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,6 +32,7 @@ import org.luaj.vm2.compiler.DumpLoadEndianIntTest;
|
||||
import org.luaj.vm2.compiler.LuaParserTests;
|
||||
import org.luaj.vm2.compiler.RegressionTests;
|
||||
import org.luaj.vm2.compiler.SimpleTests;
|
||||
import org.luaj.vm2.lib.jse.JsePlatformTest;
|
||||
import org.luaj.vm2.lib.jse.LuaJavaCoercionTest;
|
||||
import org.luaj.vm2.lib.jse.LuajavaAccessibleMembersTest;
|
||||
import org.luaj.vm2.lib.jse.LuajavaClassMembersTest;
|
||||
@@ -85,6 +86,7 @@ public class AllTests {
|
||||
|
||||
// library tests
|
||||
TestSuite lib = new TestSuite("Library Tests");
|
||||
lib.addTestSuite(JsePlatformTest.class);
|
||||
lib.addTestSuite(LuajavaAccessibleMembersTest.class);
|
||||
lib.addTestSuite(LuajavaClassMembersTest.class);
|
||||
lib.addTestSuite(LuaJavaCoercionTest.class);
|
||||
|
||||
21
test/junit/org/luaj/vm2/lib/jse/JsePlatformTest.java
Normal file
21
test/junit/org/luaj/vm2/lib/jse/JsePlatformTest.java
Normal file
@@ -0,0 +1,21 @@
|
||||
package org.luaj.vm2.lib.jse;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.luaj.vm2.Globals;
|
||||
import org.luaj.vm2.LuaValue;
|
||||
import org.luaj.vm2.Varargs;
|
||||
|
||||
|
||||
public class JsePlatformTest extends TestCase {
|
||||
public void testLuaMainPassesArguments() {
|
||||
Globals globals = JsePlatform.standardGlobals();
|
||||
LuaValue chunk = globals.load("return #arg, arg.n, arg[2], arg[1]");
|
||||
Varargs results = JsePlatform.luaMain(chunk, new String[] { "aaa", "bbb" });
|
||||
assertEquals(results.narg(), 4);
|
||||
assertEquals(results.arg(1), LuaValue.valueOf(2));
|
||||
assertEquals(results.arg(2), LuaValue.valueOf(2));
|
||||
assertEquals(results.arg(3), LuaValue.valueOf("bbb"));
|
||||
assertEquals(results.arg(4), LuaValue.valueOf("aaa"));
|
||||
}
|
||||
}
|
||||
@@ -1 +1 @@
|
||||
version: 3.0.1
|
||||
version: 3.0.2
|
||||
Reference in New Issue
Block a user