From cb25f6c08a6f1d6b0b0b662c0d4abf2775ae5820 Mon Sep 17 00:00:00 2001 From: Jonathan Coates Date: Sat, 27 Jan 2024 09:59:04 +0000 Subject: [PATCH] Update Cobalt to 0.9.0 - Debug hooks are now correctly called for every function. - Fix several minor inconsistencies with debug.getinfo. - Fix Lua tables being sized incorrectly when created from varargs. --- doc/reference/breaking_changes.md | 2 +- gradle/libs.versions.toml | 2 +- .../computercraft/core/lua/BasicFunction.java | 64 ------------------- .../core/lua/CobaltLuaMachine.java | 4 +- .../core/lua/ResultInterpreterFunction.java | 4 +- .../computercraft/core/asm/MethodTest.java | 4 +- 6 files changed, 7 insertions(+), 73 deletions(-) delete mode 100644 projects/core/src/main/java/dan200/computercraft/core/lua/BasicFunction.java diff --git a/doc/reference/breaking_changes.md b/doc/reference/breaking_changes.md index 22f9c290d..4c3b39fb8 100644 --- a/doc/reference/breaking_changes.md +++ b/doc/reference/breaking_changes.md @@ -21,7 +21,7 @@ of the mod should run fine on later versions. However, some changes to the underlying game, or CC: Tweaked's own internals may break some programs. This page serves as documentation for breaking changes and "gotchas" one should look out for between versions. -## CC: Tweaked 1.109.0 to 1.109.2 {#cct-1.109} +## CC: Tweaked 1.109.0 to 1.109.3 {#cct-1.109} - Update to Lua 5.2: - Support for Lua 5.0's pseudo-argument `arg` has been removed. You should always use `...` for varargs. diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index e0f5b9e96..e1b53a41e 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -25,7 +25,7 @@ slf4j = "2.0.1" asm = "9.6" autoService = "1.1.1" checkerFramework = "3.42.0" -cobalt = "0.8.2" +cobalt = "0.9.0" commonsCli = "1.6.0" jetbrainsAnnotations = "24.1.0" jsr305 = "3.0.2" diff --git a/projects/core/src/main/java/dan200/computercraft/core/lua/BasicFunction.java b/projects/core/src/main/java/dan200/computercraft/core/lua/BasicFunction.java deleted file mode 100644 index 44924be57..000000000 --- a/projects/core/src/main/java/dan200/computercraft/core/lua/BasicFunction.java +++ /dev/null @@ -1,64 +0,0 @@ -// SPDX-FileCopyrightText: 2020 The CC: Tweaked Developers -// -// SPDX-License-Identifier: MPL-2.0 - -package dan200.computercraft.core.lua; - -import dan200.computercraft.api.lua.ILuaContext; -import dan200.computercraft.api.lua.LuaException; -import dan200.computercraft.api.lua.MethodResult; -import dan200.computercraft.core.Logging; -import dan200.computercraft.core.methods.LuaMethod; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.squiddev.cobalt.LuaError; -import org.squiddev.cobalt.LuaState; -import org.squiddev.cobalt.Varargs; -import org.squiddev.cobalt.function.VarArgFunction; - -/** - * An "optimised" version of {@link ResultInterpreterFunction} which is guaranteed to never yield. - *

- * As we never yield, we do not need to push a function to the stack, which removes a small amount of overhead. - */ -class BasicFunction extends VarArgFunction { - private static final Logger LOG = LoggerFactory.getLogger(BasicFunction.class); - private final CobaltLuaMachine machine; - private final LuaMethod method; - private final Object instance; - private final ILuaContext context; - private final String funcName; - - BasicFunction(CobaltLuaMachine machine, LuaMethod method, Object instance, ILuaContext context, String name) { - this.machine = machine; - this.method = method; - this.instance = instance; - this.context = context; - funcName = name; - } - - @Override - public Varargs invoke(LuaState luaState, Varargs args) throws LuaError { - var arguments = VarargArguments.of(args); - MethodResult results; - try { - results = method.apply(instance, context, arguments); - } catch (LuaException e) { - throw wrap(e); - } catch (Throwable t) { - LOG.error(Logging.JAVA_ERROR, "Error calling {} on {}", funcName, instance, t); - throw new LuaError("Java Exception Thrown: " + t, 0); - } finally { - arguments.close(); - } - - if (results.getCallback() != null) { - throw new IllegalStateException("Cannot have a yielding non-yielding function"); - } - return machine.toValues(results.getResult()); - } - - public static LuaError wrap(LuaException exception) { - return exception.hasLevel() ? new LuaError(exception.getMessage()) : new LuaError(exception.getMessage(), exception.getLevel()); - } -} diff --git a/projects/core/src/main/java/dan200/computercraft/core/lua/CobaltLuaMachine.java b/projects/core/src/main/java/dan200/computercraft/core/lua/CobaltLuaMachine.java index ade0cf4d6..0cd736e2d 100644 --- a/projects/core/src/main/java/dan200/computercraft/core/lua/CobaltLuaMachine.java +++ b/projects/core/src/main/java/dan200/computercraft/core/lua/CobaltLuaMachine.java @@ -164,9 +164,7 @@ public class CobaltLuaMachine implements ILuaMachine { private LuaTable wrapLuaObject(Object object) { var table = new LuaTable(); var found = luaMethods.forEachMethod(object, (target, name, method, info) -> - table.rawset(name, info != null && info.nonYielding() - ? new BasicFunction(this, method, target, context, name) - : new ResultInterpreterFunction(this, method, target, context, name))); + table.rawset(name, new ResultInterpreterFunction(this, method, target, context, name))); return found ? table : null; } diff --git a/projects/core/src/main/java/dan200/computercraft/core/lua/ResultInterpreterFunction.java b/projects/core/src/main/java/dan200/computercraft/core/lua/ResultInterpreterFunction.java index 57e09f561..3eaa19b56 100644 --- a/projects/core/src/main/java/dan200/computercraft/core/lua/ResultInterpreterFunction.java +++ b/projects/core/src/main/java/dan200/computercraft/core/lua/ResultInterpreterFunction.java @@ -73,7 +73,7 @@ class ResultInterpreterFunction extends ResumableVarArgFunction x.getEnvironment().setPeripheral(ComputerSide.TOP, new PeripheralThrow()), 50 );