lua version

Here's a Lua version. Ported from the Perl version.
updated perl version