small improvement

This commit is contained in:
Roberto Ierusalimschy 2005-06-03 17:16:16 -03:00
parent e33d7bae45
commit eca9fa02d2
4 changed files with 16 additions and 20 deletions

View File

@ -1,5 +1,5 @@
/*
** $Id: lstate.c,v 2.30 2005/04/05 15:57:59 roberto Exp roberto $
** $Id: lstate.c,v 2.31 2005/05/05 15:34:03 roberto Exp roberto $
** Global State
** See Copyright Notice in lua.h
*/
@ -83,7 +83,7 @@ static void f_luaopen (lua_State *L, void *ud) {
static void preinit_state (lua_State *L, global_State *g) {
L->l_G = g;
G(L) = g;
L->stack = NULL;
L->stacksize = 0;
L->errorJmp = NULL;

View File

@ -1,5 +1,5 @@
/*
** $Id: lstate.h,v 2.20 2005/04/25 19:24:10 roberto Exp roberto $
** $Id: lstate.h,v 2.21 2005/05/05 15:34:03 roberto Exp roberto $
** Global State
** See Copyright Notice in lua.h
*/
@ -101,7 +101,7 @@ struct lua_State {
CommonHeader;
StkId top; /* first free slot in the stack */
StkId base; /* base of current function */
global_State *l_G;
global_State *_G;
CallInfo *ci; /* call info for current function */
const Instruction *savedpc; /* `savedpc' of current function */
StkId stack_last; /* last free slot in the stack */
@ -126,7 +126,7 @@ struct lua_State {
};
#define G(L) (L->l_G)
#define G(L) (L->_G)
/*

4
lua.c
View File

@ -1,5 +1,5 @@
/*
** $Id: lua.c,v 1.143 2005/05/16 21:19:00 roberto Exp roberto $
** $Id: lua.c,v 1.144 2005/05/17 19:49:15 roberto Exp roberto $
** Lua stand-alone interpreter
** See Copyright Notice in lua.h
*/
@ -149,7 +149,7 @@ static const char *get_prompt (lua_State *L, int firstline) {
static int incomplete (lua_State *L, int status) {
if (status == LUA_ERRSYNTAX &&
strstr(lua_tostring(L, -1), "<eof>") != NULL) {
strstr(lua_tostring(L, -1), LUA_QL("<eof>")) != NULL) {
lua_pop(L, 1);
return 1;
}

22
lzio.c
View File

@ -1,5 +1,5 @@
/*
** $Id: lzio.c,v 1.29 2004/04/30 20:13:38 roberto Exp roberto $
** $Id: lzio.c,v 1.30 2005/05/17 19:49:15 roberto Exp roberto $
** a generic input stream interface
** See Copyright Notice in lua.h
*/
@ -34,10 +34,12 @@ int luaZ_fill (ZIO *z) {
int luaZ_lookahead (ZIO *z) {
if (z->n == 0) {
int c = luaZ_fill(z);
if (c == EOZ) return c;
z->n++;
z->p--;
if (luaZ_fill(z) == EOZ)
return EOZ;
else {
z->n++; /* luaZ_fill removed first byte; put back it */
z->p--;
}
}
return char2int(*z->p);
}
@ -56,14 +58,8 @@ void luaZ_init (lua_State *L, ZIO *z, lua_Reader reader, void *data) {
size_t luaZ_read (ZIO *z, void *b, size_t n) {
while (n) {
size_t m;
if (z->n == 0) {
if (luaZ_fill(z) == EOZ)
return n; /* return number of missing bytes */
else {
++z->n; /* filbuf removed first byte; put back it */
--z->p;
}
}
if (luaZ_lookahead(z) == EOZ)
return n; /* return number of missing bytes */
m = (n <= z->n) ? n : z->n; /* min. between n and z->n */
memcpy(b, z->p, m);
z->n -= m;