ok here are another 2 versions you may find useful
local digits=setmetatable({},{__index=function(t,index) t[index]={".---.",
"| "..index.." |",
"'---'"} return t[index] end})
will add the value to the table in addition to faking it when requested
local digits
do
local tNums={}
digits=setmetatable({},{__index=function(t,index) if tNums[index] then return {".---.",
"| "..index.." |",
"'---'"} end end,__newindex=function(t,index) tNums[index]='.' end,__call=function(t) return pairs(tNums) end})
end
would make a hidden table caled tNums where it stores '.' on certain numbers and those numbers will give you a value, if you want to parse it with pairs do the following
for k,v in digits() do
print(digits[k])
end
DO NOT USE THE 'v' AS IT IS ALWAYS '.'
EDIT: there is an infinitely simpler method as follows
local digits=setmetatable({},{__newindex=function(t,index) rawset(t,index,{".---.",
"| "..index.." |",
"'---'"}) end})
if you try to add any value to the digits table it will automatically modify it to be in the format you showed in the OP
Edited by KaoS, 05 December 2012 - 12:32 AM.