Skip to content

Instantly share code, notes, and snippets.

@sclark39
Created October 23, 2014 18:36
Show Gist options
  • Save sclark39/469ca5a1fc136004a9a3 to your computer and use it in GitHub Desktop.
Save sclark39/469ca5a1fc136004a9a3 to your computer and use it in GitHub Desktop.
Lock Constants
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