davidm/luacom — Issue #2: StartMessageLoop only called once before blocking
Author: TobyD
Created: 2011-11-03 18:31:31+00:00
State: open

There is a good chance that I am doing something wrong, but when trying to implement some event callbacks for a Lecroy Voyager M3i USB analyzer I am finding that my call to StartMessageLoop() from a lua script will block. I took a look at the luacom_StartMessageLoop code in luacom.cpp and see that it is calling GetMessage - a blocking call. I'm not sure what the solution should be...perhaps using PeekMessage (with the PM_REMOVE parameter to remove the message after processing) instead of GetMessage? Although then the loop would only run until there are no more messages to process. For now I created a new method luacom_NextMessage (shown below) and I call it everytime I want to querry the queue. That seems to be working. Am I doing something wrong? Is this a bug? Is there a better way to ensure events get handled?

```lua
int luacom_NextMessage(lua_State *L)
{
MSG msg;
if(PeekMessage(&msg, NULL, 0, 0, 1)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return 0;
}
```