lua-users home
lua-l archive

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


Now that I have coroutines up, i can pause them, resume them, create them, have many in parallel. Now, all i need is to learn Lua!

So my question is, once i spawn a coroutine, is its environment its own? For example:

test1.lua:
i = 0
while i < 10 do
   print("Sleeping 1", i)
   Events.sleep(0.5)
end

test2.lua:
i = 0
while i < 10 do
   print("Sleeping 2", i)
   Events.sleep(0.5)
end

And when i spawn them both at the same time i get this:

Sleeping 1, 1
Sleeping 2, 1
Sleeping 1, 2
Sleeping 2, 3
Sleeping 1, 4
Sleeping 2, 5
Sleeping 1, 6
Sleeping 2, 7
Sleeping 1, 8
Sleeping 2, 9
Sleeping 1, 10

So i guess it that both coroutines share the environment where 'i' is stored, or am i doing something wrong when i'm newing the coroutines?

--
// David Morris-Oliveros
// Camera & Lua Coder
// Team Bondi


------------------------------------------------------------------------
Contact:
Team Bondi Pty Ltd
Level 2, 608 Harris Street
Ultimo, NSW 2007
Australia
Tel: +61 (0)2 8218 1500
Fax: +61 (0)2 8218 1507
Web: http://www.teambondi.com
------------------------------------------------------------------------
This email may contain confidential information.  If you are not
the intended recipient, you may not copy or deliver this message to
anyone. In such case, you should destroy this message and kindly
notify the sender by reply email. Opinions, conclusions and other
information in this message that do not relate to the official business
of our firm shall be understood as neither given nor endorsed by it.
------------------------------------------------------------------------