1
0
mirror of https://github.com/SquidDev-CC/CC-Tweaked synced 2024-06-23 13:43:22 +00:00

Allow lua REPL to warn about using local variables (#367)

`local varname = value` results in `varname` being inaccessible in
the next REPL input. This is often unintended and can lead to confusing
behaviour. We produce a warning when this occurs.
This commit is contained in:
Lupus590 2020-05-08 16:07:33 +01:00 committed by GitHub
parent 5739285fc2
commit 44062ebd52
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 0 deletions

View File

@ -932,6 +932,11 @@ settings.define("motd.path", {
description = [[The path to load random messages from. Should be a colon (":") separated string of file paths.]],
type = "string",
})
settings.define("lua.warn_against_use_of_local", {
default = true,
description = [[Print a message when input in the Lua REPL starts with the word 'local'. Local variables defined in the Lua REPL are be inaccessable on the next input.]],
type = "boolean",
})
if term.isColour() then
settings.define("bios.use_multishell", {
default = true,

View File

@ -67,6 +67,13 @@ while bRunning do
if s:match("%S") and tCommandHistory[#tCommandHistory] ~= s then
table.insert(tCommandHistory, s)
end
if settings.get("lua.warn_against_use_of_local") and s:match("^%s*local%s+") then
if term.isColour() then
term.setTextColour(colours.yellow)
end
print("local variables from the previous input are inaccessible afterwards. If you want to be able to use a variable across multiple inputs then remove the local keyword.")
term.setTextColour(colours.white)
end
local nForcePrint = 0
local func, e = load(s, "=lua", "t", tEnv)