diff options
Diffstat (limited to 'src/buffer.c')
-rw-r--r-- | src/buffer.c | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/src/buffer.c b/src/buffer.c index 30be156..a696158 100644 --- a/src/buffer.c +++ b/src/buffer.c | |||
@@ -60,6 +60,17 @@ int buf_meth_getstats(lua_State *L, p_buf buf) { | |||
60 | } | 60 | } |
61 | 61 | ||
62 | /*-------------------------------------------------------------------------*\ | 62 | /*-------------------------------------------------------------------------*\ |
63 | * object:setstats() interface | ||
64 | \*-------------------------------------------------------------------------*/ | ||
65 | int buf_meth_setstats(lua_State *L, p_buf buf) { | ||
66 | buf->received = (long) luaL_optnumber(L, 2, buf->received); | ||
67 | buf->sent = (long) luaL_optnumber(L, 3, buf->sent); | ||
68 | if (lua_isnumber(L, 4)) buf->birthday = tm_gettime() - lua_tonumber(L, 4); | ||
69 | lua_pushnumber(L, 1); | ||
70 | return 1; | ||
71 | } | ||
72 | |||
73 | /*-------------------------------------------------------------------------*\ | ||
63 | * object:send() interface | 74 | * object:send() interface |
64 | \*-------------------------------------------------------------------------*/ | 75 | \*-------------------------------------------------------------------------*/ |
65 | int buf_meth_send(lua_State *L, p_buf buf) { | 76 | int buf_meth_send(lua_State *L, p_buf buf) { |
@@ -68,12 +79,12 @@ int buf_meth_send(lua_State *L, p_buf buf) { | |||
68 | int err = IO_DONE; | 79 | int err = IO_DONE; |
69 | size_t size, sent; | 80 | size_t size, sent; |
70 | const char *data = luaL_checklstring(L, 2, &size); | 81 | const char *data = luaL_checklstring(L, 2, &size); |
71 | ssize_t start = (ssize_t) luaL_optnumber(L, 3, 1); | 82 | long start = (long) luaL_optnumber(L, 3, 1); |
72 | ssize_t end = (ssize_t) luaL_optnumber(L, 4, -1); | 83 | long end = (long) luaL_optnumber(L, 4, -1); |
73 | if (start < 0) start = size+start+1; | 84 | if (start < 0) start = size+start+1; |
74 | if (end < 0) end = size+end+1; | 85 | if (end < 0) end = size+end+1; |
75 | if (start < 1) start = 1; | 86 | if (start < 1) start = 1; |
76 | if (end > size) end = size; | 87 | if (end > (long) size) end = size; |
77 | if (start <= end) err = sendraw(buf, data+start-1, end-start+1, &sent); | 88 | if (start <= end) err = sendraw(buf, data+start-1, end-start+1, &sent); |
78 | /* check if there was an error */ | 89 | /* check if there was an error */ |
79 | if (err != IO_DONE) { | 90 | if (err != IO_DONE) { |