lua-users home
lua-l archive

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

On 30-Nov-06, at 10:54 AM, Javier Guerra wrote:

anything [nil]  => nil

currently both forms generate an error, and there's very little hope that it
may change.

Lua 5.1.1  Copyright (C) 1994-2006, PUC-Rio
> return ({})[nil]

-- *Setting* generates the error:
> ({})[nil] = 42
stdin:1: table index is nil
stack traceback:
        stdin:1: in main chunk
        [C]: ?

-- But you can make a table which maps nil onto something other than nil:

> a = setmetatable({}, {__index=function(_, k) if k == nil then return 42 end end})
> =a[42]
> =a[nil]