diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2001-08-31 16:46:07 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2001-08-31 16:46:07 -0300 |
commit | e1d072571ec6f9d830e575a2ecdc95fd43428e53 (patch) | |
tree | 830fab7f2acb9adaee2d63073d339cc9557a5437 /liolib.c | |
parent | 7651a5c6b2ee6ec59cadec6199319d482071f176 (diff) | |
download | lua-e1d072571ec6f9d830e575a2ecdc95fd43428e53.tar.gz lua-e1d072571ec6f9d830e575a2ecdc95fd43428e53.tar.bz2 lua-e1d072571ec6f9d830e575a2ecdc95fd43428e53.zip |
better syntax for type casts
Diffstat (limited to 'liolib.c')
-rw-r--r-- | liolib.c | 30 |
1 files changed, 15 insertions, 15 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: liolib.c,v 1.120 2001/07/16 18:48:31 roberto Exp roberto $ | 2 | ** $Id: liolib.c,v 1.121 2001/07/22 00:59:36 roberto Exp $ |
3 | ** Standard I/O (and system) library | 3 | ** Standard I/O (and system) library |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -73,7 +73,7 @@ static int pushresult (lua_State *L, int i) { | |||
73 | 73 | ||
74 | 74 | ||
75 | static FILE *getopthandle (lua_State *L, int inout) { | 75 | static FILE *getopthandle (lua_State *L, int inout) { |
76 | FILE *p = (FILE *)lua_touserdata(L, 1); | 76 | FILE *p = (FILE *)(lua_touserdata(L, 1)); |
77 | if (p != NULL) { /* is it a userdata ? */ | 77 | if (p != NULL) { /* is it a userdata ? */ |
78 | if (!checkfile(L, 1)) { /* not a valid file handle? */ | 78 | if (!checkfile(L, 1)) { /* not a valid file handle? */ |
79 | if (strcmp(lua_type(L, 1), CLOSEDFILEHANDLE) == 0) | 79 | if (strcmp(lua_type(L, 1), CLOSEDFILEHANDLE) == 0) |
@@ -88,7 +88,7 @@ static FILE *getopthandle (lua_State *L, int inout) { | |||
88 | if (!checkfile(L,-1)) | 88 | if (!checkfile(L,-1)) |
89 | luaL_verror(L, l_s("global variable `%.10s' is not a valid file handle"), | 89 | luaL_verror(L, l_s("global variable `%.10s' is not a valid file handle"), |
90 | filenames[inout]); | 90 | filenames[inout]); |
91 | p = (FILE *)lua_touserdata(L, -1); | 91 | p = (FILE *)(lua_touserdata(L, -1)); |
92 | } | 92 | } |
93 | return p; /* leave handle at stack top to avoid GC */ | 93 | return p; /* leave handle at stack top to avoid GC */ |
94 | } | 94 | } |
@@ -127,7 +127,7 @@ static void resetfile (lua_State *L, int inout) { | |||
127 | 127 | ||
128 | 128 | ||
129 | static int io_close (lua_State *L) { | 129 | static int io_close (lua_State *L) { |
130 | FILE *f = (FILE *)luaL_check_userdata(L, 1, FILEHANDLE); | 130 | FILE *f = (FILE *)(luaL_check_userdata(L, 1, FILEHANDLE)); |
131 | int status = 1; | 131 | int status = 1; |
132 | if (f != stdin && f != stdout && f != stderr) { | 132 | if (f != stdin && f != stdout && f != stderr) { |
133 | lua_settop(L, 1); /* make sure file is on top */ | 133 | lua_settop(L, 1); /* make sure file is on top */ |
@@ -139,7 +139,7 @@ static int io_close (lua_State *L) { | |||
139 | 139 | ||
140 | 140 | ||
141 | static int file_collect (lua_State *L) { | 141 | static int file_collect (lua_State *L) { |
142 | FILE *f = (FILE *)luaL_check_userdata(L, 1, FILEHANDLE); | 142 | FILE *f = (FILE *)(luaL_check_userdata(L, 1, FILEHANDLE)); |
143 | if (f != stdin && f != stdout && f != stderr) | 143 | if (f != stdin && f != stdout && f != stderr) |
144 | CLOSEFILE(L, f); | 144 | CLOSEFILE(L, f); |
145 | return 0; | 145 | return 0; |
@@ -328,7 +328,7 @@ static int io_read (lua_State *L) { | |||
328 | size_t pl = lua_strlen(L, n) - 2; | 328 | size_t pl = lua_strlen(L, n) - 2; |
329 | luaL_arg_check(L, 0 < pl && pl <= LUA_MAXUNTIL, n, | 329 | luaL_arg_check(L, 0 < pl && pl <= LUA_MAXUNTIL, n, |
330 | l_s("invalid read-until length")); | 330 | l_s("invalid read-until length")); |
331 | success = read_until(L, f, p+2, (int)pl); | 331 | success = read_until(L, f, p+2, (int)(pl)); |
332 | break; | 332 | break; |
333 | } | 333 | } |
334 | default: | 334 | default: |
@@ -373,7 +373,7 @@ static int io_write (lua_State *L) { | |||
373 | static int io_seek (lua_State *L) { | 373 | static int io_seek (lua_State *L) { |
374 | static const int mode[] = {SEEK_SET, SEEK_CUR, SEEK_END}; | 374 | static const int mode[] = {SEEK_SET, SEEK_CUR, SEEK_END}; |
375 | static const l_char *const modenames[] = {l_s("set"), l_s("cur"), l_s("end"), NULL}; | 375 | static const l_char *const modenames[] = {l_s("set"), l_s("cur"), l_s("end"), NULL}; |
376 | FILE *f = (FILE *)luaL_check_userdata(L, 1, FILEHANDLE); | 376 | FILE *f = (FILE *)(luaL_check_userdata(L, 1, FILEHANDLE)); |
377 | int op = luaL_findstring(luaL_opt_string(L, 2, l_s("cur")), modenames); | 377 | int op = luaL_findstring(luaL_opt_string(L, 2, l_s("cur")), modenames); |
378 | long offset = luaL_opt_long(L, 3, 0); | 378 | long offset = luaL_opt_long(L, 3, 0); |
379 | luaL_arg_check(L, op != -1, 2, l_s("invalid mode")); | 379 | luaL_arg_check(L, op != -1, 2, l_s("invalid mode")); |
@@ -388,8 +388,8 @@ static int io_seek (lua_State *L) { | |||
388 | 388 | ||
389 | 389 | ||
390 | static int io_flush (lua_State *L) { | 390 | static int io_flush (lua_State *L) { |
391 | FILE *f = (lua_isnull(L, 1)) ? (FILE *)NULL : | 391 | FILE *f = (lua_isnull(L, 1)) ? (FILE *)(NULL) : |
392 | (FILE *)luaL_check_userdata(L, 1, FILEHANDLE); | 392 | (FILE *)(luaL_check_userdata(L, 1, FILEHANDLE)); |
393 | return pushresult(L, fflush(f) == 0); | 393 | return pushresult(L, fflush(f) == 0); |
394 | } | 394 | } |
395 | 395 | ||
@@ -461,7 +461,7 @@ static int getfield (lua_State *L, const l_char *key, int d) { | |||
461 | lua_pushstring(L, key); | 461 | lua_pushstring(L, key); |
462 | lua_rawget(L, -2); | 462 | lua_rawget(L, -2); |
463 | if (lua_isnumber(L, -1)) | 463 | if (lua_isnumber(L, -1)) |
464 | res = (int)lua_tonumber(L, -1); | 464 | res = (int)(lua_tonumber(L, -1)); |
465 | else { | 465 | else { |
466 | if (d == -2) | 466 | if (d == -2) |
467 | luaL_verror(L, l_s("field `%.20s' missing in date table"), key); | 467 | luaL_verror(L, l_s("field `%.20s' missing in date table"), key); |
@@ -474,9 +474,9 @@ static int getfield (lua_State *L, const l_char *key, int d) { | |||
474 | 474 | ||
475 | static int io_date (lua_State *L) { | 475 | static int io_date (lua_State *L) { |
476 | const l_char *s = luaL_opt_string(L, 1, l_s("%c")); | 476 | const l_char *s = luaL_opt_string(L, 1, l_s("%c")); |
477 | time_t t = (time_t)luaL_opt_number(L, 2, -1); | 477 | time_t t = (time_t)(luaL_opt_number(L, 2, -1)); |
478 | struct tm *stm; | 478 | struct tm *stm; |
479 | if (t == (time_t)-1) /* no time given? */ | 479 | if (t == (time_t)(-1)) /* no time given? */ |
480 | t = time(NULL); /* use current time */ | 480 | t = time(NULL); /* use current time */ |
481 | if (*s == l_c('!')) { /* UTC? */ | 481 | if (*s == l_c('!')) { /* UTC? */ |
482 | stm = gmtime(&t); | 482 | stm = gmtime(&t); |
@@ -525,7 +525,7 @@ static int io_time (lua_State *L) { | |||
525 | ts.tm_year = getfield(L, l_s("year"), -2)-1900; | 525 | ts.tm_year = getfield(L, l_s("year"), -2)-1900; |
526 | ts.tm_isdst = getfield(L, l_s("isdst"), -1); | 526 | ts.tm_isdst = getfield(L, l_s("isdst"), -1); |
527 | t = mktime(&ts); | 527 | t = mktime(&ts); |
528 | if (t == (time_t)-1) | 528 | if (t == (time_t)(-1)) |
529 | lua_pushnil(L); | 529 | lua_pushnil(L); |
530 | else | 530 | else |
531 | lua_pushnumber(L, t); | 531 | lua_pushnumber(L, t); |
@@ -535,8 +535,8 @@ static int io_time (lua_State *L) { | |||
535 | 535 | ||
536 | 536 | ||
537 | static int io_difftime (lua_State *L) { | 537 | static int io_difftime (lua_State *L) { |
538 | lua_pushnumber(L, difftime((time_t)luaL_check_number(L, 1), | 538 | lua_pushnumber(L, difftime((time_t)(luaL_check_number(L, 1)), |
539 | (time_t)luaL_opt_number(L, 2, 0))); | 539 | (time_t)(luaL_opt_number(L, 2, 0)))); |
540 | return 1; | 540 | return 1; |
541 | } | 541 | } |
542 | 542 | ||