Regular expressions for Lua
#1
In my internship I've come across regular expressions allot, and I now realize how powerful they are compared to Lua patterns. Lua patterns suffice for almost any occasion, but it might scare developers away when they learn that Lua doesn't have Regex.

I thought we could add some really simple regex support. Just by putting a few functions in a table that basically calls preg_XYZ. I'd do it myself if there are no objections.
Reply
Thanks given by:
#2
There's already several Lua libraries for regexp work, LPeg is most likely the best known. I don't think it's worth rolling our own, unless there are reasons to do so.

Also, I don't think it's a good strategy to just bloat the server with all the libraries. It works with LuaRocks and possibly other integration systems, I'd leave it at that. We don't want to maintain a zillion binding libraries.
Reply
Thanks given by:
#3
I was just thinking about something simple like this:
static int tolua_RegexMatch(lua_State * tolua_S)
{
	cLuaState S(tolua_S)
	if (
		!S.CheckParamString(1, 2)
	)
	{
		return 0;
	}
	
	AString str, regexstring, res;
	L.GetStackValues(1, str, regexstring);
	
	std::regex reg(regexstring);
	res = std::regex_match(str, reg);
	
	L.Push(res);
}

///
//...
///

tolua_beginmodule(tolua_S, "cRegex");
	tolua_function(tolua_S, "Match", tolua_RegexMatch);
tolua_endmodule(tolua_S);

Reply
Thanks given by:




Users browsing this thread: 1 Guest(s)