Skip to content

Instantly share code, notes, and snippets.

@akirayu101
Created December 2, 2014 11:11
Show Gist options
  • Save akirayu101/a808b102348185fa02ba to your computer and use it in GitHub Desktop.
Save akirayu101/a808b102348185fa02ba to your computer and use it in GitHub Desktop.
a = {}
a["__realdata"] = {}
a["__realdata"]["a"] = 1 -- save const a
a["__realdata"]["b"] = 2 -- save const b
local function const_index(o, key) return o["__realdata"][key] end
local function const_newindex(o, key, value) return end
setmetatable(a, {__index = const_index, __newindex = const_newindex})
print(a["a"])
print(a["b"])
a["a"] = 3
a["b"] = 4
print(a["a"])
print(a["b"])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment