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