Another round of WinAPI binding and call to action

  • This message is for anyone interested in developing GUI apps for
    Windows using LuaJIT and for anyone who might want to get involved
    with developing a binding of the Windows API, especially UI-related
    stuff (but other parts too).

    Some 3 years ago (some time after the ffi got support for callbacks) I
    started working on a binding[1] of the Windows API which includes
    top-level windows, a some standard controls, an OpenGL widget and a
    cairo widget. I sat on it for 2-3 months and then I made it public.
    But the docs were thin.

    I started working on it again this week and this is the result:

    • the class system and most of the class hierarchy is now documented
    • there's developer documentation for how to bind more APIs
    • there's an all-in-one demo (screenshot[2], code[3])
    • bugs were crushed
    • it almost works with a 64bit build of luajit except for one big bad bug[4]
    • the list of modules is auto-generated so it always shows what's
      actually available.
    • the whole thing is at 19KLOC but it's very modular (the classes are 5KLOC)

    There's a lot more work to be done (coding and docs) to get to the
    state of any-noob-can-use-it. Currently it's closer to the typical
    Linux experience: it sometimes blows in your face and you have to go
    to the guts and fix it -- but it's not a 50MB pile of C++ guts ;) The
    good news is that when it works it's very easy to use because it's
    100% OOified and Luaized (see[3]).

    Now for the call to action part: if you are interested in this stuff,
    this is one project where it will be easy for you to collaborate on.
    There's a list of open issues, a status page, developer docs, a forum
    and you'll get my full assistance. Sure, you'll have to learn your way
    around a low-level API. OTOH there's helpers to sweep it all under the
    rug to the point where making new widget classes can be almost
    entirely declarative[5]. So if you want to help, PM me or post on
    github or on the luapower forum.

    Thank you.

    (this message was also posted on the LuaJIT mailing list)


  • 4
    Log in to reply

  • Hi Cosmin,

    First, thank you for the recent work you've done updating and documenting winapi.
    The new demo and docs make it a breeze to use.

    Second, I have done some work on finding out why the 64bit version of luajit doesn't work with winapi. I found that using version 2.0.4 of luajit raised some error messages which allowed me to do some detective work and I came up with the following changes in window.lua:-

    line 484 was:
    function GetWindowExStyle(hwnd) return GetWindowLong(hwnd, GWL_EXSTYLE) end
    I changed it to:
    function GetWindowExStyle(hwnd) return tonumber(GetWindowLong(hwnd, GWL_EXSTYLE)) end

    line 1214 was:
    local SC =, 0xfff0)
    I changed it to:
    local SC =, 0xfff0)

    The error messages were complaining about functions expecting a number, but got cdata.
    These changes got rid of the error messages, but did not completely fix the problem.
    However I think it's closer to working now. Maybe these changes will give you a clue as to what else is wrong :)

  • Thanks for finding these. I fixed them in git (do a mgit winapi pull to update).

    The bug I was talking about is different I think. On my machine, running say listboxclass.lua (or any other comctl 6 control) crashes immediately with exit code: -1073741819 (some random number) so it's clearly an access violation which seems to be caused by SendMessage (more context here I haven't managed to figure it out. Thanks for looking into it, a pair of fresh eyes is what it needs.

  • Update: the bug was fixed.

Log in to reply

Internal error.

Oops! Looks like something went wrong!