[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Setting the __mode metatable field
- From: Mike Pall <mikelu-0501@...>
- Date: Tue, 4 Jan 2005 14:43:57 +0100
Hi,
David Jones wrote:
> t={}
> setmetatable(t,{})
> getmetatable(t).__mode='v'
I think the shortest (and proper) way to do this is:
local t = setmetatable({}, {__mode='v'})
If you have many of these tables it is worth sharing the metatable:
local weakvmeta = {__mode='v'}
local function weakvtable(t) return setmetatable(t or {}, weakvmeta) end
local t1 = weakvtable()
local t2 = weakvtable{foo=a, bar=b} -- example table initializers
...
Bye,
Mike