| 658 | |
| 659 | |
| 660 | static int g_write (lua_State *L, FILE *f, int arg) { |
| 661 | int nargs = lua_gettop(L) - arg; |
| 662 | int status = 1; |
| 663 | for (; nargs--; arg++) { |
| 664 | if (lua_type(L, arg) == LUA_TNUMBER) { |
| 665 | /* optimization: could be done exactly as for strings */ |
| 666 | int len = lua_isinteger(L, arg) |
| 667 | ? fprintf(f, LUA_INTEGER_FMT, |
| 668 | (LUAI_UACINT)lua_tointeger(L, arg)) |
| 669 | : fprintf(f, LUA_NUMBER_FMT, |
| 670 | (LUAI_UACNUMBER)lua_tonumber(L, arg)); |
| 671 | status = status && (len > 0); |
| 672 | } |
| 673 | else { |
| 674 | size_t l; |
| 675 | const char *s = luaL_checklstring(L, arg, &l); |
| 676 | status = status && (fwrite(s, sizeof(char), l, f) == l); |
| 677 | } |
| 678 | } |
| 679 | if (l_likely(status)) |
| 680 | return 1; /* file handle already on stack top */ |
| 681 | else return luaL_fileresult(L, status, NULL); |
| 682 | } |
| 683 | |
| 684 | |
| 685 | static int io_write (lua_State *L) { |
no test coverage detected