lua-users home
lua-l archive

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


> I'm just starting to dig into lua sources so I might be writing
> something stupid. However, in lparser.c / recfields( ), the key value
> of the record seems to be converted twice into a RK register:
> 
> luaK_exp2RK(fs, &key);
> expr(ls, &val);
> luaK_codeABC(fs, OP_SETTABLE, cc->t->u.s.info, luaK_exp2RK(fs,
> &key), luaK_exp2RK(fs, &val));
> 
> I guess that luaK_exp2RK( ) is idempotent, and therefore it doesn't
> cause a bug, but it seems useless, and maybe an RC release would be a
> nice place to fix it?
> 
> (and if the double call to luaK_exp2RK( ) has a purpose, I'd
> appreciate if someone could explain me which one!)

The first call does the job (it should be done before reading the 'val'
expression). The second call in only to get the return value. We could
use only one call, but we would need a temporary:

  k = luaK_exp2RK(fs, &key);
  expr(ls, &val);
  luaK_codeABC(fs, OP_SETTABLE, cc->t->u.s.info, k, luaK_exp2RK(fs, &val));

-- Roberto