lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

(I sent out the original announcement just before the mailing list
went down in August, and have since added a lot of features.)

I wrote a library to do Erlang-style pattern matching in Lua. Rather
than writing a series of nested ifs to test/switch on a table's
structure, you can just specify the table itself, possibly with
variable captures. Pattern strings are also supported.


It's implemented in pure Lua (tested with Lua 5.1.4), so it should be
quite portable, and it's reasonably efficient. It uses linear search
with various kinds of indexing, most notably on the first pattern
value (as in Erlang and Prolog). I tried more complicated strategies,
such as compiling the pattern spec into CPS, but the compilation
(which, being Lua, happened at runtime) took too long to justify
teh slight improvement the matching speed. Indexing is fast and
still quite effective.

For usage examples, see the README, API docs, benchmark, and test
suite. More documentation and a rockspec will come soon.

I hope it's useful!