aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorThomas Harning Jr <harningt@gmail.com>2007-09-06 23:55:48 -0400
committerThomas Harning Jr <harningt@gmail.com>2007-09-06 23:55:48 -0400
commit978194f3f80a1e7c47903ee076ef98f9ac439675 (patch)
treec7052bf1f25daf1c530dfaa1b2742412f0350593 /src
parent155729f0539f56017af464798d32509c697186fe (diff)
downloadluaevent-prosody-978194f3f80a1e7c47903ee076ef98f9ac439675.tar.gz
luaevent-prosody-978194f3f80a1e7c47903ee076ef98f9ac439675.zip
event_buffer:get_data learned (len) and (begin,len) API
Diffstat (limited to 'src')
-rw-r--r--src/event_buffer.c25
1 files changed, 24 insertions, 1 deletions
diff --git a/src/event_buffer.c b/src/event_buffer.c
index 23d67e7..b778e2f 100644
--- a/src/event_buffer.c
+++ b/src/event_buffer.c
@@ -92,7 +92,30 @@ static int event_buffer_get_length(lua_State* L) {
/* MAYBE: Could add caching */
static int event_buffer_get_data(lua_State* L) {
le_buffer* buf = event_buffer_check(L, 1);
- lua_pushlstring(L, (const char*)EVBUFFER_DATA(buf->buffer), EVBUFFER_LENGTH(buf->buffer));
+ int begin, len;
+ switch(lua_gettop(L)) {
+ case 1:
+ /* Obtain full data */
+ begin = 0;
+ len = EVBUFFER_LENGTH(buf->buffer);
+ break;
+ case 2:
+ begin = 0;
+ len = luaL_checkinteger(L, 2);
+ if(len > EVBUFFER_LENGTH(buf->buffer))
+ len = EVBUFFER_LENGTH(buf->buffer);
+ break;
+ case 3:
+ default:
+ begin = luaL_checkinteger(L, 2);
+ len = luaL_checkinteger(L, 3);
+ if(begin > EVBUFFER_LENGTH(buf->buffer))
+ begin = EVBUFFER_LENGTH(buf->buffer);
+ if(begin + len > EVBUFFER_LENGTH(buf->buffer))
+ len = EVBUFFER_LENGTH(buf->buffer) - begin;
+ break;
+ }
+ lua_pushlstring(L, (const char*)EVBUFFER_DATA(buf->buffer) + begin, len);
return 1;
}