mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2025-02-02 04:09:11 +00:00
Update Cobalt to use Lua 5.2
This commit is contained in:
parent
58d54e2e70
commit
9f251d7b52
@ -77,7 +77,7 @@ dependencies {
|
|||||||
compileOnly("com.google.code.findbugs:jsr305:3.0.2")
|
compileOnly("com.google.code.findbugs:jsr305:3.0.2")
|
||||||
compileOnly("org.jetbrains:annotations:24.0.1")
|
compileOnly("org.jetbrains:annotations:24.0.1")
|
||||||
modImplementation("maven.modrinth:computercraft:1.50")
|
modImplementation("maven.modrinth:computercraft:1.50")
|
||||||
"shade"("org.squiddev:Cobalt")
|
"shade"("cc.tweaked:cobalt")
|
||||||
|
|
||||||
"buildTools"("cc.tweaked.cobalt:build-tools")
|
"buildTools"("cc.tweaked.cobalt:build-tools")
|
||||||
}
|
}
|
||||||
|
@ -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))
|
.errorReporter((e, m) -> CCTweaked.LOG.log(Level.SEVERE, "Error occurred in Lua VM. Execution will continue:\n" + m.get(), e))
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
globals = state.getMainThread().getfenv();
|
globals = state.globals();
|
||||||
|
|
||||||
|
try {
|
||||||
CoreLibraries.debugGlobals(state);
|
CoreLibraries.debugGlobals(state);
|
||||||
Bit32Lib.add(state, globals);
|
Bit32Lib.add(state, globals);
|
||||||
|
|
||||||
globals.rawset("_HOST", valueOf("ComputerCraft " + ComputerCraft.getVersion() + " (" + Loader.instance().getMCVersionString() + ")"));
|
globals.rawset("_HOST", valueOf("ComputerCraft " + ComputerCraft.getVersion() + " (" + Loader.instance().getMCVersionString() + ")"));
|
||||||
globals.rawset("_CC_DEFAULT_SETTINGS", valueOf(""));
|
globals.rawset("_CC_DEFAULT_SETTINGS", valueOf(""));
|
||||||
|
} catch (LuaError e) {
|
||||||
|
throw new IllegalStateException(e.getMessage());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -79,7 +84,7 @@ public class CobaltLuaMachine implements ILuaMachine {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
LuaFunction value = LoadState.load(state, bios, "@bios.lua", globals);
|
LuaFunction value = LoadState.load(state, bios, "@bios.lua", globals);
|
||||||
mainRoutine = new LuaThread(state, value, globals);
|
mainRoutine = new LuaThread(state, value);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
CCTweaked.LOG.log(Level.SEVERE, "Failed to load bios.lua", e);
|
CCTweaked.LOG.log(Level.SEVERE, "Failed to load bios.lua", e);
|
||||||
unload();
|
unload();
|
||||||
@ -207,7 +212,7 @@ public class CobaltLuaMachine implements ILuaMachine {
|
|||||||
return table;
|
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 == null) return Constants.NIL;
|
||||||
if (object instanceof Number) return valueOf(((Number) object).doubleValue());
|
if (object instanceof Number) return valueOf(((Number) object).doubleValue());
|
||||||
if (object instanceof Boolean) return valueOf((Boolean) object);
|
if (object instanceof Boolean) return valueOf((Boolean) object);
|
||||||
@ -260,7 +265,7 @@ public class CobaltLuaMachine implements ILuaMachine {
|
|||||||
return Constants.NIL;
|
return Constants.NIL;
|
||||||
}
|
}
|
||||||
|
|
||||||
Varargs toValues(Object[] objects) {
|
Varargs toValues(Object[] objects) throws LuaError {
|
||||||
if (objects == null || objects.length == 0) return Constants.NONE;
|
if (objects == null || objects.length == 0) return Constants.NONE;
|
||||||
|
|
||||||
Map<Object, LuaValue> result = new IdentityHashMap<>(0);
|
Map<Object, LuaValue> result = new IdentityHashMap<>(0);
|
||||||
|
@ -18,44 +18,8 @@ do
|
|||||||
expect = f().expect
|
expect = f().expect
|
||||||
end
|
end
|
||||||
|
|
||||||
if _VERSION == "Lua 5.1" then
|
-- Inject a stub for the old bit library
|
||||||
-- 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
|
_G.bit = {
|
||||||
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,
|
bnot = bit32.bnot,
|
||||||
band = bit32.band,
|
band = bit32.band,
|
||||||
bor = bit32.bor,
|
bor = bit32.bor,
|
||||||
@ -63,13 +27,11 @@ if _VERSION == "Lua 5.1" then
|
|||||||
brshift = bit32.arshift,
|
brshift = bit32.arshift,
|
||||||
blshift = bit32.lshift,
|
blshift = bit32.lshift,
|
||||||
blogic_rshift = bit32.rshift,
|
blogic_rshift = bit32.rshift,
|
||||||
}
|
}
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Install lua parts of the os api
|
-- Install lua parts of the os api
|
||||||
function os.version()
|
function os.version()
|
||||||
return "CraftOS 1.8"
|
return "CraftOS 1.9"
|
||||||
end
|
end
|
||||||
|
|
||||||
function os.pullEventRaw(sFilter)
|
function os.pullEventRaw(sFilter)
|
||||||
|
2
vendor/Cobalt
vendored
2
vendor/Cobalt
vendored
@ -1 +1 @@
|
|||||||
Subproject commit 6b0d2e234ebbfb1ffd20cde071ecd4c782be6da1
|
Subproject commit 6536189750811a301cff560099dc2ce4ad34316e
|
Loading…
Reference in New Issue
Block a user