lua-users home
lua-l archive

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




On 2017-09-27 04:01 AM, Sean Conner wrote:
It was thus said that the Great hz . once stated:
hi,

Is there a way to init table field as:

tbl = {
  a = ‘aaa’,
  b = a,
}

where b is inited as ‘aaa’?

Or what’s the most simple approach to do this.
   Umm ...

	tbl =
	{
	  a = 'aaa'
	}

	tbl.b = tbl.a -- ?

	tbl = {}
	tbl.a = 'aaa'
	tbl.b = tbl.a -- ?

   -spc

tbl = {}
do local _ENV = tbl
  a = 'aaa'
  b = a
  -- be careful with accidentally assigning to a local, however.
end

--
Disclaimer: these emails may be made public at any given time, with or without reason. If you don't agree with this, DO NOT REPLY.