On Thu, Mar 6, 2014 at 11:26 PM, Cheyi Lin <cheyi.lin@xxxxxxxxx> wrote: > Thanks for the replies, > > Sorry about lack of related context, here it is, foo.lua and main.lua. > -- end of foo.lua > > -- [ main.lua ] > > local Foo = require("foo") > local N = 4 > > foo = Foo:new() > bar = > function (foo, i) > -- do something irrelevant > end > > foo:push_handler( > function () > for i = 1, N do -- // PROBLEM HERE // > print(i) > bar(foo, i) > end > end) > > foo:register_event("my_event", > function () > local h = foo:pop_handler() > if h then h() end > end) > > foo:trigger_event("my_event") > > -- end of main.lua > > 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? Kaj