lua-users home
lua-l archive

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




On Thu, May 9, 2019 at 11:43 AM Dirk Laurie <dirk.laurie@gmail.com> wrote:
Op Do. 9 Mei 2019 om 15:45 het Coda Highland <chighland@gmail.com> geskryf:

> But the #n == 8 comment was never meant as anything more than a flippant remark.

My original motivation (not divulged in the post) was that invoking a
function to get the absolute value of a number is really a very
cumbersome way for something that can be done by the C ternary
operator.Therefore I looked around for a unary operator not yet
defined for type "number" and found that __len is the only candidate.

It's a ten-line patch to lvm.c:
534a535,544
>     case LUA_TNUMINT: {
>       lua_Integer n=ivalue(rb);
>       setivalue(ra,n<0?-n:n);
>       return;
>     }
>     case LUA_TNUMFLT: {
>       lua_Number x=fltvalue(rb);
>       setfltvalue(ra,x<0?-x:x);
>       return;
>     }

Then I suppose it is both amusing and appropriate that I came up with #n = abs(n) as well. :P

Not sure I think it's all that clumsy to use a function, though.

/s/ Adam