Iteration Bug?

Mar 3, 2015 at 12:59 AM
Edited Mar 3, 2015 at 1:04 AM
I'm having problems with lua code that iterates on a function. The included example prints values from 1 to 10 using a while loop and a for loop.
function range(i,n)
  return function()
    if i <= n then
      local r = i
      i = i + 1
      return r
    else
      return nil
    end
  end
end

print("while loop")
local r = range(1,10)
while true do
  local v = r()
  if v == nil then
    break
  else
    print(v)
  end
end

print("for loop")
for v in range(1,10) do
  print(v)
end  
NeoLua fails on the for loop section with the message:
No conversion defined from Func`1 to Func`3.
Both loops run fine when the same code is executed by this lua interpreter:
http://www.lua.org/cgi-bin/demo
Mar 3, 2015 at 1:01 AM
Edited Mar 3, 2015 at 1:05 AM
Sorry, I messed up the formatting. Edited.
Coordinator
Mar 3, 2015 at 9:55 AM
Work a round:
function range(i,n)
  return function(s,v)
    if i <= n then
      local r = i
      i = i + 1
      return r
    else
      return nil
    end
  end
end
Currently I check, what is the best way to make your first code work.
Coordinator
Mar 3, 2015 at 10:42 AM
Edited Mar 3, 2015 at 10:44 AM
Fixed: Commit on github

Do you need a release version (asap, 0.9.14)?
Mar 3, 2015 at 6:24 PM
Edited Mar 3, 2015 at 6:24 PM
A release version is not necessary. I was able to build from the github repository. Iteration works fine now.

Thanks!