tags:

views:

251

answers:

0

I am having trouble getting embedded wxLua to work with my application -- it works fine when I use the wxLua DLLs, but I'm trying to use the static libraries so I can distribute a single, standalone executable with no external dependencies.

First, the symptoms: Most controls (such as wxButtons, wxGauges, wxTextCtrls) do not display; at the very least, wxStaticTexts display, and I can successfully use menus to show an about menu and to quit.

Here's a simple test script:

require("wx")
frame = wx.wxFrame(wx.NULL, wx.wxID_ANY, "Frame")
panel = wx.wxPanel(frame, wx.wxID_ANY)
hbox = wx.wxBoxSizer(wx.wxHORIZONTAL)
hbox:Add(wx.wxButton(panel, wx.wxID_ANY, "I'm a button"))
hbox:Add(wx.wxStaticText(panel, wx.wxID_ANY, "Hello"))
panel:SetSizerAndFit(hbox)
frame:Show(true)
wx.wxGetApp():MainLoop()

The top window in this screen shot shows a raw lua file.lua that calls the wx library, and the bottom one shows the result when run from my embedded wxLua: alt text

As you can see, the widgets that do show up get placed correctly, but the widgets that don't show up, neither get rendered nor process events.

Here's the offending (minimalized) C++:

extern "C" {
#include "lua.h"
#include "lualib.h"
#include "lauxlib.h"
}
#include "wx/app.h"
#include "wx/image.h"

// disable some of the libraries we didn't want
#define wxLUA_USEBINDING_WXHTML 0
#define wxLUA_USEBINDING_WXNET 0
#define wxLUA_USEBINDING_WXLUASOCKET 0
#define wxLUA_USEBINDING_WXSTC 0
#include "wxbind/include/wxbinddefs.h"
#include "wx/msgdlg.h"

WXLUA_DECLARE_BIND_ALL;

class MyApp : public wxApp
{
    public:
     virtual bool OnInit();
     virtual int OnExit();
     void OnLua(wxLuaEvent &e);
     wxLuaState m_wxlState;
    private:
     DECLARE_EVENT_TABLE();
};

IMPLEMENT_APP(MyApp)

BEGIN_EVENT_TABLE(MyApp, wxApp)
EVT_LUA_ERROR    (wxID_ANY, MyApp::OnLua)
END_EVENT_TABLE()

bool MyApp::OnInit()
{
    WXLUA_IMPLEMENT_BIND_ALL

    wxInitAllImageHandlers();
    wxLuaState::sm_wxAppMainLoop_will_run = true;
    m_wxlState = m_wxlState.Create(this);
    lua_State *L = m_wxlState.GetLuaState();

    luaL_openlibs(L);
    int res = luaL_dofile(L, "C:\\file.lua");
    if (res != 0)
    {
     wxMessageBox(wxString::FromAscii(lua_tostring(L, -1)), wxT("Error running script"));
     return false;
    }

    return true;
}

int MyApp::OnExit()
{
    wxMessageBox(wxT("Goodbye!"));
    m_wxlState.CloseLuaState(true);
    m_wxlState.Destroy();
    return wxApp::OnExit();
}

void MyApp::OnLua(wxLuaEvent &e)
{
    wxMessageBox(e.GetString(), wxT("wxLua"));
}

I have stripped down both wxWidgets and wxLua using their setup.h and wxluasetup.h files; I can succcessfully render buttons if I use wxWidgets in pure C++, so I think the issue is with either how I compiled wxLua, or how I'm configuring the wxLuaState.

I think I've configured the wxLuaState correctly, but I haven't been able to find an example where all of the work is done in a luaL_dofile -- all the other examples have custom wx-derived classes, except for wxlua.cpp, which is a little different since it's for the wx.dll that Lua uses. I've spent the last few hours trying to figure out what I'm doing wrong, and I'm completely out of ideas at this point.


Update 1: If I create a button from C++ (such as wxButton *btn = new wxButton(panel, 3456, wxT("I'm a button")); and I have a corresponding hbox:Add(wx.wxWindow.FindWindowById(3456)) in Lua, the button shows up fine. I'd really rather not have to create all my widgets in C++, but it seems like a viable temporary workaround.

Update 2: On the wxLua-users list, it has been suggested that something is wrong with my wxWidgets build. I've looked through wxWidgets' setup.h a couple times, and I can't find anything where I've obviously made a poor choice. I'm using VS2008 express with the included workspace, on a Unicode release build. I'll try and see whether there are any known issues with that compilation environment, but I'm not holding my breath on it.


I just subscribed to the wxLua mailing list, but I haven't received a confirmation yet, so I figured I'd try here first. Has anyone seen this issue before, or can anyone confirm or deny that I'm setting up the wxLuaState correctly?