lua-users home
lua-l archive

Re: Is this a scoping issue?

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


Unfortunately, I get 2 different results depending on what I've passed to coroutine.create(). If I pass process() , the code runs to the same point (where I call the lua function that will call coroutine.resume), however the pcall fails when I pass process() to coroutine.create. However, I would expect that just passing process is proper, it still does not function as I would assume. I have a proof of concept application that does this just fine (with all the lua in a single file) and it uses lua_dofile instead of lua_dobuffer.
Anyone have any thoughts as to why?
jdarling@eonclash.com wrote:
Oddly enough though, in another article it shows the following code:
local thread_id = 0
local threads = {}
function fn(thread)
 thread_id = thread_id + 1
 threads[thread_id] = function()
 thread = nil
 end
 coroutine.yield()
end
while true do
 local thread = coroutine.create(fn)
 coroutine.resume(thread, thread)
end
So I'm confused and obviously haven't played with co-routines at all :)
- Jeremy
"Help I suffer from the oxymoron Corporate Security."
-------- Original Message --------
Subject: Re: Is this a scoping issue?
From: Lee Smith <wink@gettcomm.com>
Date: Thu, March 16, 2006 12:21 pm
To: Lua list <lua@bazar2.conectiva.com.br>
I don't believe so. It is created suspended, and I want it to start, but for some reason I can't resume it once it has yielded.
jdarling@eonclash.com wrote:
Shouldn't you be calling yield() instead of resume(co)?
- Jeremy
"Help I suffer from the oxymoron Corporate Security."
-------- Original Message --------
Subject: Is this a scoping issue?
From: Lee Smith <wink@gettcomm.com>
Date: Thu, March 16, 2006 11:41 am
To: lua@bazar2.conectiva.com.br
I'm having some problems with a coroutine I create. Here is the order of things: I create a lua_State and load 3 files into it, each containing its own function as follows:
In file1:
function init()
 print "init"
 co = coroutine.create(process)
 coroutine.resume(co)
end
In file2:
function process()
 print "yielding the coroutine"
 coroutine.yield()
 print "running again"
end
In file3:
function callback()
 print "resuming"
 print(coroutine.resume(co))
end
Now, when I make a lua_pcall to init, the coroutine starts the process function just like I would expect. Once it yields, I run off and do some stuff in my c code, and then pcall callback to wake the coroutine back up. However the call to resume is failing. Here is my output:
init
yielding the coroutine
c++ - doing some work
resuming
false cannot resume non-suspended coroutine
Any ideas as to where I've gone wrong?

AltStyle によって変換されたページ (->オリジナル) /