lua-users home
lua-l archive

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


Hi,

On Thu, Apr 27, 2006 at 09:50:39AM +0100, Paul Hudson wrote:
> > To this function, you can pass a function and a list of arguments,
> > and this function will be called in each iteration of the loop:
> 
> I passed a simple "function () print ("Here") end" to this, and it does get
> called - but only once, as far as I can tell? And StartMessageLoop doesn't
> seem to return to my script.

Hmm, this is a bug. Thanks for noticing.
 
> >You can look at how this function is implemented to implement the same 
> >thing with coroutines (so you would call yield whtn you want another 
> >iteration of the message loop, instead of returning). LuaCOM had to work 
> >with Lua 4.0, also, so it does not use coroutines.
> 
> I'm not familiar enough with the LUA C API to make much progress here; I can
> look at the code but I don't know what it does or how to modify it.

Another approach is to write a function to run a single iterarion of the 
message loop, and call it from your script (move the loop to the 
script, basically). Pretty easy to write:

int luacom_MessageLoopStep(lua_State *L)
{
  MSG msg;
  if(GetMessage(&msg, NULL, 0, 0)) {
    TranslateMessage(&msg);
    DispatchMessage(&msg);
  }
  return 0;
}

Now add this to the functions_tb array, in luacom.cpp:

{"MessageLoopStep", luacom_MessageLoopStep}

And rebuild Luacom (there is a Makefile that works with Microsoft's 
nmake). This adds a luacom.MessageLoopStep function that runs a single 
iterarion of the Windows Message Loop.
 
> P.
> 

--
Fabio Mascarenhas

Attachment: signature.asc
Description: Digital signature