Kouksi44

Sandboxer

Jan 4th, 2015
404
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.86 KB | None | 0 0
  1. local function iTable(cpTable,newTable,func)
  2.  
  3.   for k,v in pairs(cpTable) do
  4.     if type(v)=="table" then
  5.       newTable[k]={}
  6.       iTable(v,newTable[k],func)
  7.     else
  8.     newTable[k]=func
  9.     end
  10.   end
  11. return newTable
  12.  
  13. end
  14.  
  15. local function blocked(...)
  16.   error("Blocked function!",2)
  17. end
  18.  
  19.  
  20.  
  21. local function getFunc(f)
  22.   if fs.exists(f) then
  23.     fu=fs.open(f,"r")
  24.     funct=fu.readAll()
  25.     fu.close()
  26.     funct=loadstring(funct)
  27.     return funct
  28.   else
  29.   end
  30. end
  31.  
  32.  
  33.  
  34. function setEnvironment(sfunc,blockedFuncs,bFunc)
  35.   if sfunc==nil then
  36.     error("Must be  2 arguments")
  37.   end
  38.   bErr=bFunc or blocked
  39. if type(sfunc)=="string" then
  40.   func=getFunc(sfunc)
  41. elseif type(sfunc)=="function" then
  42.   func=sfunc
  43. end
  44.  
  45. local env=setmetatable({},{__index=_G})
  46. local nBlocked=iTable(blockedFuncs,env,bErr)
  47.      
  48. setfenv(func,nBlocked)
  49. func()
  50. end
Advertisement
Add Comment
Please, Sign In to add comment