| 620 | |
| 621 | |
| 622 | static int g_write (lua_State *L, FILE *f, int arg) { |
| 623 | int nargs = lua_gettop(L) - arg; |
| 624 | int status = 1; |
| 625 | for (; nargs--; arg++) { |
| 626 | if (lua_type(L, arg) == LUA_TNUMBER) { |
| 627 | /* optimization: could be done exactly as for strings */ |
| 628 | int len = lua_isinteger(L, arg) |
| 629 | ? fprintf(f, LUA_INTEGER_FMT, |
| 630 | (LUAI_UACINT)lua_tointeger(L, arg)) |
| 631 | : fprintf(f, LUA_NUMBER_FMT, |
| 632 | (LUAI_UACNUMBER)lua_tonumber(L, arg)); |
| 633 | status = status && (len > 0); |
| 634 | } |
| 635 | else { |
| 636 | size_t l; |
| 637 | const char *s = luaL_checklstring(L, arg, &l); |
| 638 | status = status && (fwrite(s, sizeof(char), l, f) == l); |
| 639 | } |
| 640 | } |
| 641 | if (status) return 1; /* file handle already on stack top */ |
| 642 | else return luaL_fileresult(L, status, NULL); |
| 643 | } |
| 644 | |
| 645 | |
| 646 | static int io_write (lua_State *L) { |
no test coverage detected