diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1999-12-28 09:52:49 -0200 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1999-12-28 09:52:49 -0200 |
commit | fb602839744a1e4d1c966ca4ab5640231c155cd3 (patch) | |
tree | faa0f49d4840654d401e511dc186642a46eeb806 /liolib.c | |
parent | acdb0b741e31adebfa4f608f8bf23e65fa68d741 (diff) | |
download | lua-fb602839744a1e4d1c966ca4ab5640231c155cd3.tar.gz lua-fb602839744a1e4d1c966ca4ab5640231c155cd3.tar.bz2 lua-fb602839744a1e4d1c966ca4ab5640231c155cd3.zip |
better error messages
Diffstat (limited to 'liolib.c')
-rw-r--r-- | liolib.c | 25 |
1 files changed, 11 insertions, 14 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: liolib.c,v 1.52 1999/11/22 17:39:51 roberto Exp roberto $ | 2 | ** $Id: liolib.c,v 1.53 1999/12/27 13:04:53 roberto Exp roberto $ |
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 | */ |
@@ -395,20 +395,17 @@ static void io_write (lua_State *L) { | |||
395 | FILE *f = getfileparam(L, FOUTPUT, &arg); | 395 | FILE *f = getfileparam(L, FOUTPUT, &arg); |
396 | int status = 1; | 396 | int status = 1; |
397 | lua_Object o; | 397 | lua_Object o; |
398 | while ((o = lua_getparam(L, arg++)) != LUA_NOOBJECT) { | 398 | while ((o = lua_getparam(L, arg)) != LUA_NOOBJECT) { |
399 | switch (lua_type(L, o)[2]) { | 399 | if (lua_type(L, o)[2] == 'm') { /* nuMber? */ /* LUA_NUMBER */ |
400 | case 'r': { /* stRing? */ | 400 | /* optimization: could be done exactly as for strings */ |
401 | long l = lua_strlen(L, o); | 401 | status = status && fprintf(f, "%.16g", lua_getnumber(L, o)) > 0; |
402 | status = status && | 402 | } |
403 | ((long)fwrite(lua_getstring(L, o), sizeof(char), l, f) == l); | 403 | else { |
404 | break; | 404 | long l; |
405 | } | 405 | const char *s = luaL_check_lstr(L, arg, &l); |
406 | case 'm': /* nuMber? */ /* LUA_NUMBER */ | 406 | status = status && ((long)fwrite(s, sizeof(char), l, f) == l); |
407 | /* optimization: could be done exactly as for strings */ | ||
408 | status = status && fprintf(f, "%.16g", lua_getnumber(L, o)) > 0; | ||
409 | break; | ||
410 | default: luaL_argerror(L, arg-1, "string expected"); | ||
411 | } | 407 | } |
408 | arg++; | ||
412 | } | 409 | } |
413 | pushresult(L, status); | 410 | pushresult(L, status); |
414 | } | 411 | } |