Lua closure-based solution