| 512 | |
| 513 | |
| 514 | static int g_write (lua_State *L, FILE *f, int arg) { |
| 515 | int nargs = lua_gettop(L) - arg; |
| 516 | int status = 1; |
| 517 | for (; nargs--; arg++) { |
| 518 | if (lua_type(L, arg) == LUA_TNUMBER) { |
| 519 | /* optimization: could be done exactly as for strings */ |
| 520 | status = status && |
| 521 | fprintf(f, LUA_NUMBER_FMT, lua_tonumber(L, arg)) > 0; |
| 522 | } |
| 523 | else { |
| 524 | size_t l; |
| 525 | const char *s = luaL_checklstring(L, arg, &l); |
| 526 | status = status && (fwrite(s, sizeof(char), l, f) == l); |
| 527 | } |
| 528 | } |
| 529 | if (status) return 1; /* file handle already on stack top */ |
| 530 | else return luaL_fileresult(L, status, NULL); |
| 531 | } |
| 532 | |
| 533 | |
| 534 | static int io_write (lua_State *L) { |
no test coverage detected