[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Is this a scoping issue?
- From: "Aaron Brown" <arundelo@...>
- Date: Fri, 17 Mar 2006 12:25:26 -0500
i think it _is_ a scoping issue, the 'co' variable in
file3 might not be the same as 'co' in file 1.
If they're both global and all the files have the same
environment, then they should be the same.
To debug this, you (Lee) should try adding a "print(co)" in
init() and another in callback(). If they print the same
thing, then you know that the coroutine is the same and it's
just getting resumed somewhere between the yield and the
call to callback(). If they print different things, then
either another coroutine is getting created (and resumed)
somewhere and assigned to the same global variable, or it is
a scoping issue. There are two ways it could be a scoping
issue; to check for one, use "print(getfenv())" from within
init() and callback() -- if they print different things,
then you have two different environments. To check for the
other, search the files for a local variable named "co" that
might be shadowing the global.
You may also find coroutine.status() useful.
Also, Javier is correct that you want
"coroutine.create(process)" and not
process = 'some value';
You will recieve an output of:
Tested the idea in 502 and it worked, I'm not using 5.1 so
I can't speak for how it would work.
Actually, the above is a syntax error, but if the print line
is changed to
then the output is
because there's only one "process" variable (a global) and
it can't be both a function and a string at the same time.
You may have been thinking of something like this:
process = 'some value' -- This could also be local.
local process = function()
where the function is in a local variable but references a