Lua: broken, with sharp edges
Filed under: lua imapfilterI've seen a lot of people using Lua these days as an embedded language. I've been meaning to pick up on it as it looks like a nice, simple extension language.
Well that day just came. I discovered imapfilter, a (would-be) wonderful tool for filtering mail on remote IMAP servers, something I need since the mail filtering in Evolution broken-by-design (another story altogether) and I can't stand any other MUA's I've tried.
Anyway, imapfilter uses Lua as the language for writing filters. Seems like a good plan so I dove in. The first thing I discovered is that the Lua documentation leaves something to be desired. If there were just a bit more documentation, I'd call it bad documentation, unfortunately the sample given on the website isn't enough to draw any real conclusions. The second thing I discovered is that regular expressions in Lua aren't very regular. Instead they are sort of like regular expressions, only far less powerful, badly broken and poorly documented (even worse than the main Lua docs).
Doubt me? Okay, explain this:
Lua 5.1.1 Copyright (C) 1994-2006 Lua.org, PUC-Rio
> header = 'X-BeenThere: python-list@python.org'
> print(header:gsub('X-BeenThere:(.*)', '%1'))
X-python-list@python.org 1
>
Eh? Where does that leading "X- " come from? Hard to say. Maybe it's supposed to be there (does "-" mean something? It's hard to know given the ridiculously thin documentation on the matter). Given that pcre is widely adopted amongst all the better scripting languages and most of the bad ones, (not to mention half the non-trivial software on any Linux box) I fail to see why handling regular expressions should be an issue for any language these days. Frankly, in the time I wasted putzing around with the broken string-thing (I refuse to call it a regex parser) in Lua I could have rewritten imapfilter from scratch in Python.






