Is there / please suggest a syntax to achieve a compact 'test and assign' in lua?
Consider this segment from luasql examples ( http://keplerproject.org/luasql/examples.html )
-- retrieve a cursor
cur = assert (con:execute"SELECT name, email from people")
-- print all rows, the rows will be indexed by field names
row = cur:fetch ({}, "a")
while row do
print(string.format("Name: %s, E-mail: %s", row.name, row.email))
-- reusing the table of results
row = cur:fetch (row, "a")
end
I am learning lua, and really struggling to accept the duplicated call to cur:fetch(). I see that repeat/until trivially fixes the issue, but then it seems I have to test twice:
repeat
row = cur:fetch ({}, "a")
if row then
print ...
end
until nil == row
I consider this less error prone for the case of 'row = ...' getting more complex, but still seems inelegant.