mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2025-01-26 00:46:54 +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:
parent
5739285fc2
commit
44062ebd52
@ -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.]],
|
description = [[The path to load random messages from. Should be a colon (":") separated string of file paths.]],
|
||||||
type = "string",
|
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
|
if term.isColour() then
|
||||||
settings.define("bios.use_multishell", {
|
settings.define("bios.use_multishell", {
|
||||||
default = true,
|
default = true,
|
||||||
|
@ -67,6 +67,13 @@ while bRunning do
|
|||||||
if s:match("%S") and tCommandHistory[#tCommandHistory] ~= s then
|
if s:match("%S") and tCommandHistory[#tCommandHistory] ~= s then
|
||||||
table.insert(tCommandHistory, s)
|
table.insert(tCommandHistory, s)
|
||||||
end
|
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 nForcePrint = 0
|
||||||
local func, e = load(s, "=lua", "t", tEnv)
|
local func, e = load(s, "=lua", "t", tEnv)
|
||||||
|
Loading…
Reference in New Issue
Block a user