66 |
66 |
67 /* LUA: buffer:add(...) |
67 /* LUA: buffer:add(...) |
68 progressively adds items to the buffer |
68 progressively adds items to the buffer |
69 if arg[*] is string, treat as a string:format call |
69 if arg[*] is string, treat as a string:format call |
70 if arg[*] is a buffer, perform event_add_buffer |
70 if arg[*] is a buffer, perform event_add_buffer |
|
71 expects at least 1 other argument |
71 returns number of bytes added |
72 returns number of bytes added |
72 */ |
73 */ |
73 static int event_buffer_add(lua_State* L) { |
74 static int event_buffer_add(lua_State* L) { |
74 le_buffer* buf = event_buffer_check(L, 1); |
75 le_buffer* buf = event_buffer_check(L, 1); |
75 struct evbuffer* buffer = buf->buffer; |
76 struct evbuffer* buffer = buf->buffer; |
76 int oldLength = EVBUFFER_LENGTH(buffer); |
77 int oldLength = EVBUFFER_LENGTH(buffer); |
77 int last = lua_gettop(L); |
78 int last = lua_gettop(L); |
78 int i; |
79 int i; |
|
80 if(last == 1) luaL_error(L, "Not enough arguments to add: expects at least 1 additional operand"); |
79 for(i = 2; i <= last; i++) { |
81 for(i = 2; i <= last; i++) { |
80 if(!lua_isstring(L, i) && !is_event_buffer(L, i)) |
82 if(!lua_isstring(L, i) && !is_event_buffer(L, i)) |
81 luaL_argerror(L, i, "Argument is not a string or buffer object"); |
83 luaL_argerror(L, i, "Argument is not a string or buffer object"); |
82 if(lua_equal(L, 1, i)) |
84 if(lua_equal(L, 1, i)) |
83 luaL_argerror(L, i, "Cannot add buffer to itself"); |
85 luaL_argerror(L, i, "Cannot add buffer to itself"); |