Lua 5.4.0 (work1), undef and metatable

classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|

Lua 5.4.0 (work1), undef and metatable

Sergey Zakharchenko
Hello,

I'd like to note that operations with undef seem to ignore metatables:

Lua 5.4.0 (work1)  Copyright (C) 1994-2018 Lua.org, PUC-Rio
> =undef
stdin:1: 'undef' is not a value!!
> a=setmetatable({},{__index=print,__newindex=print})
> a[1]=1
table: 0x93cc280        1       1
> a[1]=undef
> a[2]=nil
table: 0x93cc280        2       nil
> a[3]=undef
> =a[1]==nil
table: 0x93cc280        1
true
> =a[1]==undef
true

No metamethod calls occur for the undef assignment and check. This
doesn't seem right.

Best regards,

--
DoubleF

Reply | Threaded
Open this post in threaded view
|

Re: Lua 5.4.0 (work1), undef and metatable

Daurnimator
On 14 March 2018 at 20:38, Sergey Zakharchenko <[hidden email]> wrote:
> No metamethod calls occur for the undef assignment and check. This
> doesn't seem right.

I think I saw a __undef introduced?

Reply | Threaded
Open this post in threaded view
|

Re: Lua 5.4.0 (work1), undef and metatable

Sergey Zakharchenko
2018-03-14 12:43 GMT+03:00 Daurnimator <[hidden email]>:
> On 14 March 2018 at 20:38, Sergey Zakharchenko <[hidden email]> 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?

Best regards,

--
DoubleF

Reply | Threaded
Open this post in threaded view
|

Re: Lua 5.4.0 (work1), undef and metatable

Roberto Ierusalimschy
> 2018-03-14 12:43 GMT+03:00 Daurnimator <[hidden email]>:
> > On 14 March 2018 at 20:38, Sergey Zakharchenko <[hidden email]> 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.

-- Roberto

Reply | Threaded
Open this post in threaded view
|

Re: Lua 5.4.0 (work1), undef and metatable

Rob Kendrick-2
In reply to this post by Sergey Zakharchenko
On Wed, Mar 14, 2018 at 12:38:19PM +0300, Sergey Zakharchenko wrote:

> Lua 5.4.0 (work1)  Copyright (C) 1994-2018 Lua.org, PUC-Rio
> > =undef
> stdin:1: 'undef' is not a value!!

I think one exclamation mark is sufficient; two seems rather exuberant.

:)

B.

Reply | Threaded
Open this post in threaded view
|

Re: Lua 5.4.0 (work1), undef and metatable

Charles Heywood
Judging by some of the comments about trying to use it as a value still, perhaps two wasn't enough.

On Wed, Mar 14, 2018 at 9:44 AM Rob Kendrick <[hidden email]> wrote:
On Wed, Mar 14, 2018 at 12:38:19PM +0300, Sergey Zakharchenko wrote:

> Lua 5.4.0 (work1)  Copyright (C) 1994-2018 Lua.org, PUC-Rio
> > =undef
> stdin:1: 'undef' is not a value!!

I think one exclamation mark is sufficient; two seems rather exuberant.

:)

B.

--
--
Ryan | Charles <[hidden email]>
Software Developer / System Administrator
Reply | Threaded
Open this post in threaded view
|

Re: Lua 5.4.0 (work1), undef and metatable

Soni "They/Them" L.
In reply to this post by Roberto Ierusalimschy


On 2018-03-14 11:35 AM, Roberto Ierusalimschy wrote:
>> 2018-03-14 12:43 GMT+03:00 Daurnimator <[hidden email]>:
>>> On 14 March 2018 at 20:38, Sergey Zakharchenko <[hidden email]> 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

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

That keeps backwards compatibility, kinda.

>
> -- 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.


Reply | Threaded
Open this post in threaded view
|

Re: Lua 5.4.0 (work1), undef and metatable

Roberto Ierusalimschy
>
>
> On 2018-03-14 11:35 AM, Roberto Ierusalimschy wrote:
> >>2018-03-14 12:43 GMT+03:00 Daurnimator <[hidden email]>:
> >>>On 14 March 2018 at 20:38, Sergey Zakharchenko <[hidden email]> 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?


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

??

-- Roberto

Reply | Threaded
Open this post in threaded view
|

Re: Lua 5.4.0 (work1), undef and metatable

Soni "They/Them" L.


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 <[hidden email]>:
>>>>> On 14 March 2018 at 20:38, Sergey Zakharchenko <[hidden email]> 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.