lua-users home
lua-l archive

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

Miles Bader <> wrote:
> I haven't looked at the implementation, but I suppose it may simply
> use C unsigned values to represent integers, or when doing arithmetic
> on them ...

Yes. In lvm.h:

#define intop(op,v1,v2) \
	cast_integer(cast_unsigned(v1) op cast_unsigned(v2))

In lvm.c:

        TValue *rb = RKB(i);
        TValue *rc = RKC(i);
        lua_Number nb; lua_Number nc;
        if (ttisinteger(rb) && ttisinteger(rc)) {
          lua_Integer ib = ivalue(rb); lua_Integer ic = ivalue(rc);
          setivalue(ra, intop(+, ib, ic));
        else if (tonumber(rb, &nb) && tonumber(rc, &nc)) {
          setnvalue(ra, luai_numadd(L, nb, nc));
        else { Protect(luaT_trybinTM(L, rb, rc, ra, TM_ADD)); }

f.anthony.n.finch  <>
Forties, Cromarty: East, veering southeast, 4 or 5, occasionally 6 at first.
Rough, becoming slight or moderate. Showers, rain at first. Moderate or good,
occasionally poor at first.