lua-users home
lua-l archive

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



On 21 Jan 2018, at 12.33, Elias Hogstvedt <eliashogstvedt@gmail.com> wrote:

I don’t get it. Where’s the ambiguity in e. g. { 1, 2, 3, type = ”int16” } ?

I would say it's ambiguous because I'm not sure if this is "safe" to do. I've personally never done this and would put a new table inside the table to hold the numbers. If this has no side effects then it's more or less a shortcut for {array = {1, 2, 3}, type = "int16"} 

It’s totally safe and there’s a similar example in Programming in Lua. Section 3.6 in the 2nd edition (I don’t have the latest edition yet):

polyline = { color=”blue”, thickness=2, npoints=4,
  {x=0, y=0},
  {x=-10, y=0}
  {x=-10, y=1}
  {x=0, y=1}
}

Produces less garbage because there’s no intermediate table to hold the coordinates array.

Petri