luacom icon indicating copy to clipboard operation
luacom copied to clipboard

StartMessageLoop only called once before blocking

Open TobyD opened this issue 14 years ago • 1 comments

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?

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

TobyD avatar Nov 03 '11 18:11 TobyD

after start loop, you can send message to hwnd, and do what you want on message handler function.

wunoman avatar Feb 23 '24 09:02 wunoman