Exemple #1
0
static void forstat (LexState *ls, int line)
{
    /* forstat -> FOR (fornum | forlist) END */
    FuncState *fs = GetCurrentFuncState( ls );
    TString *varname;
    BlockCnt bl;

    enterblock(fs, &bl, 1);  /* scope for loop and control variables */

    luaX_next(ls);  /* skip `for' */

    varname = str_checkname(ls);  /* first variable name */

    switch (ls->t.token)
    {
    case '=':
        fornum(ls, varname, line);
        break;
    case ',': case TK_IN:
        forlist(ls, varname);
        break;
    default:
        luaX_syntaxerror(ls, LUA_QL("=") " or " LUA_QL("in") " expected");
        break;
    }

    check_match(ls, TK_END, TK_FOR, line);

    leaveblock(fs);  /* loop scope (`break' jumps to this point) */
}
Exemple #2
0
static void forstat (LexState *ls, int line) {
  /* forstat -> fornum | forlist */
  FuncState *fs = ls->fs;
  TString *varname;
  BlockCnt bl;
  enterblock(fs, &bl, 0);  /* block to control variable scope */
  next(ls);  /* skip `for' */
  varname = str_checkname(ls);  /* first variable name */
  switch (ls->t.token) {
    case '=': fornum(ls, varname, line); break;
    case ',': case TK_IN: forlist(ls, varname); break;
    default: luaX_syntaxerror(ls, "`=' or `in' expected");
  }
  check_match(ls, TK_END, TK_FOR, line);
  leaveblock(fs);
}