aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorThomas Harning Jr <harningt@gmail.com>2007-09-07 00:10:08 -0400
committerThomas Harning Jr <harningt@gmail.com>2007-09-07 00:10:08 -0400
commita7c62b2e580b1456719cd0758b0c2230bc761836 (patch)
tree673ef57893e46a326a352e3dcb5782420d4dc54e /src
parent4afd8b5a3404aeba1999bff1054a777aaf9a423d (diff)
downloadluaevent-prosody-a7c62b2e580b1456719cd0758b0c2230bc761836.tar.gz
luaevent-prosody-a7c62b2e580b1456719cd0758b0c2230bc761836.zip
event_buffer learned readline and cleaned fn-list.
Diffstat (limited to 'src')
-rw-r--r--src/event_buffer.c29
1 files changed, 23 insertions, 6 deletions
diff --git a/src/event_buffer.c b/src/event_buffer.c
index e34f885..9d7b182 100644
--- a/src/event_buffer.c
+++ b/src/event_buffer.c
@@ -3,6 +3,7 @@
#include "event_buffer.h"
#include <lauxlib.h>
+#include <malloc.h>
#define EVENT_BUFFER_MT "EVENT_BUFFER_MT"
@@ -141,6 +142,21 @@ static int event_buffer_get_data(lua_State* L) {
return 1;
}
+/* LUA: buffer:readline()
+ Returns a line terminated by either '\r\n','\n\r' or '\r' or '\n'
+ Returns nil and leaves data alone if no terminator is found
+ TODO: Evaluate whether or not the newline is included
+*/
+static int event_buffer_readline(lua_State* L) {
+ le_buffer* buf = event_buffer_check(L, 1);
+ char* line = evbuffer_readline(buf->buffer);
+ if(!line)
+ return 0;
+ lua_pushstring(L, line);
+ free(line);
+ return 1;
+}
+
/* LUA: buffer:drain(amt)
Drains 'amt' bytes from the buffer
*/
@@ -152,15 +168,16 @@ static int event_buffer_drain(lua_State* L) {
}
static luaL_Reg buffer_funcs[] = {
- {"add",event_buffer_add},
- {"length",event_buffer_get_length},
- {"get_data",event_buffer_get_data},
- {"drain",event_buffer_drain},
- {"close",event_buffer_gc},
+ {"add", event_buffer_add},
+ {"length", event_buffer_get_length},
+ {"get_data", event_buffer_get_data},
+ {"readline", event_buffer_readline},
+ {"drain", event_buffer_drain},
+ {"close", event_buffer_gc},
{NULL, NULL}
};
static luaL_Reg funcs[] = {
- {"new",event_buffer_push_new},
+ {"new", event_buffer_push_new},
{NULL, NULL}
};