diff options
Diffstat (limited to 'lib/LuaRegex.cc')
-rw-r--r-- | lib/LuaRegex.cc | 27 |
1 files changed, 25 insertions, 2 deletions
diff --git a/lib/LuaRegex.cc b/lib/LuaRegex.cc index 16cf732..00c44ee 100644 --- a/lib/LuaRegex.cc +++ b/lib/LuaRegex.cc @@ -86,17 +86,40 @@ void LuaRegex::pushstatics(Lua * L) throw (GeneralException) { L->settable(LUA_GLOBALSINDEX); } +#define MAX_MATCHES 64 + int sLua_Regex::Regex_proceed(Lua * L, int n, Regex * r, int caller) { + int r = 0, i, n; + bool m; String s; + regmatch_t pmatches[MAX_MATCHES]; switch (caller) { case REGEX_MATCH: s = L->tostring(2); - L->push(r->Match(s)); + L->push(m = r->Match(s, MAX_MATCHES, pmatches)); + if (!m) + return 1; + L->newtable(); + n = 1; + for (i = 0; i < MAX_MATCHES; i++) { + if (pmatches[i].rm_so == -1) + continue; + L->push((lua_Number) n++); + L->newtable(); + L->push("start"); + L->push((lua_Number) patches.rm_so + 1); + L->settable(); + L->push("size"); + L->push((lua_Number) patches.rm_eo - patches.rm_so); + L->settable(); + L->settable(); + } + r = 2; break; } - return 1; + return r; } int sLua_Regex::Regex_proceed_statics(Lua * L, int n, int caller) { |