1
0
mirror of https://github.com/SquidDev-CC/CC-Tweaked synced 2024-06-26 07:03:22 +00:00

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.
This commit is contained in:
Jonathan Coates 2024-01-27 09:59:04 +00:00
parent d38b1d04e7
commit cb25f6c08a
No known key found for this signature in database
GPG Key ID: B9E431FF07C98D06
6 changed files with 7 additions and 73 deletions

View File

@ -21,7 +21,7 @@ # Incompatibilities between 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.

View File

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

View File

@ -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.
* <p>
* 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());
}
}

View File

@ -164,9 +164,7 @@ public void close() {
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;
}

View File

@ -73,7 +73,7 @@ protected Varargs invoke(LuaState state, DebugFrame debugFrame, Varargs args) th
}
@Override
protected Varargs resumeThis(LuaState state, Container container, Varargs args) throws LuaError, UnwindThrowable {
public Varargs resume(LuaState state, Container container, Varargs args) throws LuaError, UnwindThrowable {
MethodResult results;
var arguments = CobaltLuaMachine.toObjects(args);
try {
@ -98,6 +98,6 @@ public static LuaError wrap(LuaException exception, int adjust) {
if (!exception.hasLevel() && adjust == 0) return new LuaError(exception.getMessage());
var level = exception.getLevel();
return new LuaError(exception.getMessage(), level <= 0 ? level : level + adjust + 1);
return new LuaError(exception.getMessage(), level <= 0 ? level : level + adjust);
}
}

View File

@ -67,8 +67,8 @@ public void testExtra() {
public void testPeripheralThrow() {
ComputerBootstrap.run(
"local throw = peripheral.wrap('top')\n" +
"local _, err = pcall(throw.thisThread) assert(err == 'pcall: !', err)\n" +
"local _, err = pcall(throw.mainThread) assert(err == 'pcall: !', err)",
"local _, err = pcall(function() throw.thisThread() end) assert(err == '/test.lua:2: !', (\"thisThread: %q\"):format(err))\n" +
"local _, err = pcall(function() throw.mainThread() end) assert(err == '/test.lua:3: !', (\"mainThread: %q\"):format(err))\n",
x -> x.getEnvironment().setPeripheral(ComputerSide.TOP, new PeripheralThrow()),
50
);