MCPcopy Create free account
hub / github.com/defold/defold / buffer_meth_send

Function buffer_meth_send

engine/script/src/luasocket/buffer.c:74–102  ·  view source on GitHub ↗

-------------------------------------------------------------------------*\ * object:send() interface \*-------------------------------------------------------------------------*/

Source from the content-addressed store, hash-verified

72* object:send() interface
73\*-------------------------------------------------------------------------*/
74int buffer_meth_send(lua_State *L, p_buffer buf) {
75 int top = lua_gettop(L);
76 int err = IO_DONE;
77 size_t size = 0, sent = 0;
78 const char *data = luaL_checklstring(L, 2, &size);
79 long start = (long) luaL_optnumber(L, 3, 1);
80 long end = (long) luaL_optnumber(L, 4, -1);
81 timeout_markstart(buf->tm);
82 if (start < 0) start = (long) (size+start+1);
83 if (end < 0) end = (long) (size+end+1);
84 if (start < 1) start = (long) 1;
85 if (end > (long) size) end = (long) size;
86 if (start <= end) err = sendraw(buf, data+start-1, end-start+1, &sent);
87 /* check if there was an error */
88 if (err != IO_DONE) {
89 lua_pushnil(L);
90 lua_pushstring(L, buf->io->error(buf->io->ctx, err));
91 lua_pushnumber(L, (lua_Number) (sent+start-1));
92 } else {
93 lua_pushnumber(L, (lua_Number) (sent+start-1));
94 lua_pushnil(L);
95 lua_pushnil(L);
96 }
97#ifdef LUASOCKET_DEBUG
98 /* push time elapsed during operation as the last return value */
99 lua_pushnumber(L, timeout_gettime() - timeout_getstart(buf->tm));
100#endif
101 return lua_gettop(L) - top;
102}
103
104/*-------------------------------------------------------------------------*\
105* object:receive() interface

Callers 3

meth_sendFunction · 0.85
meth_sendFunction · 0.85
meth_sendFunction · 0.85

Calls 11

lua_gettopFunction · 0.85
luaL_checklstringFunction · 0.85
luaL_optnumberFunction · 0.85
timeout_markstartFunction · 0.85
sendrawFunction · 0.85
lua_pushnilFunction · 0.85
lua_pushstringFunction · 0.85
lua_pushnumberFunction · 0.85
timeout_gettimeFunction · 0.85
timeout_getstartFunction · 0.85
errorMethod · 0.45

Tested by

no test coverage detected