MCPcopy Create free account
hub / github.com/EmmyLua/EmmyLuaDebugger / g_write

Function g_write

third-party/lua-5.5.0/src/liolib.c:663–687  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

661
662
663static int g_write (lua_State *L, FILE *f, int arg) {
664 int nargs = lua_gettop(L) - arg;
665 size_t totalbytes = 0; /* total number of bytes written */
666 errno = 0;
667 for (; nargs--; arg++) { /* for each argument */
668 char buff[LUA_N2SBUFFSZ];
669 const char *s;
670 size_t numbytes; /* bytes written in one call to 'fwrite' */
671 size_t len = lua_numbertocstring(L, arg, buff); /* try as a number */
672 if (len > 0) { /* did conversion work (value was a number)? */
673 s = buff;
674 len--;
675 }
676 else /* must be a string */
677 s = luaL_checklstring(L, arg, &len);
678 numbytes = fwrite(s, sizeof(char), len, f);
679 totalbytes += numbytes;
680 if (numbytes < len) { /* write error? */
681 int n = luaL_fileresult(L, 0, NULL);
682 lua_pushinteger(L, cast_st2S(totalbytes));
683 return n + 1; /* return fail, error msg., error code, and counter */
684 }
685 }
686 return 1; /* no errors; file handle already on stack top */
687}
688
689
690static int io_write (lua_State *L) {

Callers 2

io_writeFunction · 0.70
f_writeFunction · 0.70

Calls 4

lua_gettopFunction · 0.70
luaL_checklstringFunction · 0.70
luaL_fileresultFunction · 0.70
lua_pushintegerFunction · 0.70

Tested by

no test coverage detected