misc/liblua/lauxlib.c
changeset 10015 4feced261c68
parent 9162 2c6ad606f4fb
equal deleted inserted replaced
10014:56d2f2d5aad8 10015:4feced261c68
    23 #include "lua.h"
    23 #include "lua.h"
    24 
    24 
    25 #include "lauxlib.h"
    25 #include "lauxlib.h"
    26 
    26 
    27 
    27 
    28 #define FREELIST_REF	0	/* free list of references */
    28 #define FREELIST_REF    0   /* free list of references */
    29 
    29 
    30 
    30 
    31 /* convert a stack index to positive */
    31 /* convert a stack index to positive */
    32 #define abs_index(L, i)		((i) > 0 || (i) <= LUA_REGISTRYINDEX ? (i) : \
    32 #define abs_index(L, i)     ((i) > 0 || (i) <= LUA_REGISTRYINDEX ? (i) : \
    33 					lua_gettop(L) + (i) + 1)
    33                     lua_gettop(L) + (i) + 1)
    34 
    34 
    35 
    35 
    36 /*
    36 /*
    37 ** {======================================================
    37 ** {======================================================
    38 ** Error-report functions
    38 ** Error-report functions
   387 ** Generic Buffer manipulation
   387 ** Generic Buffer manipulation
   388 ** =======================================================
   388 ** =======================================================
   389 */
   389 */
   390 
   390 
   391 
   391 
   392 #define bufflen(B)	((B)->p - (B)->buffer)
   392 #define bufflen(B)  ((B)->p - (B)->buffer)
   393 #define bufffree(B)	((size_t)(LUAL_BUFFERSIZE - bufflen(B)))
   393 #define bufffree(B) ((size_t)(LUAL_BUFFERSIZE - bufflen(B)))
   394 
   394 
   395 #define LIMIT	(LUA_MINSTACK/2)
   395 #define LIMIT   (LUA_MINSTACK/2)
   396 
   396 
   397 
   397 
   398 static int emptybuffer (luaL_Buffer *B) {
   398 static int emptybuffer (luaL_Buffer *B) {
   399   size_t l = bufflen(B);
   399   size_t l = bufflen(B);
   400   if (l == 0) return 0;  /* put nothing on stack */
   400   if (l == 0) return 0;  /* put nothing on stack */
   572   }
   572   }
   573   if (c == LUA_SIGNATURE[0] && filename) {  /* binary file? */
   573   if (c == LUA_SIGNATURE[0] && filename) {  /* binary file? */
   574     lf.f = freopen(filename, "rb", lf.f);  /* reopen in binary mode */
   574     lf.f = freopen(filename, "rb", lf.f);  /* reopen in binary mode */
   575     if (lf.f == NULL) return errfile(L, "reopen", fnameindex);
   575     if (lf.f == NULL) return errfile(L, "reopen", fnameindex);
   576     /* skip eventual `#!...' */
   576     /* skip eventual `#!...' */
   577    while ((c = getc(lf.f)) != EOF && c != LUA_SIGNATURE[0]) ;
   577    while ((c = getc(lf.f)) != EOF && c != LUA_SIGNATURE[0])
       
   578        /* do nothing */ ;
   578     lf.extraline = 0;
   579     lf.extraline = 0;
   579   }
   580   }
   580   ungetc(c, lf.f);
   581   ungetc(c, lf.f);
   581   status = lua_load(L, getF, &lf, lua_tostring(L, -1));
   582   status = lua_load(L, getF, &lf, lua_tostring(L, -1));
   582   readstatus = ferror(lf.f);
   583   readstatus = ferror(lf.f);