lua-users home
lua-l archive

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


your function has 'a' defined as a global. change it to 'local a = ...' and you get what you expect

-j

On 7/10/06, Diman Todorov < diman@xover.mud.at> wrote:
Hello list,

narf = function()
         a = coroutine.yield()
         coroutine.yield()
         print(a)
end

co1 = coroutine.create(narf)
co2 = coroutine.create(narf)

coroutine.resume(co1)
coroutine.resume(co2)

coroutine.resume (co1, "narf")
coroutine.resume(co2, "zod")

coroutine.resume(co1)
coroutine.resume(co2)

<snip>
Quintillian:~/tmp diman$ lua narf.lua
zod
zod
Quintillian:~/tmp diman$
<snip>

It seems, that LUA uses the same memory to store the variable 'a' for
both coroutines
Is this a feature, is it a bug and how can i avoid it?
Can i not somehow 'duplicate' the function prior to resuming it?

regards
Diman