lua-users home
lua-l archive

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


2012/3/10 Greg <tghill@hotmail.com>:
> This must be close.  I tried running the following code:
>
>    local t1 = {}
>    table.insert(t1, 1)
>
> and got this err:
>
>    bad argument #1 to 'insert' (table expected, got number)

I fixed a very obvious bug (that should teach me to write code after
2am), but your testcase always worked for me...

Here is the updated version; look for the following else-if (in in
lj_parse.c, around line
1545), and replace it with this (or apply the attached patch on lj_parse.c):

    else if (ls->token == TK_name && lj_lex_lookahead(ls) == '=') {
      do {
        expr_str(ls, &key);
        lex_check(ls, '=');
        nhash++;

        expr(ls, &val);
        if (expr_isk_nojump(&val)) {
          TValue k;
          if (!t) {  /* Create template table on demand. */
            BCReg kidx;
            t = lj_tab_new(fs->L, 0, 0);
            kidx = const_gc(fs, obj2gco(t), LJ_TTAB);
            fs->bcbase[pc].ins = BCINS_AD(BC_TDUP, freg-1, kidx);
          }
          vcall = 0;
          expr_kvalue(&k, &key);
          expr_kvalue(lj_tab_set(fs->L, t, &k), &val);
          lj_gc_anybarriert(fs->L, t);
        } else {
          if (val.k != VCALL) { expr_toanyreg(fs, &val); vcall = 0; }
          expr_index(fs, e, &key);
          bcemit_store(fs, e, &val);
        }
        fs->freereg = freg;
      } while (ls->token == TK_name && lj_lex_lookahead(ls) == '=');
      if(!lex_opt(ls, ',')) {
        lex_opt(ls, ';');
      }
      continue;
    }

I hope this fixed all problems; I'm using this comma-saving version as
my default interpreter now- if I find any other bugs, I'll keep you
posted.

-- Wolfgang

Attachment: lj_lesscommas_fixed.patch
Description: Binary data