Re: global & unique
[
Date Prev][
Date Next][
Thread Prev][
Thread Next]
[
Date Index]
[
Thread Index]
- Subject: Re: global & unique
- From: Nodir Temirhodzhaev <tnodir@...>
- Date: 2004年4月21日 11:23:01 +0400 (MSD)
>From manual:
"Different instances of the same function may refer to
different
external local variables and may have different environment
tables."
---
local function pr() print(s) end
local function th(a)
setfenv(pr, setmetatable({s = a}, {__index = _G}))
pr()
coroutine.yield()
pr()
end
local co1, co2 = coroutine.create(th), coroutine.create(th)
coroutine.resume(co1, 1)
coroutine.resume(co2, 2)
coroutine.resume(co1)
coroutine.resume(co2)
---
Prints:
1
2
2
2
Expecting:
1
2
1
2
I don't understand, why functions have own environment
and not use environment of current thread?