浏览代码

to avoid warnings about "typecast" (Visual C++)

Roberto Ierusalimschy 26 年之前
父节点
当前提交
766e67ef3b
共有 10 个文件被更改,包括 75 次插入75 次删除
  1. 5 1
      lauxlib.h
  2. 2 2
      lbuffer.c
  3. 8 10
      lbuiltin.c
  4. 9 6
      liolib.c
  5. 4 4
      llex.c
  6. 4 5
      lmathlib.c
  7. 15 15
      lparser.c
  8. 9 9
      lstrlib.c
  9. 16 20
      lua.c
  10. 3 3
      lzio.c

+ 5 - 1
lauxlib.h

@@ -1,5 +1,5 @@
 /*
-** $Id: lauxlib.h,v 1.8 1998/06/18 16:57:03 roberto Exp roberto $
+** $Id: lauxlib.h,v 1.9 1998/06/19 16:14:09 roberto Exp roberto $
 ** Auxiliary functions for building Lua libraries
 ** See Copyright Notice in lua.h
 */
@@ -28,7 +28,11 @@ char *luaL_check_lstr (int numArg, long *len);
 #define luaL_opt_string(n, d) (luaL_opt_lstr((n), (d), NULL))
 char *luaL_opt_lstr (int numArg, char *def, long *len);
 double luaL_check_number (int numArg);
+#define luaL_check_int(n)	((int)luaL_check_number(n))
+#define luaL_check_long(n)	((long)luaL_check_number(n))
 double luaL_opt_number (int numArg, double def);
+#define luaL_opt_int(n,d)	((int)luaL_opt_number(n,d))
+#define luaL_opt_long(n,d)	((long)luaL_opt_number(n,d))
 lua_Object luaL_functionarg (int arg);
 lua_Object luaL_tablearg (int arg);
 lua_Object luaL_nonnullarg (int numArg);

+ 2 - 2
lbuffer.c

@@ -1,5 +1,5 @@
 /*
-** $Id: lbuffer.c,v 1.3 1998/06/02 20:37:04 roberto Exp roberto $
+** $Id: lbuffer.c,v 1.4 1998/06/19 16:14:09 roberto Exp roberto $
 ** Auxiliary functions for building Lua libraries
 ** See Copyright Notice in lua.h
 */
@@ -42,7 +42,7 @@ char *luaL_openspace (int size)
 void luaL_addchar (int c)
 {
   openspace(BUFF_STEP);
-  L->Mbuffer[L->Mbuffnext++] = c;
+  L->Mbuffer[L->Mbuffnext++] = (char)c;
 }
 
 

+ 8 - 10
lbuiltin.c

@@ -1,5 +1,5 @@
 /*
-** $Id: lbuiltin.c,v 1.38 1998/12/15 15:21:09 roberto Exp roberto $
+** $Id: lbuiltin.c,v 1.40 1998/12/27 20:22:36 roberto Exp roberto $
 ** Built-in functions
 ** See Copyright Notice in lua.h
 */
@@ -133,7 +133,7 @@ static void luaB_print (void) {
 
 
 static void luaB_tonumber (void) {
-  int base = luaL_opt_number(2, 10);
+  int base = luaL_opt_int(2, 10);
   if (base == 10) {  /* standard conversion */
     lua_Object o = lua_getparam(1);
     if (lua_isnumber(o))
@@ -186,7 +186,7 @@ static void luaB_luatag (void) {
 static void luaB_settag (void) {
   lua_Object o = luaL_tablearg(1);
   lua_pushobject(o);
-  lua_settag(luaL_check_number(2));
+  lua_settag(luaL_check_int(2));
   lua_pushobject(o);  /* returns first argument */
 }
 
@@ -195,8 +195,8 @@ static void luaB_newtag (void) {
 }
 
 static void luaB_copytagmethods (void) {
-  lua_pushnumber(lua_copytagmethods(luaL_check_number(1),
-                                    luaL_check_number(2)));
+  lua_pushnumber(lua_copytagmethods(luaL_check_int(1),
+                                    luaL_check_int(2)));
 }
 
 static void luaB_rawgettable (void) {
@@ -215,13 +215,11 @@ static void luaB_rawsettable (void) {
 static void luaB_settagmethod (void) {
   lua_Object nf = luaL_nonnullarg(3);
   lua_pushobject(nf);
-  lua_pushobject(lua_settagmethod((int)luaL_check_number(1),
-                                  luaL_check_string(2)));
+  lua_pushobject(lua_settagmethod(luaL_check_int(1), luaL_check_string(2)));
 }
 
 static void luaB_gettagmethod (void) {
-  lua_pushobject(lua_gettagmethod((int)luaL_check_number(1),
-                                  luaL_check_string(2)));
+  lua_pushobject(lua_gettagmethod(luaL_check_int(1), luaL_check_string(2)));
 }
 
 static void luaB_seterrormethod (void) {
@@ -231,7 +229,7 @@ static void luaB_seterrormethod (void) {
 }
 
 static void luaB_collectgarbage (void) {
-  lua_pushnumber(lua_collectgarbage(luaL_opt_number(1, 0)));
+  lua_pushnumber(lua_collectgarbage(luaL_opt_int(1, 0)));
 }
 
 

+ 9 - 6
liolib.c

@@ -1,5 +1,5 @@
 /*
-** $Id: liolib.c,v 1.26 1998/11/20 15:41:43 roberto Exp roberto $
+** $Id: liolib.c,v 1.27 1998/12/27 20:21:28 roberto Exp roberto $
 ** Standard I/O (and system) library
 ** See Copyright Notice in lua.h
 */
@@ -105,8 +105,11 @@ static FILE *getfileparam (char *name, int *arg) {
 static char *getmode (char mode) {
   static char m[3];
   m[0] = mode;
-  m[1] = (*luaL_opt_string(FIRSTARG+1, "text") == 'b') ? 'b' : '\0';
-  m[2] = '\0';
+  if (*luaL_opt_string(FIRSTARG+1, "text") == 'b') {
+     m[1] = 'b';
+     m[2] = '\0';
+  }
+  else m[1] = '\0';
   return m;
 }
 
@@ -308,7 +311,7 @@ static void io_read (void) {
     l = luaL_getsize();
     if (!success && l==0) return;  /* read fails */
     lua_pushlstring(luaL_buffer(), l);
-  } while ((p = luaL_opt_string(arg++, NULL)));
+  } while ((p = luaL_opt_string(arg++, NULL)) != NULL);
 }
 
 
@@ -319,7 +322,7 @@ static void io_write (void) {
   char *s;
   long l;
   while ((s = luaL_opt_lstr(arg++, NULL, &l)) != NULL)
-    status = status && (fwrite(s, 1, l, f) == l);
+    status = status && ((long)fwrite(s, 1, l, f) == l);
   pushresult(status);
 }
 
@@ -329,7 +332,7 @@ static void io_seek (void) {
   static char *modenames[] = {"set", "cur", "end", NULL};
   FILE *f = getfile(FIRSTARG-1+1);
   int op = luaL_findstring(luaL_opt_string(FIRSTARG-1+2, "cur"), modenames);
-  long offset = luaL_opt_number(FIRSTARG-1+3, 0);
+  long offset = luaL_opt_long(FIRSTARG-1+3, 0);
   luaL_arg_check(f, FIRSTARG-1+1, "invalid file handler");
   luaL_arg_check(op != -1, FIRSTARG-1+2, "invalid mode");
   op = fseek(f, offset, mode[op]);

+ 4 - 4
llex.c

@@ -1,5 +1,5 @@
 /*
-** $Id: llex.c,v 1.25 1998/12/03 15:45:15 roberto Exp $
+** $Id: llex.c,v 1.26 1998/12/27 20:25:20 roberto Exp roberto $
 ** Lexical Analizer
 ** See Copyright Notice in lua.h
 */
@@ -61,7 +61,7 @@ void luaX_error (LexState *ls, char *s) {
 
 void luaX_token2str (int token, char *s) {
   if (token < 255) {
-    s[0] = token;
+    s[0] = (char)token;
     s[1] = '\0';
   }
   else
@@ -138,7 +138,7 @@ static void readname (LexState *LS, char *buff)
       buff[PRAGMASIZE] = 0;
       luaX_syntaxerror(LS, "pragma too long", buff);
     }
-    buff[i++] = LS->current;
+    buff[i++] = (char)LS->current;
     next(LS);
   }
   buff[i] = 0;
@@ -344,7 +344,7 @@ int luaX_lex (LexState *LS) {
                       c = 10*c + (LS->current-'0');
                       next(LS);
                     } while (++i<3 && isdigit(LS->current));
-                    if (c > (unsigned char)c)
+                    if (c != (unsigned char)c)
                       luaX_error(LS, "escape sequence too large");
                     save(c);
                   }

+ 4 - 5
lmathlib.c

@@ -1,5 +1,5 @@
 /*
-** $Id: lmathlib.c,v 1.10 1998/06/19 16:14:09 roberto Exp roberto $
+** $Id: lmathlib.c,v 1.11 1998/09/08 19:25:35 roberto Exp roberto $
 ** Lua standard mathematical library
 ** See Copyright Notice in lua.h
 */
@@ -122,7 +122,7 @@ static void math_frexp (void) {
 }
 
 static void math_ldexp (void) {
-  lua_pushnumber(ldexp(luaL_check_number(1), luaL_check_number(2)));
+  lua_pushnumber(ldexp(luaL_check_number(1), luaL_check_int(2)));
 }
 
 
@@ -166,9 +166,8 @@ static void math_random (void)
 }
 
 
-static void math_randomseed (void)
-{
-  srand(luaL_check_number(1));
+static void math_randomseed (void) {
+  srand(luaL_check_int(1));
 }
 
 

+ 15 - 15
lparser.c

@@ -1,5 +1,5 @@
 /*
-** $Id: lparser.c,v 1.5 1998/08/11 13:28:05 roberto Exp roberto $
+** $Id: lparser.c,v 1.6 1998/12/23 14:06:57 roberto Exp roberto $
 ** LL(1) Parser and code generator for Lua
 ** See Copyright Notice in lua.h
 */
@@ -158,18 +158,18 @@ static int code_oparg_at (LexState *ls, int pc, OpCode op, int builtin,
   Byte *code = ls->fs->f->code;
   deltastack(ls, delta);
   if (arg < builtin) {
-    code[pc] = op+1+arg;
+    code[pc] = (Byte)(op+1+arg);
     return 1;
   }
   else if (arg <= 255) {
-    code[pc] = op;
-    code[pc+1] = arg;
+    code[pc] = (Byte)op;
+    code[pc+1] = (Byte)arg;
     return 2;
   }
   else if (arg <= MAX_WORD) {
-    code[pc] = op+1+builtin;
-    code[pc+1] = arg>>8;
-    code[pc+2] = arg&0xFF;
+    code[pc] = (Byte)(op+1+builtin);
+    code[pc+1] = (Byte)(arg>>8);
+    code[pc+2] = (Byte)(arg&0xFF);
     return 3;
   }
   else luaX_error(ls, "code too long " MES_LIM("64K")
@@ -202,7 +202,7 @@ static void code_oparg (LexState *ls, OpCode op, int builtin, int arg,
 
 static void code_opcode (LexState *ls, OpCode op, int delta) {
   deltastack(ls, delta);
-  code_byte(ls->fs, op);
+  code_byte(ls->fs, (Byte)op);
 }
 
 
@@ -277,7 +277,7 @@ static void flush_record (LexState *ls, int n) {
 static void flush_list (LexState *ls, int m, int n) {
   if (n == 0) return;
   code_oparg(ls, SETLIST, 1, m, -n);
-  code_byte(ls->fs, n);
+  code_byte(ls->fs, (Byte)n);
 }
 
 
@@ -391,7 +391,7 @@ static void adjuststack (LexState *ls, int n) {
 static void close_exp (LexState *ls, int pc, int nresults) {
   if (pc > 0) {  /* expression is an open function call */
     Byte *code = ls->fs->f->code;
-    int nparams = code[pc];  /* save nparams */
+    Byte nparams = code[pc];  /* save nparams */
     pc += fix_opcode(ls, pc-2, CALLFUNC, 2, nresults);
     code[pc] = nparams;  /* restore nparams */
     if (nresults != MULT_RET)
@@ -426,11 +426,11 @@ static void code_args (LexState *ls, int nparams, int dots) {
   fs->nlocalvar += nparams;  /* "self" may already be there */
   nparams = fs->nlocalvar;
   if (!dots) {
-    fs->f->code[1] = nparams;  /* fill-in arg information */
+    fs->f->code[1] = (Byte)nparams;  /* fill-in arg information */
     deltastack(ls, nparams);
   }
   else {
-    fs->f->code[1] = nparams+ZEROVARARG;
+    fs->f->code[1] = (Byte)(nparams+ZEROVARARG);
     deltastack(ls, nparams+1);
     add_localvar(ls, luaS_new("arg"));
   }
@@ -515,7 +515,7 @@ static void func_onstack (LexState *ls, FuncState *func) {
     for (i=0; i<func->nupvalues; i++)
       lua_pushvar(ls, &func->upvalues[i]);
     code_oparg(ls, CLOSURE, 0, c, -func->nupvalues+1);
-    code_byte(fs, func->nupvalues);
+    code_byte(fs, (Byte)func->nupvalues);
   }
 }
 
@@ -548,7 +548,7 @@ static void close_func (LexState *ls) {
   FuncState *fs = ls->fs;
   TProtoFunc *f = fs->f;
   code_opcode(ls, ENDCODE, 0);
-  f->code[0] = fs->maxstacksize;
+  f->code[0] = (Byte)fs->maxstacksize;
   f->code = luaM_reallocvector(f->code, fs->pc, Byte);
   f->consts = luaM_reallocvector(f->consts, f->nconsts, TObject);
   if (fs->maxvars != -1) {  /* debug information? */
@@ -1092,7 +1092,7 @@ static int funcparams (LexState *ls, int slf) {
   }
   code_byte(fs, 0);  /* save space for opcode */
   code_byte(fs, 0);  /* and nresult */
-  code_byte(fs, nparams+slf);
+  code_byte(fs, (Byte)(nparams+slf));
   return fs->pc-1;
 }
 

+ 9 - 9
lstrlib.c

@@ -1,5 +1,5 @@
 /*
-** $Id: lstrlib.c,v 1.20 1998/11/10 19:38:12 roberto Exp roberto $
+** $Id: lstrlib.c,v 1.21 1998/12/01 18:41:25 roberto Exp roberto $
 ** Standard library for strings and pattern-matching
 ** See Copyright Notice in lua.h
 */
@@ -46,8 +46,8 @@ static long posrelat (long pos, long len) {
 static void str_sub (void) {
   long l;
   char *s = luaL_check_lstr(1, &l);
-  long start = posrelat(luaL_check_number(2), l);
-  long end = posrelat(luaL_opt_number(3, -1), l);
+  long start = posrelat(luaL_check_long(2), l);
+  long end = posrelat(luaL_opt_long(3, -1), l);
   if (start < 1) start = 1;
   if (end > l) end = l;
   if (start <= end)
@@ -82,7 +82,7 @@ static void str_rep (void)
 {
   long l;
   char *s = luaL_check_lstr(1, &l);
-  int n = (int)luaL_check_number(2);
+  int n = luaL_check_int(2);
   luaL_resetbuffer();
   while (n-- > 0)
     addnchar(s, l);
@@ -94,7 +94,7 @@ static void str_byte (void)
 {
   long l;
   char *s = luaL_check_lstr(1, &l);
-  long pos = posrelat(luaL_opt_number(2, 1), l);
+  long pos = posrelat(luaL_opt_long(2, 1), l);
   luaL_arg_check(0<pos && pos<=l, 2,  "out of range");
   lua_pushnumber((unsigned char)s[pos-1]);
 }
@@ -105,7 +105,7 @@ static void str_char (void) {
   while (lua_getparam(++i) != LUA_NOOBJECT) {
     double c = luaL_check_number(i);
     luaL_arg_check((unsigned char)c == c, i, "invalid value");
-    luaL_addchar((int)c);
+    luaL_addchar((unsigned char)c);
   }
   closeandpush();
 }
@@ -338,7 +338,7 @@ static void str_find (void)
   long l;
   char *s = luaL_check_lstr(1, &l);
   char *p = luaL_check_string(2);
-  long init = posrelat(luaL_opt_number(3, 1), l) - 1;
+  long init = posrelat(luaL_opt_long(3, 1), l) - 1;
   struct Capture cap;
   luaL_arg_check(0 <= init && init <= l, 3, "out of range");
   if (lua_getparam(4) != LUA_NOOBJECT ||
@@ -418,7 +418,7 @@ static void str_gsub (void)
   char *src = luaL_check_lstr(1, &srcl);
   char *p = luaL_check_string(2);
   lua_Object newp = lua_getparam(3);
-  int max_s = (int)luaL_opt_number(4, srcl+1);
+  int max_s = luaL_opt_int(4, srcl+1);
   int anchor = (*p == '^') ? (p++, 1) : 0;
   int n = 0;
   struct Capture cap;
@@ -507,7 +507,7 @@ static void str_format (void)
           break;
         }
         case 'c':  case 'd':  case 'i':
-          sprintf(buff, form, (int)luaL_check_number(arg));
+          sprintf(buff, form, luaL_check_int(arg));
           break;
         case 'o':  case 'u':  case 'x':  case 'X':
           sprintf(buff, form, (unsigned int)luaL_check_number(arg));

+ 16 - 20
lua.c

@@ -1,5 +1,5 @@
 /*
-** $Id: lua.c,v 1.13 1998/01/19 19:49:49 roberto Exp roberto $
+** $Id: lua.c,v 1.14 1998/02/11 20:56:05 roberto Exp roberto $
 ** Lua stand-alone interpreter
 ** See Copyright Notice in lua.h
 */
@@ -32,27 +32,27 @@ typedef void (*handler)(int);  /* type for signal actions */
 
 static void laction (int i);
 
-static handler lreset (void)
-{
+
+static handler lreset (void) {
   lua_linehook = NULL;
   lua_callhook = NULL;
   return signal(SIGINT, laction);
 }
 
-static void lstop (void)
-{
+
+static void lstop (void) {
   lreset();
   lua_error("interrupted!");
 }
 
-static void laction (int i)
-{
+
+static void laction (int i) {
   lua_linehook = (lua_LHFunction)lstop;
   lua_callhook = (lua_CHFunction)lstop;
 }
 
-static int ldo (int (*f)(char *), char *name)
-{
+
+static int ldo (int (*f)(char *), char *name) {
   int res;
   handler h = lreset();
   res = f(name);  /* dostring | dofile */
@@ -61,8 +61,7 @@ static int ldo (int (*f)(char *), char *name)
 }
 
 
-static void print_message (void)
-{
+static void print_message (void) {
   fprintf(stderr,
 "Lua: command line options:\n"
 "  -v       print version information\n"
@@ -76,8 +75,7 @@ static void print_message (void)
 }
 
 
-static void assign (char *arg)
-{
+static void assign (char *arg) {
   if (strlen(arg) >= 500)
     fprintf(stderr, "lua: shell argument too long");
   else {
@@ -90,13 +88,11 @@ static void assign (char *arg)
   }
 }
 
-#define BUF_SIZE	512
 
-static void manual_input (int prompt)
-{
+static void manual_input (int prompt) {
   int cont = 1;
   while (cont) {
-    char buffer[BUF_SIZE];
+    char buffer[BUFSIZ];
     int i = 0;
     lua_beginblock();
     if (prompt)
@@ -112,13 +108,13 @@ static void manual_input (int prompt)
           buffer[i-1] = '\n';
         else break;
       }
-      else if (i >= BUF_SIZE-1) {
+      else if (i >= BUFSIZ-1) {
         fprintf(stderr, "lua: argument line too long\n");
         break;
       }
-      else buffer[i++] = c;
+      else buffer[i++] = (char)c;
     }
-    buffer[i] = 0;
+    buffer[i] = '\0';
     ldo(lua_dostring, buffer);
     lua_endblock();
   }

+ 3 - 3
lzio.c

@@ -1,5 +1,5 @@
 /*
-** $Id: lzio.c,v 1.2 1997/11/21 19:00:46 roberto Exp roberto $
+** $Id: lzio.c,v 1.3 1997/12/22 20:57:18 roberto Exp roberto $
 ** a generic input stream interface
 ** See Copyright Notice in lua.h
 */
@@ -15,11 +15,11 @@
 
 /* ----------------------------------------------------- memory buffers --- */
 
-static int zmfilbuf (ZIO* z)
-{
+static int zmfilbuf (ZIO* z) {
  return EOZ;
 }
 
+
 ZIO* zmopen (ZIO* z, char* b, int size, char *name)
 {
  if (b==NULL) return NULL;