[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Suggestion: Deprecate "Attempt to index a nil value" error; instead, return nil or create table
- From: Roberto Ierusalimschy <roberto@...>
- Date: Mon, 2 Mar 2020 11:02:17 -0300
> When writing: automatically assign a single-entry table to each undefined
> variable, with the given index the sole entry. For example, if t is an
> undefined variable, then t[a] = v would be syntactic sugar for t = {[a] =
> v}. Similarly, if t[a][b] is already declared as a table but t[a][b][c] is
> nil, then t[a][b][c][d][e] = v would mean t[a][b][c] = {[d] = {[e] = v}}.
Note that Lua does not index variables, it indexes values. For instance,
in the expression 'f(x).k = 1', if 'f(x)' is nil, there is no variable
to get the new table.
-- Roberto