ForeverDev

Untitled

Oct 1st, 2014
268
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.66 KB | None | 0 0
  1. local forbidden = {"unpack", "5"}
  2.  
  3. local contains = function(array, search)
  4.     for index, value in pairs(array) do
  5.         print(index, value)
  6.         if value == search then
  7.             return true
  8.         end
  9.     end
  10.     return false
  11. end
  12.  
  13. setfenv(1, setmetatable({print = print}, {
  14.     __newindex = function(self, key, value)
  15.         if contains(forbidden, value) then
  16.             print("Sandbox: attempt to set " .. key .. " to " .. value .. ", a forbidden " .. type(value) .. "!")
  17.             return rawset(self, key, nil)
  18.         else
  19.             return rawset(self, key, value)
  20.         end
  21.     end,
  22.     __index = function(self, index)
  23.        
  24.     end
  25. }))
  26.  
  27. x = "5"   --> Sandbox: attempt to set x to 5 (a forbidden value)
  28. print(x)  --> nil
Advertisement
Add Comment
Please, Sign In to add comment