Created
October 23, 2014 18:36
-
-
Save sclark39/469ca5a1fc136004a9a3 to your computer and use it in GitHub Desktop.
Lock Constants
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function LockConstants() | |
local ks = {} | |
for k,v in pairs( _G ) do | |
if k:sub( 1, 1 ) == 'k' then | |
ks[k] = v | |
_G[k] = nil | |
end | |
end | |
setmetatable( _G, { | |
__index = ks; | |
__newindex = function( t, k, v ) | |
if string.starts( k, "k" ) then | |
error( "Attempt to create or modify constant after lock" ) | |
end | |
rawset(t,k,v) | |
end; | |
} ) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment