lua-users home
lua-l archive

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

On Jul 6, 2013, at 10:47 PM, Dirk Laurie <> wrote:

  Tim thinks:
  -  the need for such a value is sufficiently common and uniform to
     justify adding a name and value to the Lua language itself;
  -  using one of the well-known idioms to create a unique value for
     a particular Lua instance is an inadequate workaround.

Not really, I floated the idea that *some* agreed-upon mechanism *might* be useful. I also suggested one (actually two) possible solutions; others have made other suggestions that are equally valid.

To address the well-known idioms:
-- Using empty tables. Works will within a single Lua state, is more awkward across Lua states as marshaling is needed and the table needs to be manufactured in a "safe" haven such as the Registry, and then made available via an API (and if you are doing all this, you might as well fall back on my light userdata, which is less complex and faster).

-- Switch from arrays to manually managed tables of integer keys (or similar), using "n" or some-such meta-managed state to track which "elements" of the pseudo-array are empty. This is fine until you start to wrap higher-level abstractions and want to do things like getter/setting semantics on one of the empty elements, though nil can now do this job if you are careful not to need nil for things like the "nil+error" Lua convention for error handling. There is also of course some performance overhead.