/* Setup lexer state. */ void lj_lex_setup(lua_State *L, LexState *ls) { ls->L = L; ls->fs = NULL; ls->n = 0; ls->p = NULL; ls->vstack = NULL; ls->sizevstack = 0; ls->vtop = 0; ls->bcstack = NULL; ls->sizebcstack = 0; ls->lookahead = TK_eof; /* No look-ahead token. */ ls->linenumber = 1; ls->lastline = 1; lj_str_resizebuf(ls->L, &ls->sb, LJ_MIN_SBUF); next(ls); /* Read-ahead first char. */ if (ls->current == 0xef && ls->n >= 2 && char2int(ls->p[0]) == 0xbb && char2int(ls->p[1]) == 0xbf) { /* Skip UTF-8 BOM (if buffered). */ ls->n -= 2; ls->p += 2; next(ls); } if (ls->current == '#') { /* Skip POSIX #! header line. */ do { next(ls); if (ls->current == END_OF_STREAM) return; } while (!currIsNewline(ls)); inclinenumber(ls); } if (ls->current == LUA_SIGNATURE[0]) { setstrV(L, L->top++, lj_err_str(L, LJ_ERR_XBCLOAD)); lj_err_throw(L, LUA_ERRSYNTAX); } }
static LJ_NOINLINE void save_grow(LexState *ls, int c) { MSize newsize; if (ls->sb.sz >= LJ_MAX_STR/2) lj_lex_error(ls, 0, LJ_ERR_XELEM); newsize = ls->sb.sz * 2; lj_str_resizebuf(ls->L, &ls->sb, newsize); ls->sb.buf[ls->sb.n++] = (char)c; }
static void save(LexState *ls, int c) { if (ls->sb.n + 1 > ls->sb.sz) { MSize newsize; if (ls->sb.sz >= LJ_MAX_STR/2) lj_lex_error(ls, 0, LJ_ERR_XELEM); newsize = ls->sb.sz * 2; lj_str_resizebuf(ls->L, &ls->sb, newsize); } ls->sb.buf[ls->sb.n++] = cast(char, c); }
/* Setup lexer state. */ int lj_lex_setup(lua_State *L, LexState *ls) { int header = 0; ls->L = L; ls->fs = NULL; ls->n = 0; ls->p = NULL; ls->vstack = NULL; ls->sizevstack = 0; ls->vtop = 0; ls->bcstack = NULL; ls->sizebcstack = 0; ls->lookahead = TK_eof; /* No look-ahead token. */ ls->linenumber = 1; ls->lastline = 1; lj_str_resizebuf(ls->L, &ls->sb, LJ_MIN_SBUF); next(ls); /* Read-ahead first char. */ if (ls->current == 0xef && ls->n >= 2 && char2int(ls->p[0]) == 0xbb && char2int(ls->p[1]) == 0xbf) { /* Skip UTF-8 BOM (if buffered). */ ls->n -= 2; ls->p += 2; next(ls); header = 1; } if (ls->current == '#') { /* Skip POSIX #! header line. */ do { next(ls); if (ls->current == END_OF_STREAM) return 0; } while (!currIsNewline(ls)); inclinenumber(ls); header = 1; } if (ls->current == LUA_SIGNATURE[0]) { /* Bytecode dump. */ if (header) { /* ** Loading bytecode with an extra header is disabled for security ** reasons. This may circumvent the usual check for bytecode vs. ** Lua code by looking at the first char. Since this is a potential ** security violation no attempt is made to echo the chunkname either. */ setstrV(L, L->top++, lj_err_str(L, LJ_ERR_BCBAD)); lj_err_throw(L, LUA_ERRSYNTAX); } return 1; } return 0; }