From 7395234ccf8a6e98b7d027dafd23b86766f9e12a Mon Sep 17 00:00:00 2001 From: Fabrice Ducos Date: Tue, 14 Jun 2022 21:37:48 +0200 Subject: [PATCH 01/26] 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" --- build.xml | 143 ++++++++++++++++++++++++++++-------------------------- 1 file changed, 75 insertions(+), 68 deletions(-) diff --git a/build.xml b/build.xml index e0ea7f0d..8fa8b0f9 100644 --- a/build.xml +++ b/build.xml @@ -33,79 +33,86 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + - + -- 2.49.1 From 314ffd6a233e9b16173b2a16cd3ada9b6ea602e0 Mon Sep 17 00:00:00 2001 From: Fabrice Ducos Date: Tue, 14 Jun 2022 22:03:47 +0200 Subject: [PATCH 02/26] Update README.md --- README.md | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/README.md b/README.md index 30f17dbd..eb24483d 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,29 @@ # This is a fork! + +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. Issuing the `ant` command will fail +with the following error: + +``` +[javac] error: Source option 1.3 is no longer supported. Use 7 or later. +[javac] error: Target option 1.2 is no longer supported. Use 7 or later. +``` + +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 will be left unchanged until contributors +experienced with JME be ready to join the project. + +# 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 -- 2.49.1 From 9e1a62662ab8a5b51d7e1e5b0ef56bfda6fef7e0 Mon Sep 17 00:00:00 2001 From: Fabrice Ducos Date: Tue, 14 Jun 2022 22:25:20 +0200 Subject: [PATCH 03/26] 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 --- src/core/org/luaj/vm2/compiler/FuncState.java | 2 +- src/core/org/luaj/vm2/compiler/LexState.java | 2 +- .../org/luaj/vm2/lib/jse/CoerceLuaToJava.java | 16 ++++++++-------- src/jse/org/luaj/vm2/script/LuaScriptEngine.java | 4 ++-- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/core/org/luaj/vm2/compiler/FuncState.java b/src/core/org/luaj/vm2/compiler/FuncState.java index 70e0f885..98534d50 100644 --- a/src/core/org/luaj/vm2/compiler/FuncState.java +++ b/src/core/org/luaj/vm2/compiler/FuncState.java @@ -479,7 +479,7 @@ public class FuncState extends Constants { return ((Integer) h.get(v)).intValue(); } final int idx = this.nk; - this.h.put(v, new Integer(idx)); + this.h.put(v, Integer.valueOf(idx)); final Prototype f = this.f; if (f.k == null || nk + 1 >= f.k.length) f.k = realloc( f.k, nk*2 + 1 ); diff --git a/src/core/org/luaj/vm2/compiler/LexState.java b/src/core/org/luaj/vm2/compiler/LexState.java index 0192de05..c3a64b16 100644 --- a/src/core/org/luaj/vm2/compiler/LexState.java +++ b/src/core/org/luaj/vm2/compiler/LexState.java @@ -170,7 +170,7 @@ public class LexState extends Constants { static { for ( int i=0; i Date: Tue, 14 Jun 2022 22:29:41 +0200 Subject: [PATCH 04/26] build.xml: includeantruntime="false" appended to javac tasks in order to ensure repeatable builds by ant --- build.xml | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/build.xml b/build.xml index 8fa8b0f9..ad6de20d 100644 --- a/build.xml +++ b/build.xml @@ -93,17 +93,23 @@ classpath="lib/bcel-5.2.jar" debug="on" srcdir="build/jse/src" - excludes="**/script/*,**/Lua2Java*,**/server/*,lua*"/> + excludes="**/script/*,**/Lua2Java*,**/server/*,lua*" + includeantruntime="false" + /> + includes="**/script/*,**/Lua2Java*,**/server/*" + includeantruntime="false" + /> + includes="lua*" + includeantruntime="false" + /> -- 2.49.1 From 1aa90eb7fabacaafe0e7734a33215339d5ef9bc8 Mon Sep 17 00:00:00 2001 From: Fabrice Ducos Date: Tue, 14 Jun 2022 22:39:35 +0200 Subject: [PATCH 05/26] 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. --- src/core/org/luaj/vm2/lib/CoroutineLib.java | 24 ++++++++++----------- 1 file changed, 12 insertions(+), 12 deletions(-) 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); -- 2.49.1 From bfb7da97cf6442dec015b58012c08376c9e195bb Mon Sep 17 00:00:00 2001 From: Fabrice Ducos Date: Wed, 15 Jun 2022 01:09:05 +0200 Subject: [PATCH 06/26] luaj: new command for invoking the luaj interpreter --- luaj | 3 +++ 1 file changed, 3 insertions(+) create mode 100755 luaj 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 "$@" -- 2.49.1 From 3c863714b43c08be7fb3c2ba95fa26de728daf19 Mon Sep 17 00:00:00 2001 From: Fabrice Ducos Date: Wed, 15 Jun 2022 01:10:13 +0200 Subject: [PATCH 07/26] 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) --- src/core/org/luaj/vm2/compiler/LexState.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/org/luaj/vm2/compiler/LexState.java b/src/core/org/luaj/vm2/compiler/LexState.java index c3a64b16..cf15e8e0 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; } } -- 2.49.1 From c09d65287477ae7f04402f9b5d4da8043062a2d3 Mon Sep 17 00:00:00 2001 From: Fabrice Ducos Date: Wed, 15 Jun 2022 07:12:36 +0200 Subject: [PATCH 08/26] luaj ported to Windows with the name luaj.bat --- luaj.bat | 3 +++ 1 file changed, 3 insertions(+) create mode 100755 luaj.bat 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 %* -- 2.49.1 From 7aa0389f6fc58cc3b745a382e0b04e960830f876 Mon Sep 17 00:00:00 2001 From: Fabrice Ducos Date: Wed, 15 Jun 2022 07:14:27 +0200 Subject: [PATCH 09/26] README.md updated --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index eb24483d..e0e65b51 100644 --- a/README.md +++ b/README.md @@ -22,6 +22,9 @@ It is now possible to build the jse target alone with: `ant jar-jse` The `jar-jme` target from 3.0.2 will be left unchanged 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
-- 2.49.1 From 970cfc579ac430d170daa8b3c5af06b39cd7ebbe Mon Sep 17 00:00:00 2001 From: Fabrice Ducos Date: Sun, 23 Apr 2023 11:58:52 +0200 Subject: [PATCH 10/26] .gitignore: .java-version added (a .jenv configuration file) --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index d7642856..e9cc7bb8 100644 --- a/.gitignore +++ b/.gitignore @@ -13,3 +13,4 @@ jit/ *.zip docs *.0 +.java-version -- 2.49.1 From 393cf2377540c9190233bf329e913a95bcb89cd0 Mon Sep 17 00:00:00 2001 From: Fabrice Ducos Date: Sun, 23 Apr 2023 12:00:20 +0200 Subject: [PATCH 11/26] build.xml: includeantruntime="false" added to javac Reference: https://stackoverflow.com/questions/5103384/ant-warning-includeantruntime-was-not-set --- build.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.xml b/build.xml index ad6de20d..d60b6535 100644 --- a/build.xml +++ b/build.xml @@ -51,7 +51,7 @@ - -- 2.49.1 From ee08260ce278b4edacaef5232b5da336e987dd21 Mon Sep 17 00:00:00 2001 From: Fabrice Ducos Date: Sun, 23 Apr 2023 12:07:40 +0200 Subject: [PATCH 12/26] build-applet.xml, build-midlet.xml: source and target of javac upgraded from 1.2, 1.3 or 1.4 to 1.8 --- build-applet.xml | 2 +- build-midlet.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/build-applet.xml b/build-applet.xml index d27b4420..86c12b4a 100644 --- a/build-applet.xml +++ b/build-applet.xml @@ -33,7 +33,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 @@ - -- 2.49.1 From 33b64280315eedac0dc7db653263209065800423 Mon Sep 17 00:00:00 2001 From: Fabrice Ducos Date: Sun, 23 Apr 2023 12:19:04 +0200 Subject: [PATCH 13/26] grammar/LuaParser.jj, grammer/Lua5[12].jj: JDK_VERSION upgraded from 1.3 to 1.8 --- grammar/Lua51.jj | 2 +- grammar/Lua52.jj | 2 +- grammar/LuaParser.jj | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) 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; -- 2.49.1 From a40e6862f4a27147de163c1d4ba843d749c1697f Mon Sep 17 00:00:00 2001 From: Fabrice Ducos Date: Sun, 23 Apr 2023 12:24:58 +0200 Subject: [PATCH 14/26] build-applet.xml: -target 1.4 -> -target 1.8 -> --- build-applet.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/build-applet.xml b/build-applet.xml index 86c12b4a..9d019f9f 100644 --- a/build-applet.xml +++ b/build-applet.xml @@ -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' > - + -- 2.49.1 From 8df7dd717c77f9d27145b52da971393d0d796efb Mon Sep 17 00:00:00 2001 From: Fabrice Ducos Date: Sun, 23 Apr 2023 12:27:47 +0200 Subject: [PATCH 15/26] build-coverage.xml: javac target="1.5" -> target="1.8" --- build-coverage.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 @@ - + -- 2.49.1 From 2207f7f2e2dc3057d77abdb6afa354c5e0023524 Mon Sep 17 00:00:00 2001 From: Fabrice Ducos Date: Sun, 23 Apr 2023 12:58:56 +0200 Subject: [PATCH 16/26] src/core/org/luaj/vm2/compiler/FuncState.java: Replaced the deprecated, non generic Hashtable with generic Map (interface) and HashMap (implementation) Hashtable h -> Map h this.h = new Hashtable() -> this.h = new HashMap<>() --- src/core/org/luaj/vm2/compiler/FuncState.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/core/org/luaj/vm2/compiler/FuncState.java b/src/core/org/luaj/vm2/compiler/FuncState.java index 98534d50..049c60c2 100644 --- a/src/core/org/luaj/vm2/compiler/FuncState.java +++ b/src/core/org/luaj/vm2/compiler/FuncState.java @@ -21,7 +21,8 @@ ******************************************************************************/ package org.luaj.vm2.compiler; -import java.util.Hashtable; +import java.util.Map; +import java.util.HashMap; import org.luaj.vm2.LocVars; import org.luaj.vm2.Lua; @@ -47,7 +48,7 @@ public class FuncState extends Constants { }; Prototype f; /* current function header */ - Hashtable h; /* table to find (and reuse) elements in `k' */ + Map h; /* table to find (and reuse) elements in `k' */ FuncState prev; /* enclosing function */ LexState ls; /* lexical state */ BlockCnt bl; /* chain of current blocks */ @@ -474,7 +475,7 @@ public class FuncState extends Constants { } int addk(LuaValue v) { if (this.h == null) { - this.h = new Hashtable(); + this.h = new HashMap<>(); } else if (this.h.containsKey(v)) { return ((Integer) h.get(v)).intValue(); } -- 2.49.1 From b0df2ddcb01f96e9f8228554d417167891a392de Mon Sep 17 00:00:00 2001 From: Fabrice Ducos Date: Sun, 23 Apr 2023 13:44:20 +0200 Subject: [PATCH 17/26] build.xml: default task is now "jar-jse" instead of "all" --- build.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.xml b/build.xml index d60b6535..4fa4b6bc 100644 --- a/build.xml +++ b/build.xml @@ -1,4 +1,4 @@ - + -- 2.49.1 From f680cce33601b9e1f098077b28185f7d58942e7e Mon Sep 17 00:00:00 2001 From: Fabrice Ducos Date: Sun, 23 Apr 2023 13:46:38 +0200 Subject: [PATCH 18/26] README.md updated --- README.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/README.md b/README.md index e0e65b51..2965c8e9 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,10 @@ # This is a fork! +Compile with: `ant` or `ant jar-jse` + +There is no guarantee that `ant all` still compiles for the moment +(though that may be fixed in a future version). + 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. -- 2.49.1 From f364bb0189f5c424fc02f76495c572ebcd9ec331 Mon Sep 17 00:00:00 2001 From: Fabrice Ducos Date: Sun, 23 Apr 2023 13:49:16 +0200 Subject: [PATCH 19/26] README.md updated --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index 2965c8e9..b79e7ac3 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,10 @@ Compile with: `ant` or `ant jar-jse` +Then test with: `./luaj` + +(or `luaj.bat` on Windows) + There is no guarantee that `ant all` still compiles for the moment (though that may be fixed in a future version). -- 2.49.1 From 1b8d7c7485a18bd9fbe0c2341a092c487d034a5c Mon Sep 17 00:00:00 2001 From: Fabrice Ducos Date: Sun, 23 Apr 2023 14:08:03 +0200 Subject: [PATCH 20/26] README.md updated --- README.md | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index b79e7ac3..1073e889 100644 --- a/README.md +++ b/README.md @@ -2,12 +2,17 @@ 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) -There is no guarantee that `ant all` still compiles for the moment -(though that may be fixed in a future version). +If you need JME support (Java Micro Edition, specifically for mobiles), +this fork is not recommend. + +You can try `ant all` or `ant jar-jme`, but there is no no guarantee that it +will even compile (though that may be fixed in a future version). This fork aims to fix some issues met with luaj 3.0.2, still present in [luaj/luaj](https://github.com/luaj/luaj) at -- 2.49.1 From 113c3a9b974e10e1c6b93e0ed0e0a2ba1fdff7a5 Mon Sep 17 00:00:00 2001 From: Fabrice Ducos Date: Sun, 23 Apr 2023 14:16:41 +0200 Subject: [PATCH 21/26] README.md updated --- README.md | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 1073e889..9b6df64a 100644 --- a/README.md +++ b/README.md @@ -9,9 +9,9 @@ Then test with: `./luaj` (or `luaj.bat` on Windows) If you need JME support (Java Micro Edition, specifically for mobiles), -this fork is not recommend. +this fork is not recommended. -You can try `ant all` or `ant jar-jme`, but there is no no guarantee that it +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). This fork aims to fix some issues met with luaj 3.0.2, still present in @@ -19,13 +19,7 @@ This fork aims to fix some issues met with luaj 3.0.2, still present in 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. Issuing the `ant` command will fail -with the following error: - -``` -[javac] error: Source option 1.3 is no longer supported. Use 7 or later. -[javac] error: Target option 1.2 is no longer supported. Use 7 or later. -``` +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 @@ -33,7 +27,7 @@ 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 will be left unchanged until contributors +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` -- 2.49.1 From 65a5088092a6dc28aa12945d7804a34a92227e03 Mon Sep 17 00:00:00 2001 From: Fabrice Ducos Date: Sun, 23 Apr 2023 14:40:20 +0200 Subject: [PATCH 22/26] src/core/org/luaj/vm2/compiler/FuncState.java: reverted changed from generic HashMap to non generic Hashtable for JME portability --- src/core/org/luaj/vm2/compiler/FuncState.java | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/core/org/luaj/vm2/compiler/FuncState.java b/src/core/org/luaj/vm2/compiler/FuncState.java index 049c60c2..98534d50 100644 --- a/src/core/org/luaj/vm2/compiler/FuncState.java +++ b/src/core/org/luaj/vm2/compiler/FuncState.java @@ -21,8 +21,7 @@ ******************************************************************************/ package org.luaj.vm2.compiler; -import java.util.Map; -import java.util.HashMap; +import java.util.Hashtable; import org.luaj.vm2.LocVars; import org.luaj.vm2.Lua; @@ -48,7 +47,7 @@ public class FuncState extends Constants { }; Prototype f; /* current function header */ - Map h; /* table to find (and reuse) elements in `k' */ + Hashtable h; /* table to find (and reuse) elements in `k' */ FuncState prev; /* enclosing function */ LexState ls; /* lexical state */ BlockCnt bl; /* chain of current blocks */ @@ -475,7 +474,7 @@ public class FuncState extends Constants { } int addk(LuaValue v) { if (this.h == null) { - this.h = new HashMap<>(); + this.h = new Hashtable(); } else if (this.h.containsKey(v)) { return ((Integer) h.get(v)).intValue(); } -- 2.49.1 From 3fad81709950d7da3803f56f29ea4b8acf32d991 Mon Sep 17 00:00:00 2001 From: Fabrice Ducos Date: Sun, 23 Apr 2023 15:03:15 +0200 Subject: [PATCH 23/26] New file TODO --- README.md | 1 + TODO | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+) create mode 100644 TODO diff --git a/README.md b/README.md index 9b6df64a..7c89c36a 100644 --- a/README.md +++ b/README.md @@ -13,6 +13,7 @@ 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 diff --git a/TODO b/TODO new file mode 100644 index 00000000..d8ed0e6f --- /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 replaced 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. -- 2.49.1 From 91735791f07362910deaa1fc742006664d984852 Mon Sep 17 00:00:00 2001 From: Fabrice Ducos Date: Sun, 23 Apr 2023 15:04:55 +0200 Subject: [PATCH 24/26] TODO: fixed a typo --- TODO | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/TODO b/TODO index d8ed0e6f..1df866ac 100644 --- a/TODO +++ b/TODO @@ -10,7 +10,7 @@ with java.lang.StringBuilder Unfortunately, this class is not available in the JME environment. -A workaround would be to replaced the + concatenation with the String.concat() method, like this: +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())); } -- 2.49.1 From e54b0c3d576630ec8137a227bffcfb68ab3ea5af Mon Sep 17 00:00:00 2001 From: Fabrice Ducos Date: Mon, 24 Apr 2023 02:01:16 +0200 Subject: [PATCH 25/26] 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)) --- src/core/org/luaj/vm2/compiler/FuncState.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/org/luaj/vm2/compiler/FuncState.java b/src/core/org/luaj/vm2/compiler/FuncState.java index 98534d50..70e0f885 100644 --- a/src/core/org/luaj/vm2/compiler/FuncState.java +++ b/src/core/org/luaj/vm2/compiler/FuncState.java @@ -479,7 +479,7 @@ public class FuncState extends Constants { return ((Integer) h.get(v)).intValue(); } final int idx = this.nk; - this.h.put(v, Integer.valueOf(idx)); + this.h.put(v, new Integer(idx)); final Prototype f = this.f; if (f.k == null || nk + 1 >= f.k.length) f.k = realloc( f.k, nk*2 + 1 ); -- 2.49.1 From 12ef7015953075e461d4cbc8329970c4652e8434 Mon Sep 17 00:00:00 2001 From: Fabrice Ducos Date: Mon, 24 Apr 2023 02:02:28 +0200 Subject: [PATCH 26/26] 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) --- src/core/org/luaj/vm2/compiler/LexState.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/org/luaj/vm2/compiler/LexState.java b/src/core/org/luaj/vm2/compiler/LexState.java index cf15e8e0..01c3508c 100644 --- a/src/core/org/luaj/vm2/compiler/LexState.java +++ b/src/core/org/luaj/vm2/compiler/LexState.java @@ -170,7 +170,7 @@ public class LexState extends Constants { static { for ( int i=0; i