From 3ace49d27fd6f583e25462a6fae136d45aaac89f Mon Sep 17 00:00:00 2001 From: Jonathan Coates Date: Tue, 22 Jun 2021 20:58:35 +0100 Subject: [PATCH] Remove config option for debug API And also remove the "is present" guards within the various APIs. I'm happy at this point that debug is safe, and think we can guarantee its presence. --- src/main/java/dan200/computercraft/ComputerCraft.java | 1 - .../dan200/computercraft/core/lua/CobaltLuaMachine.java | 2 +- src/main/java/dan200/computercraft/shared/Config.java | 6 ------ .../data/computercraft/lua/rom/modules/main/cc/expect.lua | 6 ++---- .../data/computercraft/lua/rom/modules/main/cc/pretty.lua | 3 +-- 5 files changed, 4 insertions(+), 14 deletions(-) diff --git a/src/main/java/dan200/computercraft/ComputerCraft.java b/src/main/java/dan200/computercraft/ComputerCraft.java index a51773124..440b4e5cd 100644 --- a/src/main/java/dan200/computercraft/ComputerCraft.java +++ b/src/main/java/dan200/computercraft/ComputerCraft.java @@ -36,7 +36,6 @@ public final class ComputerCraft public static int maximumFilesOpen = 128; public static boolean disableLua51Features = false; public static String defaultComputerSettings = ""; - public static boolean debugEnable = true; public static boolean logComputerErrors = true; public static boolean commandRequireCreative = true; diff --git a/src/main/java/dan200/computercraft/core/lua/CobaltLuaMachine.java b/src/main/java/dan200/computercraft/core/lua/CobaltLuaMachine.java index 07cb1e923..c6b2932e7 100644 --- a/src/main/java/dan200/computercraft/core/lua/CobaltLuaMachine.java +++ b/src/main/java/dan200/computercraft/core/lua/CobaltLuaMachine.java @@ -97,7 +97,7 @@ public CobaltLuaMachine( Computer computer, TimeoutState timeout ) globals.load( state, new CoroutineLib() ); globals.load( state, new Bit32Lib() ); globals.load( state, new Utf8Lib() ); - if( ComputerCraft.debugEnable ) globals.load( state, new DebugLib() ); + globals.load( state, new DebugLib() ); // Remove globals we don't want to expose globals.rawset( "collectgarbage", Constants.NIL ); diff --git a/src/main/java/dan200/computercraft/shared/Config.java b/src/main/java/dan200/computercraft/shared/Config.java index 121a8f882..4fb4f2c7d 100644 --- a/src/main/java/dan200/computercraft/shared/Config.java +++ b/src/main/java/dan200/computercraft/shared/Config.java @@ -42,7 +42,6 @@ public final class Config private static final ConfigValue maximumFilesOpen; private static final ConfigValue disableLua51Features; private static final ConfigValue defaultComputerSettings; - private static final ConfigValue debugEnabled; private static final ConfigValue logComputerErrors; private static final ConfigValue commandRequireCreative; @@ -120,10 +119,6 @@ private Config() {} "autocompletion" ) .define( "default_computer_settings", ComputerCraft.defaultComputerSettings ); - debugEnabled = builder - .comment( "Enable Lua's debug library. This is sandboxed to each computer, so is generally safe to be used by players." ) - .define( "debug_enabled", ComputerCraft.debugEnable ); - logComputerErrors = builder .comment( "Log exceptions thrown by peripherals and other Lua objects.\n" + "This makes it easier for mod authors to debug problems, but may result in log spam should people use buggy methods." ) @@ -317,7 +312,6 @@ public static void sync() ComputerCraft.maximumFilesOpen = maximumFilesOpen.get(); ComputerCraft.disableLua51Features = disableLua51Features.get(); ComputerCraft.defaultComputerSettings = defaultComputerSettings.get(); - ComputerCraft.debugEnable = debugEnabled.get(); ComputerCraft.computerThreads = computerThreads.get(); ComputerCraft.logComputerErrors = logComputerErrors.get(); ComputerCraft.commandRequireCreative = commandRequireCreative.get(); diff --git a/src/main/resources/data/computercraft/lua/rom/modules/main/cc/expect.lua b/src/main/resources/data/computercraft/lua/rom/modules/main/cc/expect.lua index 877fa0476..9c93dc7d6 100644 --- a/src/main/resources/data/computercraft/lua/rom/modules/main/cc/expect.lua +++ b/src/main/resources/data/computercraft/lua/rom/modules/main/cc/expect.lua @@ -51,10 +51,8 @@ local function expect(index, value, ...) -- If we can determine the function name with a high level of confidence, try to include it. local name - if native_type(debug) == "table" and native_type(debug.getinfo) == "function" then - local ok, info = pcall(debug.getinfo, 3, "nS") - if ok and info.name and info.name ~= "" and info.what ~= "C" then name = info.name end - end + local ok, info = pcall(debug.getinfo, 3, "nS") + if ok and info.name and info.name ~= "" and info.what ~= "C" then name = info.name end local type_names = get_type_names(...) if name then diff --git a/src/main/resources/data/computercraft/lua/rom/modules/main/cc/pretty.lua b/src/main/resources/data/computercraft/lua/rom/modules/main/cc/pretty.lua index 9cd8410c7..37b691505 100644 --- a/src/main/resources/data/computercraft/lua/rom/modules/main/cc/pretty.lua +++ b/src/main/resources/data/computercraft/lua/rom/modules/main/cc/pretty.lua @@ -28,8 +28,7 @@ local expect = require "cc.expect" local expect, field = expect.expect, expect.field local type, getmetatable, setmetatable, colours, str_write, tostring = type, getmetatable, setmetatable, colours, write, tostring -local debug_info = type(debug) == "table" and type(debug.getinfo) == "function" and debug.getinfo -local debug_local = type(debug) == "table" and type(debug.getlocal) == "function" and debug.getlocal +local debug_info, debug_local = debug.getinfo, debug.getlocal --- @{table.insert} alternative, but with the length stored inline. local function append(out, value)