Observe that there is only one local variable. The rest are globals.
function rows (connection, sql_statement)local cursor = assert (connection:execute (sql_statement))return function ()return cursor:fetch()endendThe variable is local; but it is an upvalue, too, so it can only be collected when the closure is finalised, which means the return value of rows() needs to be a scoped variable.
But here is how it is supposed to be used:env = assert (require"luasql.mysql".mysql()
)con = assert (env:connect"my_db")for id, name, address in rows (con, "select * from contacts") doprint (string.format ("%s: %s", name, address))end