lua-users home
lua-l archive

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


Aaron, thanks for the reply. I was able to work around the issue. What I was seeing was that the pointer created with lua_open was different than the pointer I was recieving in my register'd function. eg:

lua_State *mystate = lua_open()

and my registered function

int dostuff(lua_State *L)

mystate and L were 2 totally different pointers, however, I could store the mystate pointer as lightuserdata in the state (right after I open it), and then in the dostuff function pull it out (via set/get global), cast it, and address the state that way. I'm just really confused as to why I would have 2 different pointers there.


-Lee

Aaron Brown wrote:

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.