26 Commits

Author SHA1 Message Date
Fabrice Ducos
12ef701595 src/core/org/luaj/vm2/compiler/LexState.java
Store Integers directly in RESERVED (instead of String): Integer.valueOf(FIRST_RESERVED+i) -> new Integer(FIRST_RESERVED+i)
2023-04-24 02:02:28 +02:00
Fabrice Ducos
e54b0c3d57 src/core/org/luaj/vm2/compiler/FuncState.java:
Store Integers directly in h (instead of String): this.h.put(v, Integer.valueOf(idx)) -> this.h.put(v, new Integer(idx))
2023-04-24 02:01:16 +02:00
Fabrice Ducos
91735791f0 TODO: fixed a typo 2023-04-23 15:04:55 +02:00
Fabrice Ducos
3fad817099 New file TODO 2023-04-23 15:03:15 +02:00
Fabrice Ducos
65a5088092 src/core/org/luaj/vm2/compiler/FuncState.java: reverted changed from generic HashMap to non generic Hashtable for JME portability 2023-04-23 14:40:20 +02:00
Fabrice Ducos
113c3a9b97 README.md updated 2023-04-23 14:16:41 +02:00
Fabrice Ducos
1b8d7c7485 README.md updated 2023-04-23 14:08:03 +02:00
Fabrice Ducos
f364bb0189 README.md updated 2023-04-23 13:49:16 +02:00
Fabrice Ducos
f680cce336 README.md updated 2023-04-23 13:46:38 +02:00
Fabrice Ducos
b0df2ddcb0 build.xml: default task is now "jar-jse" instead of "all" 2023-04-23 13:44:20 +02:00
Fabrice Ducos
2207f7f2e2 src/core/org/luaj/vm2/compiler/FuncState.java:
Replaced the deprecated, non generic Hashtable with generic Map (interface) and HashMap (implementation)

Hashtable h -> Map<LuaValue, Integer> h

this.h = new Hashtable() -> this.h = new HashMap<>()
2023-04-23 12:58:56 +02:00
Fabrice Ducos
8df7dd717c build-coverage.xml: javac target="1.5" -> target="1.8" 2023-04-23 12:27:47 +02:00
Fabrice Ducos
a40e6862f4 build-applet.xml:
-target 1.4 -> -target 1.8

<param name=java_version value="1.4+"/> -> <param name=java_version value="1.8+"/>
2023-04-23 12:24:58 +02:00
Fabrice Ducos
33b6428031 grammar/LuaParser.jj, grammer/Lua5[12].jj: JDK_VERSION upgraded from 1.3 to 1.8 2023-04-23 12:19:04 +02:00
Fabrice Ducos
ee08260ce2 build-applet.xml, build-midlet.xml: source and target of javac upgraded from 1.2, 1.3 or 1.4 to 1.8 2023-04-23 12:07:40 +02:00
Fabrice Ducos
393cf23775 build.xml: includeantruntime="false" added to javac
Reference: https://stackoverflow.com/questions/5103384/ant-warning-includeantruntime-was-not-set
2023-04-23 12:00:20 +02:00
Fabrice Ducos
970cfc579a .gitignore: .java-version added (a .jenv configuration file) 2023-04-23 11:58:52 +02:00
Fabrice Ducos
7aa0389f6f README.md updated 2022-06-15 07:14:27 +02:00
Fabrice Ducos
c09d652874 luaj ported to Windows with the name luaj.bat 2022-06-15 07:12:36 +02:00
Fabrice Ducos
3c863714b4 src/core/org/luaj/vm2/compiler/LexState.java: error message on unexpected symbol fixed (it was returning a strange character
corresponding to an internal token code, meaningless to the user)
2022-06-15 01:11:09 +02:00
Fabrice Ducos
bfb7da97cf luaj: new command for invoking the luaj interpreter 2022-06-15 01:09:05 +02:00
Fabrice Ducos
1aa90eb7fa src/core/org/luaj/vm2/lib/CoroutineLib.java:
Internal classes create, resume, ..., yield, wrap renamed Create, Resume, ... Yield, Wrap

This change was motivated by the fact that yield is a restricted name in JDK 14+

A lowercase 'yield' class was producing a warning in JDK 8 and could potentially not compile in newer JDK.
2022-06-14 22:40:10 +02:00
Fabrice Ducos
610833f025 build.xml: includeantruntime="false" appended to javac tasks in order to ensure repeatable builds by ant 2022-06-14 22:30:41 +02:00
Fabrice Ducos
9e1a62662a Removed deprecated wrapper class constructors (new Byte, ..., new Integer, new Double...)
Replaced with valueOf() in order to silence many warnings from modern versions of the JDK
2022-06-14 22:25:20 +02:00
Fabrice Ducos
314ffd6a23 Update README.md 2022-06-14 22:03:47 +02:00
Fabrice Ducos
7395234ccf build.xml: refactored with separate targets for jme and jse: compile-jme and compile-jse
New versions of ant (e.g. 1.10.11) at this time of writing fail to build jar-jme

because the source (1.2) and target (1.3) are considered too old.

The jme target can now be compiled separately with 'ant jar-jme'

and the jse target with 'ant jar-jse'

The jse target will now be built with source="1.8" and target="1.8"
2022-06-14 21:37:48 +02:00
16 changed files with 177 additions and 100 deletions

1
.gitignore vendored
View File

@@ -13,3 +13,4 @@ jit/
*.zip *.zip
docs docs
*.0 *.0
.java-version

View File

@@ -1,4 +1,41 @@
# This is a fork! # 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
<div style="border: 1px dotted red; margin: 1.em 0.5em; font-weight: bold; color: red;"> <div style="border: 1px dotted red; margin: 1.em 0.5em; font-weight: bold; color: red;">
This repository has been forked from the original CVS sources of Luaj. 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 The commit history has been converted to make sure that the original work of

20
TODO Normal file
View File

@@ -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.

View File

@@ -33,7 +33,7 @@
<copy todir="${build.dir}"> <copy todir="${build.dir}">
<fileset dir="${script.dir}" includes="${script.name}.lua,${image.name}"/> <fileset dir="${script.dir}" includes="${script.name}.lua,${image.name}"/>
</copy> </copy>
<javac destdir="${build.dir}/classes" source="1.4" target="1.4" <javac destdir="${build.dir}/classes" source="1.8" target="1.8"
classpath="${luaj.jar}" srcdir="${java.dir}" includes="${java.name}.java"/> classpath="${luaj.jar}" srcdir="${java.dir}" includes="${java.name}.java"/>
</target> </target>
@@ -70,7 +70,7 @@
-keep public class * extends java.applet.Applet -keep public class * extends java.applet.Applet
-target 1.4 -target 1.8
</proguard> </proguard>
</target> </target>
@@ -95,7 +95,7 @@
width='800' width='800'
height='640' > height='640' >
<param name='luaj.script' value='${script.name}.lua'/> <param name='luaj.script' value='${script.name}.lua'/>
<param name="java_version" value="1.4+"/> <param name="java_version" value="1.8+"/>
</applet> </applet>
</body> </body>
</html> </html>

View File

@@ -46,7 +46,7 @@
</target> </target>
<target name="compile" depends="init,wtk-or-fail"> <target name="compile" depends="init,wtk-or-fail">
<javac destdir="${classes.dir}" debug="yes" target="1.5"> <javac destdir="${classes.dir}" debug="yes" target="1.8">
<classpath refid="cobertura.classpath" /> <classpath refid="cobertura.classpath" />
<classpath refid="wtk-libs" /> <classpath refid="wtk-libs" />
<classpath path="lib/bcel-5.2.jar" /> <classpath path="lib/bcel-5.2.jar" />

View File

@@ -59,7 +59,7 @@
<pathelement path="lib/midpapi20.jar"/> <pathelement path="lib/midpapi20.jar"/>
<pathelement path="lib/mmapi.jar"/> <pathelement path="lib/mmapi.jar"/>
</path> </path>
<javac destdir="build/classes" encoding="utf-8" source="1.3" target="1.2" bootclasspathref="wtk-libs" <javac destdir="build/classes" encoding="utf-8" source="1.8" target="1.8" bootclasspathref="wtk-libs"
srcdir="build/midlet/src"/> srcdir="build/midlet/src"/>
</target> </target>

View File

@@ -1,4 +1,4 @@
<project default="all"> <project default="jar-jse">
<property file="version.properties"/> <property file="version.properties"/>
<property name="jar.name.jme" value="luaj-jme-${version}.jar"/> <property name="jar.name.jme" value="luaj-jme-${version}.jar"/>
@@ -34,13 +34,10 @@
</java> </java>
</target> </target>
<target name="compile" depends="wtk-libs,bcel-lib"> <target name="compile-jme" depends="wtk-libs,bcel-lib">
<delete dir="build/jme/src"/> <delete dir="build/jme/src"/>
<delete dir="build/jse/src"/>
<mkdir dir="build/jme/src"/> <mkdir dir="build/jme/src"/>
<mkdir dir="build/jse/src"/>
<mkdir dir="build/jme/classes"/> <mkdir dir="build/jme/classes"/>
<mkdir dir="build/jse/classes"/>
<copy todir="build/jme/src"> <copy todir="build/jme/src">
<fileset dir="src/core"/> <fileset dir="src/core"/>
<fileset dir="src/jme"/> <fileset dir="src/jme"/>
@@ -48,6 +45,21 @@
<tokenfilter><replacestring from='"Luaj 0.0"' to='"Luaj-jme ${version}"'/></tokenfilter> <tokenfilter><replacestring from='"Luaj 0.0"' to='"Luaj-jme ${version}"'/></tokenfilter>
</filterchain> </filterchain>
</copy> </copy>
<path id="wtk-libs">
<pathelement path="lib/cldcapi11.jar"/>
<pathelement path="lib/midpapi20.jar"/>
<pathelement path="lib/mmapi.jar"/>
</path>
<javac includeantruntime="false" destdir="build/jme/classes" encoding="utf-8" source="1.8" target="1.8" bootclasspathref="wtk-libs"
debug="on"
srcdir="build/jme/src"/>
</target>
<target name="compile-jse" depends="wtk-libs,bcel-lib">
<delete dir="build/jse/src"/>
<mkdir dir="build/jse/src"/>
<mkdir dir="build/jse/classes"/>
<copy todir="build/jse/src"> <copy todir="build/jse/src">
<fileset dir="src/core"/> <fileset dir="src/core"/>
<filterchain> <filterchain>
@@ -76,36 +88,37 @@
<tokenfilter><replacestring from='&lt;LuaString,String&gt;' to=''/></tokenfilter> <tokenfilter><replacestring from='&lt;LuaString,String&gt;' to=''/></tokenfilter>
</filterchain> </filterchain>
</copy> </copy>
<path id="wtk-libs">
<pathelement path="lib/cldcapi11.jar"/> <javac destdir="build/jse/classes" encoding="utf-8" source="1.8" target="1.8"
<pathelement path="lib/midpapi20.jar"/>
<pathelement path="lib/mmapi.jar"/>
</path>
<javac destdir="build/jme/classes" encoding="utf-8" source="1.3" target="1.2" bootclasspathref="wtk-libs"
debug="on"
srcdir="build/jme/src"/>
<javac destdir="build/jse/classes" encoding="utf-8" source="1.3" target="1.3"
classpath="lib/bcel-5.2.jar" classpath="lib/bcel-5.2.jar"
debug="on" debug="on"
srcdir="build/jse/src" srcdir="build/jse/src"
excludes="**/script/*,**/Lua2Java*,**/server/*,lua*"/> excludes="**/script/*,**/Lua2Java*,**/server/*,lua*"
<javac destdir="build/jse/classes" encoding="utf-8" source="1.5" target="1.5" includeantruntime="false"
/>
<javac destdir="build/jse/classes" encoding="utf-8" source="1.8" target="1.8"
classpath="build/jse/classes" classpath="build/jse/classes"
debug="on" debug="on"
srcdir="build/jse/src" srcdir="build/jse/src"
includes="**/script/*,**/Lua2Java*,**/server/*"/> includes="**/script/*,**/Lua2Java*,**/server/*"
<javac destdir="build/jse/classes" encoding="utf-8" source="1.3" target="1.3" includeantruntime="false"
/>
<javac destdir="build/jse/classes" encoding="utf-8" source="1.8" target="1.8"
classpath="build/jse/classes" classpath="build/jse/classes"
debug="on" debug="on"
srcdir="build/jse/src" srcdir="build/jse/src"
includes="lua*"/> includes="lua*"
includeantruntime="false"
/>
</target> </target>
<target name="jar-jme" depends="compile"> <target name="compile" depends="compile-jme,compile-jse" />
<target name="jar-jme" depends="compile-jme">
<jar destfile="${jar.name.jme}" basedir="build/jme/classes"/> <jar destfile="${jar.name.jme}" basedir="build/jme/classes"/>
</target> </target>
<target name="jar-jse" depends="compile"> <target name="jar-jse" depends="compile-jse">
<jar destfile="${jar.name.jse}"> <jar destfile="${jar.name.jse}">
<fileset dir="build/jse/classes"/> <fileset dir="build/jse/classes"/>
<fileset dir="src/jse/"> <fileset dir="src/jse/">

View File

@@ -15,7 +15,7 @@
options { options {
STATIC = false; STATIC = false;
JDK_VERSION = "1.3"; JDK_VERSION = "1.8";
ERROR_REPORTING = false; ERROR_REPORTING = false;
DEBUG_LOOKAHEAD = false; DEBUG_LOOKAHEAD = false;
DEBUG_PARSER = false; DEBUG_PARSER = false;

View File

@@ -15,7 +15,7 @@
options { options {
STATIC = false; STATIC = false;
JDK_VERSION = "1.3"; JDK_VERSION = "1.8";
ERROR_REPORTING = false; ERROR_REPORTING = false;
DEBUG_LOOKAHEAD = false; DEBUG_LOOKAHEAD = false;
DEBUG_PARSER = false; DEBUG_PARSER = false;

View File

@@ -26,7 +26,7 @@
options { options {
STATIC = false; STATIC = false;
JDK_VERSION = "1.3"; JDK_VERSION = "1.8";
ERROR_REPORTING = true; ERROR_REPORTING = true;
UNICODE_INPUT = true; UNICODE_INPUT = true;
DEBUG_LOOKAHEAD = false; DEBUG_LOOKAHEAD = false;

3
luaj Executable file
View File

@@ -0,0 +1,3 @@
#!/bin/sh
exec jrunscript -cp luaj-jse-3.0.2.jar -l lua "$@"

3
luaj.bat Executable file
View File

@@ -0,0 +1,3 @@
@echo off
jrunscript -cp luaj-jse-3.0.2.jar -l lua %*

View File

@@ -1391,7 +1391,7 @@ public class LexState extends Constants {
return; return;
} }
default: { default: {
this.syntaxerror("unexpected symbol " + t.token + " (" + ((char) t.token) + ")"); this.syntaxerror("unexpected symbol near " + token2str(t.token) + " (code " + t.token + ")");
return; return;
} }
} }

View File

@@ -75,51 +75,51 @@ public class CoroutineLib extends TwoArgFunction {
public LuaValue call(LuaValue modname, LuaValue env) { public LuaValue call(LuaValue modname, LuaValue env) {
globals = env.checkglobals(); globals = env.checkglobals();
LuaTable coroutine = new LuaTable(); LuaTable coroutine = new LuaTable();
coroutine.set("create", new create()); coroutine.set("create", new Create());
coroutine.set("resume", new resume()); coroutine.set("resume", new Resume());
coroutine.set("running", new running()); coroutine.set("running", new Running());
coroutine.set("status", new status()); coroutine.set("status", new Status());
coroutine.set("yield", new yield()); coroutine.set("yield", new Yield());
coroutine.set("wrap", new wrap()); coroutine.set("wrap", new Wrap());
env.set("coroutine", coroutine); env.set("coroutine", coroutine);
if (!env.get("package").isnil()) env.get("package").get("loaded").set("coroutine", coroutine); if (!env.get("package").isnil()) env.get("package").get("loaded").set("coroutine", coroutine);
return coroutine; return coroutine;
} }
final class create extends LibFunction { final class Create extends LibFunction {
public LuaValue call(LuaValue f) { public LuaValue call(LuaValue f) {
return new LuaThread(globals, f.checkfunction()); return new LuaThread(globals, f.checkfunction());
} }
} }
static final class resume extends VarArgFunction { static final class Resume extends VarArgFunction {
public Varargs invoke(Varargs args) { public Varargs invoke(Varargs args) {
final LuaThread t = args.checkthread(1); final LuaThread t = args.checkthread(1);
return t.resume( args.subargs(2) ); return t.resume( args.subargs(2) );
} }
} }
final class running extends VarArgFunction { final class Running extends VarArgFunction {
public Varargs invoke(Varargs args) { public Varargs invoke(Varargs args) {
final LuaThread r = globals.running; final LuaThread r = globals.running;
return varargsOf(r, valueOf(r.isMainThread())); return varargsOf(r, valueOf(r.isMainThread()));
} }
} }
static final class status extends LibFunction { static final class Status extends LibFunction {
public LuaValue call(LuaValue t) { public LuaValue call(LuaValue t) {
LuaThread lt = t.checkthread(); LuaThread lt = t.checkthread();
return valueOf( lt.getStatus() ); return valueOf( lt.getStatus() );
} }
} }
final class yield extends VarArgFunction { final class Yield extends VarArgFunction {
public Varargs invoke(Varargs args) { public Varargs invoke(Varargs args) {
return globals.yield( args ); return globals.yield( args );
} }
} }
final class wrap extends LibFunction { final class Wrap extends LibFunction {
public LuaValue call(LuaValue f) { public LuaValue call(LuaValue f) {
final LuaValue func = f.checkfunction(); final LuaValue func = f.checkfunction();
final LuaThread thread = new LuaThread(globals, func); final LuaThread thread = new LuaThread(globals, func);

View File

@@ -174,13 +174,13 @@ public class CoerceLuaToJava {
public Object coerce(LuaValue value) { public Object coerce(LuaValue value) {
switch ( targetType ) { switch ( targetType ) {
case TARGET_TYPE_BYTE: return new Byte( (byte) value.toint() ); case TARGET_TYPE_BYTE: return Byte.valueOf( (byte) value.toint() );
case TARGET_TYPE_CHAR: return new Character( (char) value.toint() ); case TARGET_TYPE_CHAR: return Character.valueOf( (char) value.toint() );
case TARGET_TYPE_SHORT: return new Short( (short) value.toint() ); case TARGET_TYPE_SHORT: return Short.valueOf( (short) value.toint() );
case TARGET_TYPE_INT: return new Integer( (int) value.toint() ); case TARGET_TYPE_INT: return Integer.valueOf( (int) value.toint() );
case TARGET_TYPE_LONG: return new Long( (long) value.todouble() ); case TARGET_TYPE_LONG: return Long.valueOf( (long) value.todouble() );
case TARGET_TYPE_FLOAT: return new Float( (float) value.todouble() ); case TARGET_TYPE_FLOAT: return Float.valueOf( (float) value.todouble() );
case TARGET_TYPE_DOUBLE: return new Double( (double) value.todouble() ); case TARGET_TYPE_DOUBLE: return Double.valueOf( (double) value.todouble() );
default: return null; default: return null;
} }
} }
@@ -308,7 +308,7 @@ public class CoerceLuaToJava {
public Object coerce(LuaValue value) { public Object coerce(LuaValue value) {
switch ( value.type() ) { switch ( value.type() ) {
case LuaValue.TNUMBER: 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: case LuaValue.TBOOLEAN:
return value.toboolean()? Boolean.TRUE: Boolean.FALSE; return value.toboolean()? Boolean.TRUE: Boolean.FALSE;
case LuaValue.TSTRING: case LuaValue.TSTRING:

View File

@@ -244,8 +244,8 @@ public class LuaScriptEngine extends AbstractScriptEngine implements ScriptEngin
case LuaValue.TSTRING: return luajValue.tojstring(); case LuaValue.TSTRING: return luajValue.tojstring();
case LuaValue.TUSERDATA: return luajValue.checkuserdata(Object.class); case LuaValue.TUSERDATA: return luajValue.checkuserdata(Object.class);
case LuaValue.TNUMBER: return luajValue.isinttype()? case LuaValue.TNUMBER: return luajValue.isinttype()?
(Object) new Integer(luajValue.toint()): (Object) Integer.valueOf(luajValue.toint()):
(Object) new Double(luajValue.todouble()); (Object) Double.valueOf(luajValue.todouble());
default: return luajValue; default: return luajValue;
} }
} }