[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Behavior of logical operators
- From: Gavin Wraith <gavin@...>
- Date: Sun, 13 Mar 2011 13:06:10 GMT
In message <AANLkTinA5F+hOtmWB+qD+vWSt-UYN4ScadytB3R=q3A4@mail.gmail.com> you wrote:
> 2011/3/13 Axel Kittenberger <axkibe@gmail.com>
>
> > > I would expect this expression to return "true". What am I missing?
> >
> > This is a known bug. See http://www.lua.org/bugs.html#5.1.4-3
> >
> > Personally I consider this a very grave bug if basic operations go
> > wrong, and its been a year. When can we expect an official version
> > with logical operators fixed?
> >
> > and it happens in lua5.2-alpha, too.
I use lua5.2-alpha with the following patch (marked by
#if 0 ... #endif) in lcode.c which seems to cure the problem:
/ ---- begin code -------
void luaK_goiftrue (FuncState *fs, expdesc *e) {
int pc; /* pc of last jump */
luaK_dischargevars(fs, e);
switch (e->k) {
#if 0
case VK: case VKNUM: case VTRUE: {
pc = NO_JUMP; /* always true; do nothing */
break;
}
#endif
case VJMP: {
invertjump(fs, e);
pc = e->u.info;
break;
}
#if 0
case VFALSE: {
if (!hasjumps(e)) {
pc = luaK_jump(fs); /* always jump */
break;
}
/* else go through */
}
#endif
default: {
pc = jumponcond(fs, e, 0);
break;
}
}
luaK_concat(fs, &e->f, pc); /* insert last jump in `f' list */
luaK_patchtohere(fs, e->t);
e->t = NO_JUMP;
}
static void luaK_goiffalse (FuncState *fs, expdesc *e) {
int pc; /* pc of last jump */
luaK_dischargevars(fs, e);
switch (e->k) {
#if 0
case VNIL: case VFALSE: {
pc = NO_JUMP; /* always false; do nothing */
break;
}
#endif
case VJMP: {
pc = e->u.info;
break;
}
#if 0
case VTRUE: {
if (!hasjumps(e)) {
pc = luaK_jump(fs); /* always jump */
break;
}
/* else go through */
}
#endif
default: {
pc = jumponcond(fs, e, 1);
break;
}
}
luaK_concat(fs, &e->t, pc); /* insert last jump in `t' list */
luaK_patchtohere(fs, e->f);
e->f = NO_JUMP;
}
/ ------- end code --------
--
Gavin Wraith (gavin@wra1th.plus.com)
Home page: http://www.wra1th.plus.com/