Explorar o código

small improvement

Roberto Ierusalimschy %!s(int64=20) %!d(string=hai) anos
pai
achega
eca9fa02d2
Modificáronse 4 ficheiros con 16 adicións e 20 borrados
  1. 2 2
      lstate.c
  2. 3 3
      lstate.h
  3. 2 2
      lua.c
  4. 9 13
      lzio.c

+ 2 - 2
lstate.c

@@ -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
 ** Global State
 ** See Copyright Notice in lua.h
 ** 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) {
 static void preinit_state (lua_State *L, global_State *g) {
-  L->l_G = g;
+  G(L) = g;
   L->stack = NULL;
   L->stack = NULL;
   L->stacksize = 0;
   L->stacksize = 0;
   L->errorJmp = NULL;
   L->errorJmp = NULL;

+ 3 - 3
lstate.h

@@ -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
 ** Global State
 ** See Copyright Notice in lua.h
 ** See Copyright Notice in lua.h
 */
 */
@@ -101,7 +101,7 @@ struct lua_State {
   CommonHeader;
   CommonHeader;
   StkId top;  /* first free slot in the stack */
   StkId top;  /* first free slot in the stack */
   StkId base;  /* base of current function */
   StkId base;  /* base of current function */
-  global_State *l_G;
+  global_State *_G;
   CallInfo *ci;  /* call info for current function */
   CallInfo *ci;  /* call info for current function */
   const Instruction *savedpc;  /* `savedpc' of current function */
   const Instruction *savedpc;  /* `savedpc' of current function */
   StkId stack_last;  /* last free slot in the stack */
   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)
 
 
 
 
 /*
 /*

+ 2 - 2
lua.c

@@ -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
 ** Lua stand-alone interpreter
 ** See Copyright Notice in lua.h
 ** 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) {
 static int incomplete (lua_State *L, int status) {
   if (status == LUA_ERRSYNTAX &&
   if (status == LUA_ERRSYNTAX &&
-         strstr(lua_tostring(L, -1), "<eof>") != NULL) {
+         strstr(lua_tostring(L, -1), LUA_QL("<eof>")) != NULL) {
     lua_pop(L, 1);
     lua_pop(L, 1);
     return 1;
     return 1;
   }
   }

+ 9 - 13
lzio.c

@@ -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
 ** a generic input stream interface
 ** See Copyright Notice in lua.h
 ** See Copyright Notice in lua.h
 */
 */
@@ -34,10 +34,12 @@ int luaZ_fill (ZIO *z) {
 
 
 int luaZ_lookahead (ZIO *z) {
 int luaZ_lookahead (ZIO *z) {
   if (z->n == 0) {
   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);
   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) {
 size_t luaZ_read (ZIO *z, void *b, size_t n) {
   while (n) {
   while (n) {
     size_t m;
     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 */
     m = (n <= z->n) ? n : z->n;  /* min. between n and z->n */
     memcpy(b, z->p, m);
     memcpy(b, z->p, m);
     z->n -= m;
     z->n -= m;