Here's a file that I ran with pdftex and with luatex: both worked. Worked for me too (also tex and etex; xetex still fails, of course, but that's ok). Nice job. I could ask my LuaTeX friends if we're missing anything, but it looks straightforward.
My only comment is merely stylistic: for this tiny chunk of code, I'd be tempted to just use the fully-qualified names (unicode.utf8.char, string.byte, string.gsub) instead of defining and then using abbreviations -- especially since they are only used once, I think. But that's just me. Thanks, Karl