Welcome! Log In Create A New Profile

Advanced

HAProxy Lua Map.end & reserved keywords

Posted by Robin H. Johnson 
Robin H. Johnson
HAProxy Lua Map.end & reserved keywords
January 09, 2017 07:30PM
TL;DR:
'end' is a reserved Lua keyword, and cannot be used as a structure
member as in Map.end. Need to change the naming of constants maybe?

http://www.arpalert.org/src/haproxy-lua-api/1.7/index.html#map-class
> -- Create and load map
> geo = Map.new("geo.map", Map.ip);

Now if you want to use the match method 'end', the docs say to use
'Map.end'.

This is not legal Lua, because 'end' is a reserved keyword.

I see two potential ways forward:
a) Map['end'] # works right now, but ugly
b) Map.match_end # intent is much clearer

--
Robin Hugh Johnson
E-Mail : robbat2@orbis-terrarum.net
Home Page : http://www.orbis-terrarum.net/?l=people.robbat2
ICQ# : 30269588 or 41961639
GnuPG FP : 11ACBA4F 4778E3F6 E4EDF38E B27B944E 34884E85
Anonymous User
Re: HAProxy Lua Map.end & reserved keywords
January 09, 2017 08:10PM
On Mon, 9 Jan 2017 18:22:56 +0000
"Robin H. Johnson" <[email protected]> wrote:

> TL;DR:
> 'end' is a reserved Lua keyword, and cannot be used as a structure
> member as in Map.end. Need to change the naming of constants maybe?
>
> http://www.arpalert.org/src/haproxy-lua-api/1.7/index.html#map-class
> > -- Create and load map
> > geo = Map.new("geo.map", Map.ip);
>
> Now if you want to use the match method 'end', the docs say to use
> 'Map.end'.
>
> This is not legal Lua, because 'end' is a reserved keyword.
>
> I see two potential ways forward:
> a) Map['end'] # works right now, but ugly
> b) Map.match_end # intent is much clearer


Hi, thank for you comment ! You're absolutely right. This keyword
doesn't run because it is reserved. The good news is that I can change
the API because, obviously, nobody use this keyword :)

I agree, the solution "a" is ugly, but it is working now. I dont like
the solution "b", because the form of the word is different than other.

Maybe "suffix" in place of "end", but I prefer the same word that the
word used in haproxy configs.

I think that I will rename all the match keywords with the prefix
"match_", and keep the old names available, but undocumented for the
backward compatibility.

All the ideas are welcome.

Thierry


> --
> Robin Hugh Johnson
> E-Mail : robbat2@orbis-terrarum.net
> Home Page : http://www.orbis-terrarum.net/?l=people.robbat2
> ICQ# : 30269588 or 41961639
> GnuPG FP : 11ACBA4F 4778E3F6 E4EDF38E B27B944E 34884E85
>
Robin H. Johnson
Re: HAProxy Lua Map.end & reserved keywords
January 09, 2017 09:50PM
On Mon, Jan 09, 2017 at 07:49:40PM +0100, thierry.fournier@arpalert.org wrote:
> > I see two potential ways forward:
> > a) Map['end'] # works right now, but ugly
> > b) Map.match_end # intent is much clearer
> Hi, thank for you comment ! You're absolutely right. This keyword
> doesn't run because it is reserved. The good news is that I can change
> the API because, obviously, nobody use this keyword :)
Nobody used it until me it seems :-).

> I agree, the solution "a" is ugly, but it is working now. I dont like
> the solution "b", because the form of the word is different than other.
>
> Maybe "suffix" in place of "end", but I prefer the same word that the
> word used in haproxy configs.
>
> I think that I will rename all the match keywords with the prefix
> "match_", and keep the old names available, but undocumented for the
> backward compatibility.
Maybe Willy would considering changing the name of the matches to 'prefix'
& 'suffix' instead of 'beg' & 'end', and just keep beg/end as legacy.

--
Robin Hugh Johnson
E-Mail : robbat2@orbis-terrarum.net
Home Page : http://www.orbis-terrarum.net/?l=people.robbat2
ICQ# : 30269588 or 41961639
GnuPG FP : 11ACBA4F 4778E3F6 E4EDF38E B27B944E 34884E85
Willy Tarreau
Re: HAProxy Lua Map.end & reserved keywords
January 11, 2017 12:20PM
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.

It's convenient to keep short names there as they're commonly used in
anonymous ACLs involving paths. Or maybe "pfx" and "sfx" ? Anyway given
that they've been available for something like 10 years I'd say I don't
feel much comfortable with renaming this "just" due to incompatibilities
between multiple namespaces. This can get worse over time. Moreover, the
Lua version already doesn't use exactly the same name as the haproxy
variant.

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.

Regards,
willy
Robin H. Johnson
Re: HAProxy Lua Map.end & reserved keywords
January 12, 2017 11:00AM
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.

--
Robin Hugh Johnson
E-Mail : robbat2@orbis-terrarum.net
Home Page : http://www.orbis-terrarum.net/?l=people.robbat2
ICQ# : 30269588 or 41961639
GnuPG FP : 11ACBA4F 4778E3F6 E4EDF38E B27B944E 34884E85
Thierry Fournier
Re: HAProxy Lua Map.end & reserved keywords
January 19, 2017 07:50PM
Hi. Just a quick message: I don't forget this bug, I'm just just very busy.

Thierry


Le 12 janvier 2017 10:54:42 AM "Robin H. Johnson"
<[email protected]> a √©crit :

> 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.
>
> --
> Robin Hugh Johnson
> E-Mail : robbat2@orbis-terrarum.net
> Home Page : http://www.orbis-terrarum.net/?l=people.robbat2
> ICQ# : 30269588 or 41961639
> GnuPG FP : 11ACBA4F 4778E3F6 E4EDF38E B27B944E 34884E85
>
Sorry, only registered users may post in this forum.

Click here to login