Skip to content

Commit

Permalink
Bump Cobalt to 0.8
Browse files Browse the repository at this point in the history
Not on my maven right now as it's still a snapshot build.
  • Loading branch information
SquidDev committed Oct 25, 2023
1 parent b2f314d commit 7f42bd5
Show file tree
Hide file tree
Showing 11 changed files with 40 additions and 66 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ java {
repositories {
mavenCentral()

mavenLocal {
content {
includeModule("org.squiddev", "Cobalt")
}
}

val mainMaven = maven("https://squiddev.cc/maven") {
name = "SquidDev"
content {
Expand All @@ -57,7 +63,6 @@ repositories {

filter {
includeGroup("cc.tweaked")
includeModule("org.squiddev", "Cobalt")
// Things we mirror
includeGroup("commoble.morered")
includeGroup("dev.architectury")
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ kotlin.jvm.target.validation.mode=error

# Mod properties
isUnstable=false
modVersion=1.108.3
modVersion=1.109.0-SNAPSHOT

# Minecraft properties: We want to configure this here so we can read it in settings.gradle
mcVersion=1.20.1
4 changes: 2 additions & 2 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ parchmentMc = "1.20.1"
asm = "9.5"
autoService = "1.1.1"
checkerFramework = "3.32.0"
cobalt = "0.7.3"
cobalt-next = "0.7.4" # Not a real version, used to constrain the version we accept.
cobalt = "0.8.0-SNAPSHOT"
cobalt-next = "0.8.1" # Not a real version, used to constrain the version we accept.
fastutil = "8.5.9"
guava = "31.1-jre"
jetbrainsAnnotations = "24.0.1"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,20 +73,20 @@ public CobaltLuaMachine(MachineEnvironment environment, InputStream bios) throws
.build();

// Set up our global table.
var globals = state.getMainThread().getfenv();
CoreLibraries.debugGlobals(state);
Bit32Lib.add(state, globals);
globals.rawset("_HOST", ValueFactory.valueOf(environment.hostString()));
globals.rawset("_CC_DEFAULT_SETTINGS", ValueFactory.valueOf(CoreConfig.defaultComputerSettings));
try {
var globals = state.globals();
CoreLibraries.debugGlobals(state);
Bit32Lib.add(state, globals);
globals.rawset("_HOST", ValueFactory.valueOf(environment.hostString()));
globals.rawset("_CC_DEFAULT_SETTINGS", ValueFactory.valueOf(CoreConfig.defaultComputerSettings));

// Add default APIs
for (var api : environment.apis()) addAPI(globals, api);
// Add default APIs
for (var api : environment.apis()) addAPI(globals, api);

// And load the BIOS
try {
// And load the BIOS
var value = LoadState.load(state, bios, "@bios.lua", globals);
mainRoutine = new LuaThread(state, value, globals);
} catch (CompileException e) {
mainRoutine = new LuaThread(state, value);
} catch (LuaError | CompileException e) {
throw new MachineException(Nullability.assertNonNull(e.getMessage()));
}

Expand Down Expand Up @@ -171,7 +171,7 @@ private LuaTable wrapLuaObject(Object object) {
return found ? table : null;
}

private LuaValue toValue(@Nullable Object object, @Nullable IdentityHashMap<Object, LuaValue> values) {
private LuaValue toValue(@Nullable Object object, @Nullable IdentityHashMap<Object, LuaValue> values) throws LuaError {
if (object == null) return Constants.NIL;
if (object instanceof Number num) return ValueFactory.valueOf(num.doubleValue());
if (object instanceof Boolean bool) return ValueFactory.valueOf(bool);
Expand Down Expand Up @@ -235,7 +235,7 @@ private LuaValue toValue(@Nullable Object object, @Nullable IdentityHashMap<Obje
return Constants.NIL;
}

Varargs toValues(@Nullable Object[] objects) {
Varargs toValues(@Nullable Object[] objects) throws LuaError {
if (objects == null || objects.length == 0) return Constants.NONE;
if (objects.length == 1) return toValue(objects[0], null);

Expand Down
29 changes: 1 addition & 28 deletions projects/core/src/main/resources/data/computercraft/lua/bios.lua
Original file line number Diff line number Diff line change
Expand Up @@ -18,33 +18,6 @@ do
expect = f().expect
end

if _VERSION == "Lua 5.1" then
-- If we're on Lua 5.1, install parts of the Lua 5.2/5.3 API so that programs can be written against it
local nativeload = load

function load(x, name, mode, env)
expect(1, x, "function", "string")
expect(2, name, "string", "nil")
expect(3, mode, "string", "nil")
expect(4, env, "table", "nil")

local ok, p1, p2 = pcall(function()
local result, err = nativeload(x, name, mode, env)
if result and env then
env._ENV = env
end
return result, err
end)
if ok then
return p1, p2
else
error(p1, 2)
end
end

loadstring = function(string, chunkname) return nativeload(string, chunkname) end
end

-- Inject a stub for the old bit library
_G.bit = {
bnot = bit32.bnot,
Expand All @@ -58,7 +31,7 @@ _G.bit = {

-- Install lua parts of the os api
function os.version()
return "CraftOS 1.8"
return "CraftOS 1.9"
end

function os.pullEventRaw(sFilter)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# New features in CC: Tweaked 1.109.0-SNAPSHOT

Mistakes.

# New features in CC: Tweaked 1.108.3

Several bug fixes:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
New features in CC: Tweaked 1.108.3
New features in CC: Tweaked 1.109.0-SNAPSHOT

Several bug fixes:
* Fix disconnect when joining a dedicated server.
Mistakes.

Type "help changelog" to see the full version history.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import it.unimi.dsi.fastutil.ints.IntSet;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.squiddev.cobalt.LuaError;
import org.squiddev.cobalt.LuaState;
import org.squiddev.cobalt.Prototype;
import org.squiddev.cobalt.compiler.CompileException;
import org.squiddev.cobalt.compiler.LuaC;
Expand Down Expand Up @@ -108,9 +110,9 @@ private static IntSet getActiveLines(File file) throws IOException {
Queue<Prototype> queue = new ArrayDeque<>();

try (InputStream stream = new FileInputStream(file)) {
var proto = LuaC.compile(stream, "@" + file.getPath());
var proto = LuaC.compile(new LuaState(), stream, "@" + file.getPath());
queue.add(proto);
} catch (CompileException e) {
} catch (LuaError | CompileException e) {
throw new IllegalStateException("Cannot compile", e);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import dan200.computercraft.api.lua.LuaException;
import org.junit.jupiter.api.Test;
import org.squiddev.cobalt.Constants;
import org.squiddev.cobalt.LuaError;
import org.squiddev.cobalt.LuaTable;
import org.squiddev.cobalt.ValueFactory;

Expand All @@ -18,7 +19,11 @@
class VarargArgumentsTest {
private static LuaTable tableWithCustomType() {
var metatable = new LuaTable();
metatable.rawset(Constants.NAME, ValueFactory.valueOf("some type"));
try {
metatable.rawset(Constants.NAME, ValueFactory.valueOf("some type"));
} catch (LuaError e) {
throw new IllegalStateException("Cannot create metatable", e);
}

var table = new LuaTable();
table.setMetatable(null, metatable);
Expand Down
14 changes: 0 additions & 14 deletions projects/core/src/test/resources/test-rom/spec/base_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -79,20 +79,6 @@ describe("The Lua base library", function()
end)

describe("load", function()
it("validates arguments", function()
load("")
load(function()
end)
load("", "")
load("", "", "")
load("", "", "", _ENV)

expect.error(load, nil):eq("bad argument #1 (function or string expected, got nil)")
expect.error(load, "", false):eq("bad argument #2 (string expected, got boolean)")
expect.error(load, "", "", false):eq("bad argument #3 (string expected, got boolean)")
expect.error(load, "", "", "", false):eq("bad argument #4 (table expected, got boolean)")
end)

local function generator(parts)
return coroutine.wrap(function()
for i = 1, #parts do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ describe("The shell", function()
local lines = {}
for i = 1, 5 do lines[i] = win.getLine(i):gsub(" +$", "") end
expect(lines):same {
"CraftOS 1.8",
"CraftOS 1.9",
"> xyz",
"Transferring transfer.txt",
"> xyz",
Expand Down

0 comments on commit 7f42bd5

Please sign in to comment.