Re: Weird numeric for loop counter variable behavior

  • From: Cheyi Lin <cheyi.lin@xxxxxxxxx>
  • To: luajit@xxxxxxxxxxxxx
  • Date: Fri, 7 Mar 2014 16:51:05 +0800

Kaj Eijlers <bizziboi@xxxxxxxxx> wrote:
> My first question would be, is it indeed guaranteed that bar() does
> something irrelevant? It could be assigning to a local variable N while
> forgetting to declare it - and give the issue you see?

Sorry the handler snippet should be:

foo:push_handler(
  function ()
    for i = 1, N do  -- // PROBLEM HERE //
      if i < 0 or i > 4 then
        print(i, N)  -- got i = 5, N = 4
      end
      bar(foo, i)
    end
  end)

I can guarantee that the local variable N has not been modified during
the bar() is called.
Thank you for pointing that out.

Other related posts: