lua-users home
lua-l archive

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




On 2018-03-15 03:47 PM, Roberto Ierusalimschy wrote:

On 2018-03-14 11:35 AM, Roberto Ierusalimschy wrote:
2018-03-14 12:43 GMT+03:00 Daurnimator <quae@daurnimator.com>:
On 14 March 2018 at 20:38, Sergey Zakharchenko <doublef.mobile@gmail.com> wrote:
No metamethod calls occur for the undef assignment and check. This
doesn't seem right.
I think I saw a __undef introduced?
How would the supposed backwards compatibility be kept if existing
code doesn't define __undef/__isdef?
You are right. We still do not get full backwards compatibility, because
of metamethods. We will try to correct it.
For __newindex = check if select("#", ...) == 2 instead of == 3
We thought about that, but it is kind of ugly this use of varargs and
select. Maybe a fourth parameter?

Allow undef to test varargs:

function __newindex(t, k, ...)
  if ... == undef then -- check if there are any vargs
    -- none
  else
    rawset(t, k, ...)
  end
end

This would also have some interesting properties when the sandbox you're using doesn't have select because some asshole didn't put it in:

function table.pack(...)
  local function pop(_, ...)
    return ...
  end
  local function inner(t, ...)
    if ... == undef then return t end
    t.n = t.n + 1
    t[t.n] = ...
    return inner(t, pop(...))
  end
  inner({n=0}, ...)
end



For __index = check if select("#", __index()) == 0 instead of == 1?

Rather than having __isundef or w/e, use the return value of __index:

if it returns nil, it's nil. if it returns nothing, it's undef.

E.g.

function __index(t, k)
  if k == "nothere" then
    return
  else
    return nil
end

??

-- Roberto


--
Disclaimer: these emails may be made public at any given time, with or without reason. If you don't agree with this, DO NOT REPLY.