Advertisement
Stiepen

Sandbox

Oct 12th, 2012
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.83 KB | None | 0 0
  1. function createSandbox()
  2.   --local sb_apis_user_wl = {"redstone", "gps", "_VERSION", "keys",}
  3.   local sb_apis_user_bl = {getfenv = true, user = true, KilOS = true}
  4.   local sb_apis_root_bl = {}
  5.  
  6.   local root = user.getName() == "root"
  7.  
  8.   sandbox = {}
  9.  
  10.   if root then
  11.     for k, v in pairs(_G) do
  12.       sandbox[v] = v
  13.     end
  14.   else
  15.     for k, v in pairs(_G) do
  16.       if not sb_apis_user_bl[k] then
  17.         sandbox[v] = _G[v]
  18.       end
  19.     end
  20.  
  21.  
  22.     sandbox.getfenv = function(f)
  23.       return sandbox
  24.     end
  25.    
  26.     sandbox.dofile = function(file)
  27.       local f = loadfile()
  28.       setfenv(f, sandbox)
  29.       f()
  30.     end
  31.    
  32.     sandbox.user = nil
  33.    
  34.     --sandbox.user = {["getName"] = user.getName}
  35.     --for k, v in pairs(user) do write(k..", ") end print()
  36.    
  37.     sandbox._G = sandbox
  38.   end
  39. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement