1
0
mirror of https://github.com/SquidDev-CC/CC-Tweaked synced 2025-02-01 19:59:11 +00:00

Update Cobalt to use Lua 5.2

This commit is contained in:
Jonathan Coates 2024-02-28 10:16:46 +00:00
parent 58d54e2e70
commit 9f251d7b52
No known key found for this signature in database
GPG Key ID: B9E431FF07C98D06
4 changed files with 26 additions and 59 deletions

View File

@ -77,7 +77,7 @@ dependencies {
compileOnly("com.google.code.findbugs:jsr305:3.0.2")
compileOnly("org.jetbrains:annotations:24.0.1")
modImplementation("maven.modrinth:computercraft:1.50")
"shade"("org.squiddev:Cobalt")
"shade"("cc.tweaked:cobalt")
"buildTools"("cc.tweaked.cobalt:build-tools")
}

View File

@ -54,12 +54,17 @@ public class CobaltLuaMachine implements ILuaMachine {
.errorReporter((e, m) -> CCTweaked.LOG.log(Level.SEVERE, "Error occurred in Lua VM. Execution will continue:\n" + m.get(), e))
.build();
globals = state.getMainThread().getfenv();
CoreLibraries.debugGlobals(state);
Bit32Lib.add(state, globals);
globals = state.globals();
globals.rawset("_HOST", valueOf("ComputerCraft " + ComputerCraft.getVersion() + " (" + Loader.instance().getMCVersionString() + ")"));
globals.rawset("_CC_DEFAULT_SETTINGS", valueOf(""));
try {
CoreLibraries.debugGlobals(state);
Bit32Lib.add(state, globals);
globals.rawset("_HOST", valueOf("ComputerCraft " + ComputerCraft.getVersion() + " (" + Loader.instance().getMCVersionString() + ")"));
globals.rawset("_CC_DEFAULT_SETTINGS", valueOf(""));
} catch (LuaError e) {
throw new IllegalStateException(e.getMessage());
}
}
@Override
@ -79,7 +84,7 @@ public class CobaltLuaMachine implements ILuaMachine {
try {
LuaFunction value = LoadState.load(state, bios, "@bios.lua", globals);
mainRoutine = new LuaThread(state, value, globals);
mainRoutine = new LuaThread(state, value);
} catch (Exception e) {
CCTweaked.LOG.log(Level.SEVERE, "Failed to load bios.lua", e);
unload();
@ -207,7 +212,7 @@ public class CobaltLuaMachine implements ILuaMachine {
return table;
}
private LuaValue toValue(Object object, Map<Object, LuaValue> values) {
private LuaValue toValue(Object object, Map<Object, LuaValue> values) throws LuaError {
if (object == null) return Constants.NIL;
if (object instanceof Number) return valueOf(((Number) object).doubleValue());
if (object instanceof Boolean) return valueOf((Boolean) object);
@ -260,7 +265,7 @@ public class CobaltLuaMachine implements ILuaMachine {
return Constants.NIL;
}
Varargs toValues(Object[] objects) {
Varargs toValues(Object[] objects) throws LuaError {
if (objects == null || objects.length == 0) return Constants.NONE;
Map<Object, LuaValue> result = new IdentityHashMap<>(0);

View File

@ -18,58 +18,20 @@ 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
if _CC_DISABLE_LUA51_FEATURES then
-- Remove the Lua 5.1 features that will be removed when we update to Lua 5.2, for compatibility testing.
-- See "disable_lua51_functions" in ComputerCraft.cfg
setfenv = nil
getfenv = nil
loadstring = nil
unpack = nil
math.log10 = nil
table.maxn = nil
else
loadstring = function(string, chunkname) return nativeload(string, chunkname) end
-- Inject a stub for the old bit library
_G.bit = {
bnot = bit32.bnot,
band = bit32.band,
bor = bit32.bor,
bxor = bit32.bxor,
brshift = bit32.arshift,
blshift = bit32.lshift,
blogic_rshift = bit32.rshift,
}
end
end
-- Inject a stub for the old bit library
_G.bit = {
bnot = bit32.bnot,
band = bit32.band,
bor = bit32.bor,
bxor = bit32.bxor,
brshift = bit32.arshift,
blshift = bit32.lshift,
blogic_rshift = bit32.rshift,
}
-- Install lua parts of the os api
function os.version()
return "CraftOS 1.8"
return "CraftOS 1.9"
end
function os.pullEventRaw(sFilter)

2
vendor/Cobalt vendored

@ -1 +1 @@
Subproject commit 6b0d2e234ebbfb1ffd20cde071ecd4c782be6da1
Subproject commit 6536189750811a301cff560099dc2ce4ad34316e