| 608 | |
| 609 | |
| 610 | static int g_write(lua_State *L, FILE *f, int arg) { |
| 611 | int nargs = lua_gettop(L) - arg; |
| 612 | int status = 1; |
| 613 | for (; nargs--; arg++) { |
| 614 | if (lua_type(L, arg) == LUA_TNUMBER) { |
| 615 | /* optimization: could be done exactly as for strings */ |
| 616 | int len = lua_isinteger(L, arg) |
| 617 | ? fprintf(f, LUA_INTEGER_FMT, lua_tointeger(L, arg)) |
| 618 | : fprintf(f, LUA_NUMBER_FMT, lua_tonumber(L, arg)); |
| 619 | status = status && (len > 0); |
| 620 | } |
| 621 | else { |
| 622 | size_t l; |
| 623 | const char *s = luaL_checklstring(L, arg, &l); |
| 624 | status = status && (fwrite(s, sizeof(char), l, f) == l); |
| 625 | } |
| 626 | } |
| 627 | if (status) return 1; /* file handle already on stack top */ |
| 628 | else return luaL_fileresult(L, status, nullptr); |
| 629 | } |
| 630 | |
| 631 | |
| 632 | static int io_write(lua_State *L) { |
no test coverage detected