| 644 | |
| 645 | |
| 646 | static int g_write (lua_State *L, FILE *f, int arg) { |
| 647 | int nargs = lua_gettop(L) - arg; |
| 648 | int status = 1; |
| 649 | for (; nargs--; arg++) { |
| 650 | if (lua_type(L, arg) == LUA_TNUMBER) { |
| 651 | /* optimization: could be done exactly as for strings */ |
| 652 | int len = lua_isinteger(L, arg) |
| 653 | ? fprintf(f, LUA_INTEGER_FMT, |
| 654 | (LUAI_UACINT)lua_tointeger(L, arg)) |
| 655 | : fprintf(f, LUA_NUMBER_FMT, |
| 656 | (LUAI_UACNUMBER)lua_tonumber(L, arg)); |
| 657 | status = status && (len > 0); |
| 658 | } |
| 659 | else { |
| 660 | size_t l; |
| 661 | const char *s = luaL_checklstring(L, arg, &l); |
| 662 | status = status && (fwrite(s, sizeof(char), l, f) == l); |
| 663 | } |
| 664 | } |
| 665 | if (status) return 1; /* file handle already on stack top */ |
| 666 | else return luaL_fileresult(L, status, NULL); |
| 667 | } |
| 668 | |
| 669 | |
| 670 | static int io_write (lua_State *L) { |
no test coverage detected