lua-users home
lua-l archive

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


I fixed the problem with the changes I told you. I copy the code below.

However, I suppose that the 'text' field in the LuaCallParms structure in messages is always a (null terminated) string. Since the message system is only used for watch_for_file_changes in my application, it seems it works. However, I don't know if it's true for all the uses of your module.


Alexandre



static LRESULT CALLBACK WndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
  WNDPROC lpPrevWndProc;
  if (uMsg == MY_INTERNAL_LUA_MESSAGE) {
    BOOL res;
    LuaCallParms *P  = (LuaCallParms*)lParam;
    res = call_lua_direct(P->L,P->ref,P->idx,P->text,P->discard);
    if(P->text)
        free(P->text);
    free(P);
    return res;
  }

  lpPrevWndProc = (WNDPROC)GetWindowLongPtr(hwnd, GWLP_USERDATA);
  if (lpPrevWndProc)
    return CallWindowProc(lpPrevWndProc, hwnd, uMsg, wParam, lParam);

  return DefWindowProc(hwnd, uMsg, wParam, lParam);
}


BOOL call_lua(lua_State *L, Ref ref, int idx, const char *text, int discard) {
  BOOL res;
  if (s_use_mutex) {
    lock_mutex();
    res = call_lua_direct(L,ref,idx,text,discard);
    release_mutex();
  } else {
    LuaCallParms *parms = (LuaCallParms*)malloc(sizeof(LuaCallParms));
    parms->L = L;
    parms->ref = ref;
    parms->idx = idx;
    if(text) {
      size_t text_len = strlen(text);
      char *mtext = (char *)malloc(text_len+1);
      memcpy(mtext, text, text_len+1);
      parms->text = mtext;
    } else
      parms->text = text;
    parms->discard = discard;
    PostMessage(hMessageWin,MY_INTERNAL_LUA_MESSAGE,0,(LPARAM)parms);
    res = FALSE; // for now
  }

  return res;
}


---------------------------------------------------------------------
Alexandre Rion
Fuel and Fire Department (MEYGU)
EADS / Airbus Military
---------------------------------------------------------------------

> Date: Wed, 27 Jun 2012 09:49:01 +0200
> From: steve.j.donovan@gmail.com
> To: lua-l@lists.lua.org
> Subject: Re: [ANN] winapi 1.4
>
> On Wed, Jun 27, 2012 at 9:41 AM, Alexandre Rion <gaumerie@hotmail.com> wrote:
> > I think it should work, and it will be my fix for now. But I'm sure a more
> > elegant solution (and using less memory allocations) can be found, so I
> > watch for your feedback.
>
> Thanks, Alexandre - this is very useful feedback. Any patches welcome
> - I usually use the library in console mode and haven't stress tested
> the file watcher.
>
> Life in C is all about watching memory ;)
>
> steve d.
>