lua-users home
lua-l archive

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


> Lythoner LY kirjoitti 19.10.2007 kello 14:02:
> > Can I have the above configuration in this model?
> > MYDEF Variable1 { TYPE = BYTE }
Asko Kauppi writes:
> The closest I can think of is:
> MYDEF { Variable1, TYPE = BYTE }

Approach #1:

  BYTE = 1
  function MYDEF(name)
    return function(v) _G[name] = v end
  end
  
  MYDEF 'Variable1' { TYPE = BYTE }
  assert(Variable1.TYPE == BYTE)

Approach #2:

  BYTE = 1
  local mt = {}
  MYDEF = setmetatable({}, mt)
  function mt:__index(name)
    return function(v) _G[name] = v end
  end
  
  MYDEF.Variable1 { TYPE = BYTE }
  assert(Variable1.TYPE == BYTE)

Other possible approaches:

  MYDEF.Variable1 = { TYPE = BYTE }
  MYDEF (Variable1) { TYPE = BYTE }