Programming in Lua - 3.6
Programming in Lua - 3.6
Programming in Lua
Part I. The Language
Chapter 3. Expressions
a = {x=0, y=0}
which is equivalent to
x.f = w
print(w["x"]) --> 0
list = nil
end
l = list
while l do
print(l.value)
l = l.next
end
{x=0, y=0},
{x=-10, y=0},
{x=-10, y=1},
{x=0, y=1}
i = 20; s = "-"
{x=0, y=0}
is equivalent to
{["x"]=0, ["y"]=0}
is equivalent to
Such flexibility makes it easier to write programs that generate Lua tables,
because they do not need to handle the last element as a special case.
Finally, you can always use a semicolon instead of a comma in a constructor.
We usually reserve semicolons to delimit
different sections in a constructor,
for instance to separate its list part from its record part: