lua-users home
lua-l archive

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




On Mar 7, 2019, at 2:52 AM, Dirk Laurie <dirk.laurie@gmail.com> wrote:

It is not good enough just to say that missing arguments are nil. For
example, the library function table.insert, since
table.insert(tbl,key,nil) and table.insert(tbl,item) do different
things. You really need to know whether that third argument is
actually present.

This function has always been a gentle eye-brow raiser for me to be honest. This whole “nil vs bounds” issue is one area where Lua isn’t as clean as it could be (imho of course). We see it with the perennial issues with table sequences, capturing arguments into tables, enumerating arguments that might be nil etc etc.

While the OP might be pushing things a bit hard, I think he does have a point. LUA_TNONE *is* a slightly odd way to indicate that you are “off the end” of the stack.

As I’ve said before (though Roberto disagreed), “nil” in Lua is subtly overloaded to mean both “no value” and “not present”. In many cases this doesnt make a practical difference, but when it DOES, it can be confusing since the lack of distinction in most cases lulls new users into thinking there IS no difference; witness all the arguments about sequence.

—Tim