Advertisement
King0fGamesYami

locked_tables

Sep 17th, 2014
355
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.59 KB | None | 0 0
  1. local function lock( t )
  2.     t.__locked = true
  3.     return setmetatable( {}, {
  4.         __index = t,
  5.         __newindex = function( )
  6.             error( "attempt to modify read only table", 2 )
  7.         end,
  8.         __metatable = false,
  9.     })
  10. end
  11.  
  12. local _rawset = _G.rawset
  13. rawset = function( t, k, v, password )
  14.     if t.__locked then
  15.       error( "attempt to modify read only table", 2 )
  16.     else--#change to else
  17.       return _rawset( t, k, v )
  18.     end
  19. end
  20. _G.rawset = rawset
  21.  
  22. local t = { "hello" }
  23. t = lock( t )
  24. print( t.__locked )
  25. t.__locked = false --#error!
  26. print(t.__locked )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement