[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Global Metatables
- From: RJ Russell <russellsprouts2@...>
- Date: Sat, 4 Sep 2010 15:14:55 -0700
In 5.2, I think it would be great if we could set metatables for ALL
tables and ALL functions, much like you can set it for all strings and
all numbers.
If a single table has a metatable that conflicts with the global
metatable, then the single table's metatable trump it.
--Just an example of what it could do:
debug.setmetatable('tables',{
__unm=function(op)
local temp={}
for k,v in pairs(op)do
temp[v]=k
end
return temp
end},
__add=function(a,b)
local temp={}
for k,v in pairs(a)do
temp[k]=v
end
for k,v in pairs(b)do
temp[k]=v
end
end)
--Now, dictionaries are very easy to make:
local dictionary=-{'if','then','else'}
--And you can add tables
local newtab={a=4}+{b=6}