| 411 | |
| 412 | |
| 413 | static int g_write (lua_State *L, FILE *f, int arg) { |
| 414 | int nargs = lua_gettop(L) - 1; |
| 415 | int status = 1; |
| 416 | for (; nargs--; arg++) { |
| 417 | if (lua_type(L, arg) == LUA_TNUMBER) { |
| 418 | /* optimization: could be done exactly as for strings */ |
| 419 | status = status && |
| 420 | fprintf(f, LUA_NUMBER_FMT, lua_tonumber(L, arg)) > 0; |
| 421 | } |
| 422 | else { |
| 423 | size_t l; |
| 424 | const char *s = luaL_checklstring(L, arg, &l); |
| 425 | status = status && (fwrite(s, sizeof(char), l, f) == l); |
| 426 | } |
| 427 | } |
| 428 | return pushresult(L, status, NULL); |
| 429 | } |
| 430 | |
| 431 | |
| 432 | static int io_write (lua_State *L) { |
no test coverage detected