lua-users home
lua-l archive

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


John Labenski wrote:

...
What solutions have others come up with to deal with this? Has anyone
successfully packaged wxLua to work with the 5.1 packaging system?


Sorry, I haven't, but it's definitely on the TODO list.

Can you point to (in your repository) what you had to do to get it to
work (in 5.0 for now) so we can duplicate it?

I am working in 5.1, so I don't have a 5.0 solution. And, while I can use require to load my module, it is not really wxLua. I wrap it in my own C++ wrapper so I can do the thread spawning and such. The result does not support the wxLua mechanism for creating dialogs, you do something more like this:

    require "WxGUI"
    local GUI = WxGUI {
        url = "mygui.xrc"
        widgets = {
            WxGUI.Widget {
                name = "ID_BUTTON"
                action = function(self)
                    print("You pressed ", self:getWidget():GetLabel())
                end
            }
        }
    }

This will load the .xrc file, bring up the dialog and then wait for button presses. The dialog's event loop runs in a separate thread, where the wxApp object was constructed. As I mentioned, this still runs the Lua code in the main thread because I added a callback mechanism to wxLua. When you create a WxGUI.Widget object, it creates the widget (a wxButton in this case) and then attaches a native C++ callback to it. When the event fires, this callback sends a message to the main thread, which processes it and calls the Lua function to print the button.

You don't use all the LoadDialog mechanism of wxLua at all. But it does use all the other facilities of wxLua. For instance, calling Widget:getWidget() returns the wxLua wrapper around the wxButton, allowing you to call all of its methods, like the GetLabel() method I call above.

All of this is tied into Emma's object model. In this case it's just used to wrap Lua interfaces around the C++ classes of WxGUI and Widget. But Emma also provides an implicit event loop, which is why yoy don't see any call to a wxApp.run() sort of call above. That is the one piece that makes this not ready for prime-time. As soon as I fix that, you will add a:

    WxGUI:run()

call to the end of the program and it will run from a stock Lua interpreter.

So, is this part of wxLua, or something different? All this code can be seen at:

    http://emma3d.org/svn/emma

It is all Open Source, so I would be happy to make it part of wxLua. Or maybe we can just add my callback mechanism and a couple of bug fixes and then I could use wxLua from sourceforge and build my WxGUI package on top of it.

Let me know if there is any interest and I can send patches for my changes to wxLua. the callback mechanism is a very minor change. I basically added a class:

    class wxLuaNativeCallback {
    public:
        virtual void execute(wxEvent* event)=0;
    };

and a new variant of ConnectEvent() which sets up the callback to be called. You simply subclass wxLuaNativeCallback, implement execute() and then call ConnectEvent. All the existing functionality is left intact. This just gives a new way to use it.

--
chris marrin              ,""$, "As a general rule,don't solve puzzles
chris@marrin.com        b`    $  that open portals to Hell" ,,.
        ,.`           ,b`    ,`                            , 1$'
     ,|`             mP    ,`                              :$$'     ,mm
   ,b"              b"   ,`            ,mm      m$$    ,m         ,`P$$
  m$`             ,b`  .` ,mm        ,'|$P   ,|"1$`  ,b$P       ,`  :$1
 b$`             ,$: :,`` |$$      ,`   $$` ,|` ,$$,,`"$$     .`    :$|
b$|            _m$`,:`    :$1   ,`     ,$Pm|`    `    :$$,..;"'     |$:
P$b,      _;b$$b$1"       |$$ ,`      ,$$"             ``'          $$
 ```"```'"    `"`         `""`        ""`                          ,P`