a pure Lua implementation