lua-users home
lua-l archive

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


Hello Luiz,

Thursday, December 21, 2006, 5:25:49 PM, you wrote:

>> But message process and create window may not in the same coroutine.
>> For example, if you are calling UpdateWindow in a lua coroutine.
>> UpdateWindow will call SendMessage(hWnd,WM_PAINT) , and this will call
>> my WinProc . At this time, it needs coroutine's lua_State *L , not the
>> lua_State at the time window created .

LHdF> This is a common problem in some APIs. If you cannot store callback data
LHdF> in WinProc, then the best you can do is to store the Lua state in a global
LHdF> variable everytime you get in C from Lua, ie, everytime Lua calls C. I've
LHdF> done that on a some occasions for error handling and other interrupts.
LHdF> See my lalarm, lbc, lgdbm and lmapm. Look for LL.

Maybe we can add a record in struct lua_State :) (IMHO)
Store running lua state into the main lua state everytime we switch the coroutine. (in
lua_resume)

We don't need store lua state everytime lua calls C, because lua state
must not changed until call lua_resume. And we can get this running
lua state from any interrelated lua state.

-- 
Best regards,
 Cloud                            mailto:cloudwu@163.com
            http://blog.codingnow.com

[先相信自己, 然后别人才会相信你]