mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2025-08-31 01:27:55 +00:00
Strict Globals (#583)
This commit is contained in:
@@ -344,3 +344,9 @@ Cleanup examples for the various modules
|
|||||||
|
|
||||||
Ignored Documentation Changes, these are locate
|
Ignored Documentation Changes, these are locate
|
||||||
```
|
```
|
||||||
|
|
||||||
|
```
|
||||||
|
9a749642d294506095e697a3a4345dfe260bd68c
|
||||||
|
|
||||||
|
Strict Globals (#583)
|
||||||
|
```
|
||||||
|
@@ -523,6 +523,16 @@ function os.run(_tEnv, _sPath, ...)
|
|||||||
|
|
||||||
local tEnv = _tEnv
|
local tEnv = _tEnv
|
||||||
setmetatable(tEnv, { __index = _G })
|
setmetatable(tEnv, { __index = _G })
|
||||||
|
|
||||||
|
if settings.get("bios.strict_globals", false) then
|
||||||
|
-- load will attempt to set _ENV on this environment, which
|
||||||
|
-- throws an error with this protection enabled. Thus we set it here first.
|
||||||
|
tEnv._ENV = tEnv
|
||||||
|
getmetatable(tEnv).__newindex = function(_, name)
|
||||||
|
error("Attempt to create global " .. tostring(name), 2)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
local fnFile, err = loadfile(_sPath, nil, tEnv)
|
local fnFile, err = loadfile(_sPath, nil, tEnv)
|
||||||
if fnFile then
|
if fnFile then
|
||||||
local ok, err = pcall(fnFile, ...)
|
local ok, err = pcall(fnFile, ...)
|
||||||
@@ -954,6 +964,11 @@ settings.define("lua.function_source", {
|
|||||||
description = "Show where a function was defined when printing functions.",
|
description = "Show where a function was defined when printing functions.",
|
||||||
type = "boolean",
|
type = "boolean",
|
||||||
})
|
})
|
||||||
|
settings.define("bios.strict_globals", {
|
||||||
|
default = false,
|
||||||
|
description = "Prevents assigning variables into a program's environment. Make sure you use the local keyword or assign to _G explicitly.",
|
||||||
|
type = "boolean",
|
||||||
|
})
|
||||||
|
|
||||||
if term.isColour() then
|
if term.isColour() then
|
||||||
settings.define("bios.use_multishell", {
|
settings.define("bios.use_multishell", {
|
||||||
|
Reference in New Issue
Block a user