This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
mrpoopy345's profile picture

Sentfenv some function not allowed?

Started by mrpoopy345, 03 January 2015 - 02:33 PM
mrpoopy345 #1
Posted 03 January 2015 - 03:33 PM
Hello!
So, from another one of my questions I know that
setfenv(shell.run("MyProgram"),{print=_G.print})
Would set the environment to where only the print function was allowed.
My question is, how would you set the environment to include everything BUT specific functions.
For ex, I want to make every function work except print and fs.create.
How would that be possible?
(Does not necessarily have to use setfenv)
Edited on 03 January 2015 - 02:34 PM
SquidDev #2
Posted 03 January 2015 - 04:10 PM
shell.run does not return a function. You would want to do loadfile(shell.resolveProgram("MyProgram"))


local env = setmetatable({
  print = function(...) error("NOPE", 2) end
}, {__index = getfenv(), __metatable = {}})

evn._G = env

local envFS = setmetatable({
  open = function() error("NOPE", 2) end
}, {__index = getfenv().fs, __metatable = {}})

setfenv(loadfile("thing"), env)()

Sandboxing is hard as I've tried to explain here.