From fb602839744a1e4d1c966ca4ab5640231c155cd3 Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Tue, 28 Dec 1999 09:52:49 -0200 Subject: better error messages --- liolib.c | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) (limited to 'liolib.c') diff --git a/liolib.c b/liolib.c index a99820f6..df8e5c53 100644 --- a/liolib.c +++ b/liolib.c @@ -1,5 +1,5 @@ /* -** $Id: liolib.c,v 1.52 1999/11/22 17:39:51 roberto Exp roberto $ +** $Id: liolib.c,v 1.53 1999/12/27 13:04:53 roberto Exp roberto $ ** Standard I/O (and system) library ** See Copyright Notice in lua.h */ @@ -395,20 +395,17 @@ static void io_write (lua_State *L) { FILE *f = getfileparam(L, FOUTPUT, &arg); int status = 1; lua_Object o; - while ((o = lua_getparam(L, arg++)) != LUA_NOOBJECT) { - switch (lua_type(L, o)[2]) { - case 'r': { /* stRing? */ - long l = lua_strlen(L, o); - status = status && - ((long)fwrite(lua_getstring(L, o), sizeof(char), l, f) == l); - break; - } - case 'm': /* nuMber? */ /* LUA_NUMBER */ - /* optimization: could be done exactly as for strings */ - status = status && fprintf(f, "%.16g", lua_getnumber(L, o)) > 0; - break; - default: luaL_argerror(L, arg-1, "string expected"); + while ((o = lua_getparam(L, arg)) != LUA_NOOBJECT) { + if (lua_type(L, o)[2] == 'm') { /* nuMber? */ /* LUA_NUMBER */ + /* optimization: could be done exactly as for strings */ + status = status && fprintf(f, "%.16g", lua_getnumber(L, o)) > 0; + } + else { + long l; + const char *s = luaL_check_lstr(L, arg, &l); + status = status && ((long)fwrite(s, sizeof(char), l, f) == l); } + arg++; } pushresult(L, status); } -- cgit v1.2.3-55-g6feb