[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Help needed with lua_resume / lua_yieldk with lua threads
- From: Thomas Jericke <tjericke@...>
- Date: Tue, 28 May 2013 07:55:38 +0000
On 05/28/2013 01:22 AM, Ram Prasad wrote:
I have done similar things, just without setting the _ENV variable.
Could you provide some code snippets. I am interested in how you set up
the lua tasks to start the functions, and how the yield and resume is
done. So what I need to know is, how are those "sessions" implemented.
Just thought I'd update you'll on my issue:
The issue was this :
When I was calling a lua script function (data()) for a client
session, say session1, I was setting its _ENV upvalue to the table
corresponding to session1.
When lua script function called my "sleep(n)" API, I did the lua_yieldk...
Now, when session2 came in, I called the same lua function (data()),
and I changed the function's _ENV upvalue to that corresponding to
So, when the lua function called sleep(n) and yeilded, the lua
function's (data()) _ENV upvalue was still set to that of session2.
And when the timer fired for session1, and we resumed the lua script
function (data()), the lua function still had its _ENV still set to
that of session2 - leading to problems.
In my test code, I am able to fix it as follows :
In the continuation function, I reset the _ENV upvalue of the lua
script function (data()) to that corresponding to that of the current
session (i.e. one for which timer fired).
This ensures that when lua script function executes after the sleep,
it finds the right _ENV.
Not sure whether doing the above in the continutation is the right
thing. I think I should be doing it in lua_userstateresume by
redifining those. Will dig more on that.
Just thought I will update y'll on this.
It's not that I'm so smart, it's just that I stay with problems longer
- Albert Einstein.