lua-users home
lua-l archive

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

On Jun 28, 2013, at 3:59 PM, Rena <> wrote:

That sounds like you're describing nil. What difference is there between empty and nil except that one can be stored in a table? That seems a lot more confusing than nil itself.
It can help to rethink how tables work. It's not true that a table can't contain nil - it contains nil in every key that doesn't have something else in it. The problem is that leaves no way to iterate over keys that contain nil, since you'd never know when to stop - there are an infinite number of them in every table.

Wel yes, and really the point here is that nil is somewhat overloaded; it means "nothing" sometimes (such as in return values of functions) and other times means "delete" (as in table key/value pairs). And yes, I get (and really like) the concept of all tables having an infinite number of entries, most of which are nil. "empty", to my mind, is just a value stored as a placeholder so that an array stays an array when it has "holes" .. perhaps what's messing people around is my use of the name "empty" .. perhaps "hole" might be better (? "black hole").

Like I said before, I do think there's benefit to having a single standard "empty" value across the entire Lua state, so that each module doesn't have to have their own - I think this was the main point you intended to make. I just don't see why it needs to be a new "special" type, and not just a global variable created by the standard libraries, just like string and math, pointing to an empty table or userdata.

And that would be perfectly fine too .. it's not really an issue of it having to be baked into the language, it's just a standard that everyone can assume is available. My current work-around is pretty much as you describe; it's a light userdata holding a C (void*)0 pointer. It has all the attributes I need, and it works just fine. But without someone saying "if you need to create an "holding place" within an array, use "xxx", everyone will come up with different ways to do this, and we have chaos. After all, look at the all the different suggestions in this thread; all valid but all different. I'm reminded of the old Adventure game: "You are in a twisty maze of little passages, all different". :)