local PowerOfTwo = {}
function PowerOfTwo.new()
return setmetatable({}, PowerOfTwo)
end
-- The table is empty: every index is missing
-- and goes to __index
function PowerOfTwo.__index(_, i)
return 1 << i
end
local power2 = PowerOfTwo.new()
local p2 = power2[2]
-- p2 = 4
local p8 = power2[8]
-- p8 = 256
local p16 = power2[16]
-- p16 = 65536
print("p2 = " .. p2)
print("p8 = " .. p8)
print("p16 = " .. p16)