"If a function call is used as the value of an explicit key ({K = F()}, for example), it's adjusted to one return value. If it's used as the value of an implicit integer key, it's only adjusted to one return value if it's not the last thing in the table constructor; if it's the last thing, no adjustment is made."
> function ReturnNothing ()
>> end
> function ReturnThreeVals ()
>> return "x", "y", "z"
>> end
> TblA = {ReturnThreeVals (), ReturnThreeVals()}
> print (TblA[1], TblA[2], TblA[3], TblA[4])
x x y z
> TblC = {ReturnThreeVals (), ReturnNothing ()}
> print (TblC[1], TblC[2], TblC[3], TblC[4])
x nil nil nil
TblC[2] is nil because it is set to the result of ReturnNothing (). 3 and 4 are nil because they were not set.
If a table has a "gap" (a nil in element 1 or later, but not all elements are nil) then the length operator "#" is not defined.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment