lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


In the manual here: http://www.lua.org/pil/9.3.html

The following wrapped coroutine is demonstrated:

    for p in perm{"a", "b", "c"} do
      printResult(p)
    end

    function perm (a)
      local n = table.getn(a)
      return coroutine.wrap(function () permgen(a, n) end)
    end

What I don't understand, is what principle or rule of lua is preventing
perm{"a","b","c"} to get called over and over again.  I mean, evidently
"perm" is only called once, and the coroutine is the only part that keeps on
executing after the initial call to "perm."  I would have thought that
"perm" would get called over and over as well, causing this loop to never
end (or the coroutine.wrap to be executed over and over again).

What magic is at work here?

-Brent