[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: call logic
- From: Ben Sunshine-Hill <sneftel@...>
- Date: Tue, 23 Aug 2005 13:43:05 -0700
There's no magic. The expression 'perm{"a", "b", "c"}' is evaluated,
and its result (the unnamed function which is returned by
coroutine.wrap) is used as the generator function for the for-block.
Ben
On 8/23/05, Brent Arias <barias@signaturedevices.com> wrote:
> 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
>
>