lua-users home
lua-l archive

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


Javier wrote:

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
"coroutine.create(process()).

Jeremy wrote:

process = 'some value';
function process()
  print process;
end

process()

You will recieve an output of:
some value

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

 print(process)

then the output is

 function: 00441950

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:

 do
   process = 'some value' -- This could also be local.
   local process = function()
     print(process)
   end

   process()
 end

where the function is in a local variable but references a
global variable.

--
Aaron