aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2010-05-18 14:32:19 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2010-05-18 14:32:19 -0300
commite8a2c3690940016f0c7050f441b1e78b1bc6d78a (patch)
tree308cea4550bb637c73ec2b2949207a012b53b819
parent3c39a0e8cbf35f449f303e3ef8323062158121d4 (diff)
downloadlua-e8a2c3690940016f0c7050f441b1e78b1bc6d78a.tar.gz
lua-e8a2c3690940016f0c7050f441b1e78b1bc6d78a.tar.bz2
lua-e8a2c3690940016f0c7050f441b1e78b1bc6d78a.zip
more comments
-rw-r--r--lauxlib.c18
1 files changed, 9 insertions, 9 deletions
diff --git a/lauxlib.c b/lauxlib.c
index ccdc6af0..a0a66e47 100644
--- a/lauxlib.c
+++ b/lauxlib.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lauxlib.c,v 1.211 2010/05/17 18:30:27 roberto Exp roberto $ 2** $Id: lauxlib.c,v 1.212 2010/05/18 17:21:24 roberto Exp roberto $
3** Auxiliary functions for building Lua libraries 3** Auxiliary functions for building Lua libraries
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -476,26 +476,26 @@ LUALIB_API void luaL_unref (lua_State *L, int t, int ref) {
476*/ 476*/
477 477
478typedef struct LoadF { 478typedef struct LoadF {
479 int first; 479 int first; /* pre-read character */
480 FILE *f; 480 FILE *f; /* file being read */
481 char buff[LUAL_BUFFERSIZE]; 481 char buff[LUAL_BUFFERSIZE]; /* area for reading file */
482} LoadF; 482} LoadF;
483 483
484 484
485static const char *getF (lua_State *L, void *ud, size_t *size) { 485static const char *getF (lua_State *L, void *ud, size_t *size) {
486 LoadF *lf = (LoadF *)ud; 486 LoadF *lf = (LoadF *)ud;
487 (void)L; 487 (void)L;
488 if (lf->first != EOF) { 488 if (lf->first != EOF) { /* first character not read yet? */
489 lf->buff[0] = (char)lf->first; /* return it */
489 *size = 1; 490 *size = 1;
490 lf->buff[0] = (char)lf->first; 491 lf->first = EOF; /* now it has been read */
491 lf->first = EOF;
492 } 492 }
493 else { 493 else { /* read a block from file */
494 /* 'fread' can return > 0 *and* set the EOF flag. If next call to 494 /* 'fread' can return > 0 *and* set the EOF flag. If next call to
495 'getF' called 'fread', it might still wait for user input. 495 'getF' called 'fread', it might still wait for user input.
496 The next check avoids this problem. */ 496 The next check avoids this problem. */
497 if (feof(lf->f)) return NULL; 497 if (feof(lf->f)) return NULL;
498 *size = fread(lf->buff, 1, sizeof(lf->buff), lf->f); 498 *size = fread(lf->buff, 1, sizeof(lf->buff), lf->f); /* read block */
499 } 499 }
500 return lf->buff; 500 return lf->buff;
501} 501}