Ported successfully to Lua

Written in Lua.