diff --git a/.gitignore b/.gitignore index d7642856..e9cc7bb8 100644 --- a/.gitignore +++ b/.gitignore @@ -13,3 +13,4 @@ jit/ *.zip docs *.0 +.java-version diff --git a/README.md b/README.md index 30f17dbd..7c89c36a 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,41 @@ # This is a fork! + +Compile with: `ant` or `ant jar-jse` + +(this will build only the project for Java Standard Edition) + +Then test with: `./luaj` + +(or `luaj.bat` on Windows) + +If you need JME support (Java Micro Edition, specifically for mobiles), +this fork is not recommended. + +You can try `ant all` or `ant jar-jme`, but there is no guarantee that it +will even compile (though that may be fixed in a future version). +The `TODO` file can contain information about some known issues. + +This fork aims to fix some issues met with luaj 3.0.2, still present in +[luaj/luaj](https://github.com/luaj/luaj) at +this time of writing. + +Building the version 3.0.2 with recent versions of ant (e.g. 1.10.11) and +JDK (8+) seems no longer possible. + +The `build.xml` file of this fork has been refactored in order to separate +jme and jse targets, and to upgrade the jse target to more recent versions +of the JDK (namely 1.8+). + +It is now possible to build the jse target alone with: `ant jar-jse` + +The `jar-jme` target from 3.0.2 won't be supported until contributors +experienced with JME be ready to join the project. + +The interpreter can be tested with `luaj` (on POSIX systems) or `luaj.bat` +(on Windows systems). These commands can be passed arguments. + +# Original README.md +
This repository has been forked from the original CVS sources of Luaj. The commit history has been converted to make sure that the original work of diff --git a/TODO b/TODO new file mode 100644 index 00000000..1df866ac --- /dev/null +++ b/TODO @@ -0,0 +1,20 @@ +The current version doesn't compile with: +ant jar-jme|all + +The Java compiler complains with an obscure error: + [javac] /Users/ducos/Projects/luaj/build/jme/src/org/luaj/vm2/LuaValue.java:532: error: cannot access StringBuilder + [javac] public String tojstring() { return typename() + ": " + Integer.toHexString(hashCode()); } + +This is because, in recent versions of Java, the concatenation of strings is automatically performed +with java.lang.StringBuilder + +Unfortunately, this class is not available in the JME environment. + +A workaround would be to replace the + concatenation with the String.concat() method, like this: + +- public String tojstring() { return typename() + ": " + Integer.toHexString(hashCode()); } ++ public String tojstring() { return typename().concat(": ").concat(Integer.toHexString(hashCode())); } + +But it has to be done everywhere in the code. + +Maybe there is a more straightforward method, with a compiler's flag. diff --git a/build-applet.xml b/build-applet.xml index d27b4420..9d019f9f 100644 --- a/build-applet.xml +++ b/build-applet.xml @@ -33,7 +33,7 @@ - @@ -70,7 +70,7 @@ -keep public class * extends java.applet.Applet - -target 1.4 + -target 1.8 @@ -95,7 +95,7 @@ width='800' height='640' > - + diff --git a/build-coverage.xml b/build-coverage.xml index 8a491f8c..be7c1845 100644 --- a/build-coverage.xml +++ b/build-coverage.xml @@ -46,7 +46,7 @@ - + diff --git a/build-midlet.xml b/build-midlet.xml index 89457961..73cdd467 100644 --- a/build-midlet.xml +++ b/build-midlet.xml @@ -59,7 +59,7 @@ - diff --git a/build.xml b/build.xml index e0ea7f0d..4fa4b6bc 100644 --- a/build.xml +++ b/build.xml @@ -1,4 +1,4 @@ - + @@ -33,79 +33,92 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + - + diff --git a/grammar/Lua51.jj b/grammar/Lua51.jj index 9f09de3a..cd7a7ae1 100644 --- a/grammar/Lua51.jj +++ b/grammar/Lua51.jj @@ -15,7 +15,7 @@ options { STATIC = false; - JDK_VERSION = "1.3"; + JDK_VERSION = "1.8"; ERROR_REPORTING = false; DEBUG_LOOKAHEAD = false; DEBUG_PARSER = false; diff --git a/grammar/Lua52.jj b/grammar/Lua52.jj index d84f4c6f..b304677a 100644 --- a/grammar/Lua52.jj +++ b/grammar/Lua52.jj @@ -15,7 +15,7 @@ options { STATIC = false; - JDK_VERSION = "1.3"; + JDK_VERSION = "1.8"; ERROR_REPORTING = false; DEBUG_LOOKAHEAD = false; DEBUG_PARSER = false; diff --git a/grammar/LuaParser.jj b/grammar/LuaParser.jj index 11c30b8b..374dc0b9 100644 --- a/grammar/LuaParser.jj +++ b/grammar/LuaParser.jj @@ -26,7 +26,7 @@ options { STATIC = false; - JDK_VERSION = "1.3"; + JDK_VERSION = "1.8"; ERROR_REPORTING = true; UNICODE_INPUT = true; DEBUG_LOOKAHEAD = false; diff --git a/luaj b/luaj new file mode 100755 index 00000000..3990dc36 --- /dev/null +++ b/luaj @@ -0,0 +1,3 @@ +#!/bin/sh + +exec jrunscript -cp luaj-jse-3.0.2.jar -l lua "$@" diff --git a/luaj.bat b/luaj.bat new file mode 100755 index 00000000..2e6dc2b2 --- /dev/null +++ b/luaj.bat @@ -0,0 +1,3 @@ +@echo off + +jrunscript -cp luaj-jse-3.0.2.jar -l lua %* diff --git a/src/core/org/luaj/vm2/compiler/LexState.java b/src/core/org/luaj/vm2/compiler/LexState.java index 0192de05..01c3508c 100644 --- a/src/core/org/luaj/vm2/compiler/LexState.java +++ b/src/core/org/luaj/vm2/compiler/LexState.java @@ -1391,7 +1391,7 @@ public class LexState extends Constants { return; } default: { - this.syntaxerror("unexpected symbol " + t.token + " (" + ((char) t.token) + ")"); + this.syntaxerror("unexpected symbol near " + token2str(t.token) + " (code " + t.token + ")"); return; } } diff --git a/src/core/org/luaj/vm2/lib/CoroutineLib.java b/src/core/org/luaj/vm2/lib/CoroutineLib.java index 28cb246b..18752e5f 100644 --- a/src/core/org/luaj/vm2/lib/CoroutineLib.java +++ b/src/core/org/luaj/vm2/lib/CoroutineLib.java @@ -75,51 +75,51 @@ public class CoroutineLib extends TwoArgFunction { public LuaValue call(LuaValue modname, LuaValue env) { globals = env.checkglobals(); LuaTable coroutine = new LuaTable(); - coroutine.set("create", new create()); - coroutine.set("resume", new resume()); - coroutine.set("running", new running()); - coroutine.set("status", new status()); - coroutine.set("yield", new yield()); - coroutine.set("wrap", new wrap()); + coroutine.set("create", new Create()); + coroutine.set("resume", new Resume()); + coroutine.set("running", new Running()); + coroutine.set("status", new Status()); + coroutine.set("yield", new Yield()); + coroutine.set("wrap", new Wrap()); env.set("coroutine", coroutine); if (!env.get("package").isnil()) env.get("package").get("loaded").set("coroutine", coroutine); return coroutine; } - final class create extends LibFunction { + final class Create extends LibFunction { public LuaValue call(LuaValue f) { return new LuaThread(globals, f.checkfunction()); } } - static final class resume extends VarArgFunction { + static final class Resume extends VarArgFunction { public Varargs invoke(Varargs args) { final LuaThread t = args.checkthread(1); return t.resume( args.subargs(2) ); } } - final class running extends VarArgFunction { + final class Running extends VarArgFunction { public Varargs invoke(Varargs args) { final LuaThread r = globals.running; return varargsOf(r, valueOf(r.isMainThread())); } } - static final class status extends LibFunction { + static final class Status extends LibFunction { public LuaValue call(LuaValue t) { LuaThread lt = t.checkthread(); return valueOf( lt.getStatus() ); } } - final class yield extends VarArgFunction { + final class Yield extends VarArgFunction { public Varargs invoke(Varargs args) { return globals.yield( args ); } } - final class wrap extends LibFunction { + final class Wrap extends LibFunction { public LuaValue call(LuaValue f) { final LuaValue func = f.checkfunction(); final LuaThread thread = new LuaThread(globals, func); diff --git a/src/jse/org/luaj/vm2/lib/jse/CoerceLuaToJava.java b/src/jse/org/luaj/vm2/lib/jse/CoerceLuaToJava.java index c658aacc..cac1ac48 100644 --- a/src/jse/org/luaj/vm2/lib/jse/CoerceLuaToJava.java +++ b/src/jse/org/luaj/vm2/lib/jse/CoerceLuaToJava.java @@ -174,13 +174,13 @@ public class CoerceLuaToJava { public Object coerce(LuaValue value) { switch ( targetType ) { - case TARGET_TYPE_BYTE: return new Byte( (byte) value.toint() ); - case TARGET_TYPE_CHAR: return new Character( (char) value.toint() ); - case TARGET_TYPE_SHORT: return new Short( (short) value.toint() ); - case TARGET_TYPE_INT: return new Integer( (int) value.toint() ); - case TARGET_TYPE_LONG: return new Long( (long) value.todouble() ); - case TARGET_TYPE_FLOAT: return new Float( (float) value.todouble() ); - case TARGET_TYPE_DOUBLE: return new Double( (double) value.todouble() ); + case TARGET_TYPE_BYTE: return Byte.valueOf( (byte) value.toint() ); + case TARGET_TYPE_CHAR: return Character.valueOf( (char) value.toint() ); + case TARGET_TYPE_SHORT: return Short.valueOf( (short) value.toint() ); + case TARGET_TYPE_INT: return Integer.valueOf( (int) value.toint() ); + case TARGET_TYPE_LONG: return Long.valueOf( (long) value.todouble() ); + case TARGET_TYPE_FLOAT: return Float.valueOf( (float) value.todouble() ); + case TARGET_TYPE_DOUBLE: return Double.valueOf( (double) value.todouble() ); default: return null; } } @@ -308,7 +308,7 @@ public class CoerceLuaToJava { public Object coerce(LuaValue value) { switch ( value.type() ) { case LuaValue.TNUMBER: - return value.isint()? (Object)new Integer(value.toint()): (Object)new Double(value.todouble()); + return value.isint()? (Object) Integer.valueOf(value.toint()): (Object) Double.valueOf(value.todouble()); case LuaValue.TBOOLEAN: return value.toboolean()? Boolean.TRUE: Boolean.FALSE; case LuaValue.TSTRING: diff --git a/src/jse/org/luaj/vm2/script/LuaScriptEngine.java b/src/jse/org/luaj/vm2/script/LuaScriptEngine.java index 415c885c..05282641 100644 --- a/src/jse/org/luaj/vm2/script/LuaScriptEngine.java +++ b/src/jse/org/luaj/vm2/script/LuaScriptEngine.java @@ -244,8 +244,8 @@ public class LuaScriptEngine extends AbstractScriptEngine implements ScriptEngin case LuaValue.TSTRING: return luajValue.tojstring(); case LuaValue.TUSERDATA: return luajValue.checkuserdata(Object.class); case LuaValue.TNUMBER: return luajValue.isinttype()? - (Object) new Integer(luajValue.toint()): - (Object) new Double(luajValue.todouble()); + (Object) Integer.valueOf(luajValue.toint()): + (Object) Double.valueOf(luajValue.todouble()); default: return luajValue; } }