On Thu, 12 Jan 2017 09:51:28 +0000 "Robin H. Johnson" <robb...@orbis-terrarum.net> wrote:
> On Wed, Jan 11, 2017 at 12:17:26PM +0100, Willy Tarreau wrote: > > On Mon, Jan 09, 2017 at 08:47:17PM +0000, Robin H. Johnson wrote: > > > Maybe Willy would considering changing the name of the matches to 'prefix' > > > & 'suffix' instead of 'beg' & 'end', and just keep beg/end as legacy. > > Another approach would be to have simple rules when mapping a namespace > > to another one. For example we could easily imagine that all "map_something" > > in haproxy are mapped to their exact equivalent name in Lua (thus we would > > have "map_end" instead of "map.end"), or that we could prefix all these > > words by "_" which would give "map._end" which is not much different from > > the haproxy keyword "map_end" and easy enough to remember. > This is actually why I thought of Map.match_str, with a potential idea > that at some point it MIGHT become a bitfield for additional behaviors > (eg the output types per > https://cbonte.github.io/haproxy-dconv/1.6/configuration.html#7.3.1-map). > > The underscore is not sufficiently unique I think, but my knowledge of > Lua is nowhere near as extensive as I'd like. Hi, I prefer the prefix '_' because it is shorter that "match_". I'm confident for the unicity of these name because there are locked in the namespace "Map". If someone uses "_beg" or "_end" in other context, these new words will not conflict the the map pattern matching: the namespace "Map" differenciate this ones. I join a patch. Thierry > -- > Robin Hugh Johnson > E-Mail : robb...@orbis-terrarum.net > Home Page : http://www.orbis-terrarum.net/?l=people.robbat2 > ICQ# : 30269588 or 41961639 > GnuPG FP : 11ACBA4F 4778E3F6 E4EDF38E B27B944E 34884E85 >
>From dc3695a41af3d3a77681cec0ba23005d0370fc07 Mon Sep 17 00:00:00 2001 From: Thierry FOURNIER <thierry.fourn...@ozon.io> Date: Sat, 28 Jan 2017 08:33:08 +0100 Subject: [PATCH 1/2] BUG/MINOR: lua: Map.end are not reliable because "end" is a reserved keyword X-Bogosity: Ham, tests=bogofilter, spamicity=0.001260, version=1.2.4 This patch change the names prefixing it by a "_". So "end" becomes "_end". The backward compatibility with names without the prefix "_" is assured. In other way, another the keyword "end" can be used like this: Map['end']. Thanks Robin H. Johnson for the bug repport This should be backported in version 1.6 and 1.7 --- doc/lua-api/index.rst | 44 ++++++++++++++++++++++++++++++-------------- src/hlua.c | 4 ++++ 2 files changed, 34 insertions(+), 14 deletions(-) diff --git a/doc/lua-api/index.rst b/doc/lua-api/index.rst index e04c5b5..b6dcc23 100644 --- a/doc/lua-api/index.rst +++ b/doc/lua-api/index.rst @@ -1863,7 +1863,7 @@ Map class default = "usa" -- Create and load map - geo = Map.new("geo.map", Map.ip); + geo = Map.new("geo.map", Map._ip); -- Create new fetch that returns the user country core.register_fetches("country", function(txn) @@ -1888,60 +1888,76 @@ Map class return loc; end); -.. js:attribute:: Map.int +.. js:attribute:: Map._int See the HAProxy configuration.txt file, chapter "Using ACLs and fetching samples" ans subchapter "ACL basics" to understand this pattern matching method. -.. js:attribute:: Map.ip + Note that :js:attr:`Map.int` is also available for compatibility. + +.. js:attribute:: Map._ip See the HAProxy configuration.txt file, chapter "Using ACLs and fetching samples" ans subchapter "ACL basics" to understand this pattern matching method. -.. js:attribute:: Map.str + Note that :js:attr:`Map.p` is also available for compatibility. + +.. js:attribute:: Map._str See the HAProxy configuration.txt file, chapter "Using ACLs and fetching samples" ans subchapter "ACL basics" to understand this pattern matching method. -.. js:attribute:: Map.beg + Note that :js:attr:`Map.str` is also available for compatibility. + +.. js:attribute:: Map._beg See the HAProxy configuration.txt file, chapter "Using ACLs and fetching samples" ans subchapter "ACL basics" to understand this pattern matching method. -.. js:attribute:: Map.sub + Note that :js:attr:`Map.beg` is also available for compatibility. + +.. js:attribute:: Map._sub See the HAProxy configuration.txt file, chapter "Using ACLs and fetching samples" ans subchapter "ACL basics" to understand this pattern matching method. -.. js:attribute:: Map.dir + Note that :js:attr:`Map.sub` is also available for compatibility. + +.. js:attribute:: Map._dir See the HAProxy configuration.txt file, chapter "Using ACLs and fetching samples" ans subchapter "ACL basics" to understand this pattern matching method. -.. js:attribute:: Map.dom + Note that :js:attr:`Map.dir` is also available for compatibility. + +.. js:attribute:: Map._dom See the HAProxy configuration.txt file, chapter "Using ACLs and fetching samples" ans subchapter "ACL basics" to understand this pattern matching method. -.. js:attribute:: Map.end + Note that :js:attr:`Map.dom` is also available for compatibility. + +.. js:attribute:: Map._end See the HAProxy configuration.txt file, chapter "Using ACLs and fetching samples" ans subchapter "ACL basics" to understand this pattern matching method. -.. js:attribute:: Map.reg +.. js:attribute:: Map._reg See the HAProxy configuration.txt file, chapter "Using ACLs and fetching samples" ans subchapter "ACL basics" to understand this pattern matching method. + Note that :js:attr:`Map.reg` is also available for compatibility. + .. js:function:: Map.new(file, method) @@ -1951,10 +1967,10 @@ Map class :param integer method: Is the map pattern matching method. See the attributes of the Map class. :returns: a class Map object. - :see: The Map attributes: :js:attr:`Map.int`, :js:attr:`Map.ip`, - :js:attr:`Map.str`, :js:attr:`Map.beg`, :js:attr:`Map.sub`, - :js:attr:`Map.dir`, :js:attr:`Map.dom`, :js:attr:`Map.end` and - :js:attr:`Map.reg`. + :see: The Map attributes: :js:attr:`Map._int`, :js:attr:`Map._ip`, + :js:attr:`Map._str`, :js:attr:`Map._beg`, :js:attr:`Map._sub`, + :js:attr:`Map._dir`, :js:attr:`Map._dom`, :js:attr:`Map._end` and + :js:attr:`Map._reg`. .. js:function:: Map.lookup(map, str) diff --git a/src/hlua.c b/src/hlua.c index bfb9c94..41f1805 100644 --- a/src/hlua.c +++ b/src/hlua.c @@ -7258,6 +7258,10 @@ void hlua_init(void) /* register pattern types. */ for (i=0; i<PAT_MATCH_NUM; i++) hlua_class_const_int(gL.T, pat_match_names[i], i); + for (i=0; i<PAT_MATCH_NUM; i++) { + snprintf(trash.str, trash.size, "_%s", pat_match_names[i]); + hlua_class_const_int(gL.T, trash.str, i); + } /* register constructor. */ hlua_class_function(gL.T, "new", hlua_map_new); -- 1.7.10.4