lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


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