lua-users home
lua-l archive

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

On 05/28/2013 01:22 AM, Ram Prasad wrote:
Hi All,

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.

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.