LUA_FUNCTION_DEF (text, gc);
LUA_FUNCTION_DEF (text, eq);
LUA_FUNCTION_DEF (text, lt);
+LUA_FUNCTION_DEF (text, concat);
static const struct luaL_reg textlib_f[] = {
LUA_INTERFACE_DEF (text, fromstring),
{"__gc", lua_text_gc},
{"__eq", lua_text_eq},
{"__lt", lua_text_lt},
+ {"__concat", lua_text_concat},
{NULL, NULL}
};
else if (pos_type == LUA_TSTRING) {
/* Fake static lua_text */
static struct rspamd_lua_text fake_text;
+ gsize len;
- fake_text.start = lua_tolstring (L, pos, &fake_text.len);
+ fake_text.start = lua_tolstring (L, pos, &len);
+ if (len >= G_MAXUINT) {
+ return NULL;
+ }
+
+ fake_text.len = len;
fake_text.flags = RSPAMD_TEXT_FLAG_FAKE;
return &fake_text;
lua_text_eq (lua_State *L)
{
LUA_TRACE_POINT;
- struct rspamd_lua_text *t1 = lua_check_text (L, 1),
+ struct rspamd_lua_text *t1 = lua_check_text_or_string (L, 1),
*t2 = lua_check_text_or_string (L, 2);
if (t1->len == t2->len) {
lua_text_lt (lua_State *L)
{
LUA_TRACE_POINT;
- struct rspamd_lua_text *t1 = lua_check_text (L, 1),
+ struct rspamd_lua_text *t1 = lua_check_text_or_string (L, 1),
*t2 = lua_check_text_or_string (L, 2);
if (t1 && t2) {
return 1;
}
+static gint
+lua_text_concat (lua_State *L)
+{
+ LUA_TRACE_POINT;
+ struct rspamd_lua_text *t1 = lua_check_text_or_string (L, 1),
+ *t2 = lua_check_text_or_string (L, 2);
+
+ if (t1 && t2) {
+ struct rspamd_lua_text *final;
+
+ final = lua_new_text (L, NULL, t1->len + t2->len, TRUE);
+ memcpy ((void *)final->start, t1->start, t1->len);
+ memcpy ((void *)(final->start + t1->len), t2->start, t2->len);
+ }
+
+ return 1;
+}
+
static gint
lua_text_wipe (lua_State *L)
{