Skip to content

Commit 79d6d54

Browse files
committed
Remove usage of getfenv and setfenv
1 parent bf2b162 commit 79d6d54

File tree

4 files changed

+6
-14
lines changed

4 files changed

+6
-14
lines changed

bsrocks/bin/repl.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ preload['bsrocks.env'] = function()
22
return function()
33
return {
44
cleanup = {},
5-
_G = setmetatable({}, {__index = getfenv()})
5+
_G = setmetatable({}, {__index = _ENV})
66
}
77
end
88
end

bsrocks/commands/exec.lua

+3-4
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,12 @@ return {
3535
file = shell.resolve(file)
3636
end
3737

38-
local loaded, msg = loadfile(file)
39-
if not loaded then error(msg, 0) end
40-
4138
local env = env()
4239
local thisEnv = env._G
4340
thisEnv.arg = {[-2] = "/" .. shell.getRunningProgram(), [-1] = "exec", [0] = "/" .. file, ... }
44-
setfenv(loaded, thisEnv)
41+
42+
local loaded, msg = loadfile(file, thisEnv)
43+
if not loaded then error(msg, 0) end
4544

4645
local args = {...}
4746
local success, msg = xpcall(

bsrocks/env/init.lua

+1-6
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,7 @@ return function()
6363

6464
-- Need to set environment
6565
function _G.loadstring(name, chunk)
66-
local result, message = loadstring(name, chunk)
67-
if result then
68-
return setfenv(result, _G)
69-
end
70-
71-
return result, message
66+
return load(name, chunk, nil, _G)
7267
end
7368

7469
-- Customised loadfile function to work with relative files

bsrocks/lib/serialize.lua

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
local function unserialize(text)
2-
local func = assert(loadstring(text, "unserialize"))
3-
42
local table = {}
5-
setfenv(func, table)()
3+
assert(load(text, "unserialize", nil, table))()
64
return table
75
end
86

0 commit comments

Comments
 (0)