From: John L. <jr...@us...> - 2008-12-05 05:57:27
|
Update of /cvsroot/wxlua/wxLua/apps/wxlua/src In directory 23jxhf1.ch3.sourceforge.com:/tmp/cvs-serv8178/wxLua/apps/wxlua/src Modified Files: Makefile editor.h lconsole.cpp lconsole.h wxlua.cpp wxlua.h Log Message: Make the wxLuaConsole not rely on the wxApp having a pointer to it so it can be used easier. Index: editor.h =================================================================== RCS file: /cvsroot/wxlua/wxLua/apps/wxlua/src/editor.h,v retrieving revision 1.42 retrieving revision 1.43 diff -C2 -d -r1.42 -r1.43 *** editor.h 1 Apr 2008 05:10:04 -0000 1.42 --- editor.h 5 Dec 2008 05:57:20 -0000 1.43 *************** *** 7,15 **** /* Original filename: '../../../samples/editor.wx.lua' */ ! extern const size_t wxLuaEditor_len; ! extern const unsigned char wxLuaEditor[]; ! const size_t wxLuaEditor_len = 91181; ! const unsigned char wxLuaEditor[91182] = { 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 61, 45, 45, 45, 10, 45, 45, 32, 78, 97,109,101, 58, 32, 32, 32, 32, 32, 32, 32, 32, 69,100,105,116,111,114, 46,119,120, 46,108,117, 97, 10, --- 7,15 ---- /* Original filename: '../../../samples/editor.wx.lua' */ ! extern const size_t editor_wx_lua_len; ! extern const unsigned char editor_wx_lua[]; ! const size_t editor_wx_lua_len = 91181; ! const unsigned char editor_wx_lua[91182] = { 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 61, 45, 45, 45, 10, 45, 45, 32, 78, 97,109,101, 58, 32, 32, 32, 32, 32, 32, 32, 32, 69,100,105,116,111,114, 46,119,120, 46,108,117, 97, 10, Index: lconsole.h =================================================================== RCS file: /cvsroot/wxlua/wxLua/apps/wxlua/src/lconsole.h,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** lconsole.h 12 Dec 2006 01:23:40 -0000 1.10 --- lconsole.h 5 Dec 2008 05:57:21 -0000 1.11 *************** *** 17,20 **** --- 17,22 ---- class WXDLLEXPORT wxListBox; + class wxLuaConsoleWrapper; + // ---------------------------------------------------------------------------- // wxLuaConsole - define a console class to display print statements *************** *** 24,28 **** { public: ! wxLuaConsole(wxWindow* parent, wxWindowID id, const wxString& title = wxT("wxLua console"), const wxPoint& pos = wxDefaultPosition, --- 26,31 ---- { public: ! wxLuaConsole(wxLuaConsoleWrapper* consoleWrapper, ! wxWindow* parent, wxWindowID id, const wxString& title = wxT("wxLua console"), const wxPoint& pos = wxDefaultPosition, *************** *** 39,42 **** --- 42,47 ---- void SetExitOnError(bool is_error) { m_exit_on_error = m_exit_on_error || is_error; } + wxLuaConsoleWrapper* m_wrapper; + protected: void OnCloseWindow(wxCloseEvent& event); *************** *** 51,53 **** --- 56,83 ---- }; + // ---------------------------------------------------------------------------- + // wxLuaConsoleWrapper - A smart pointer like wrapper for the wxLuaConsole + // + // Create one as a member of the wxApp or whereever it will exist longer than + // the wxLuaConsole it wraps and the wxLuaConsole will NULL the pointer to + // it when closed. See wxLuaConsole::OnCloseWindow(wxCloseEvent&) as to why + // we simply can't catch the close event elsewhere. + // ---------------------------------------------------------------------------- + + class wxLuaConsoleWrapper + { + public: + + wxLuaConsoleWrapper(wxLuaConsole* c = NULL) : m_luaConsole(c) {} + + bool Ok() const { return m_luaConsole != NULL; } + + wxLuaConsole* GetConsole(); // this will assert if console is NULL, check with Ok() + void SetConsole(wxLuaConsole* c) { m_luaConsole = c; } + + protected: + wxLuaConsole* m_luaConsole; + }; + + #endif // WX_LUA_CONSOLE_H Index: Makefile =================================================================== RCS file: /cvsroot/wxlua/wxLua/apps/wxlua/src/Makefile,v retrieving revision 1.24 retrieving revision 1.25 diff -C2 -d -r1.24 -r1.25 *** Makefile 16 Jul 2007 19:34:12 -0000 1.24 --- Makefile 5 Dec 2008 05:57:20 -0000 1.25 *************** *** 39,43 **** editor: ! $(LUA) $(WXLUA_DIR)/util/bin2c/bin2c.lua -t -lf -n wxLuaEditor -o editor.h $(WXLUA_DIR)/samples/editor.wx.lua clean: --- 39,43 ---- editor: ! $(LUA) $(WXLUA_DIR)/util/bin2c/bin2c.lua -t -lf -n editor_wx_lua -o editor.h $(WXLUA_DIR)/samples/editor.wx.lua clean: Index: wxlua.cpp =================================================================== RCS file: /cvsroot/wxlua/wxLua/apps/wxlua/src/wxlua.cpp,v retrieving revision 1.53 retrieving revision 1.54 diff -C2 -d -r1.53 -r1.54 *** wxlua.cpp 3 Dec 2008 05:26:03 -0000 1.53 --- wxlua.cpp 5 Dec 2008 05:57:21 -0000 1.54 *************** *** 113,121 **** bool wxLuaStandaloneApp::OnInit() { ! m_programName = argv[0]; // The name of this program ! m_luaConsole = NULL; ! m_want_console = false; ! m_wxlDebugTarget = NULL; ! m_mem_bitmap_added = false; int arg_count = 0; // counter for args used during parsing --- 113,120 ---- bool wxLuaStandaloneApp::OnInit() { ! m_programName = argv[0]; // The name of this program ! m_want_console = false; ! m_wxlDebugTarget = NULL; ! m_mem_bitmap_added = false; int arg_count = 0; // counter for args used during parsing *************** *** 150,154 **** // When this function returns wxApp:MainLoop() will be called by wxWidgets ! // and so we want the Lua code wx.wxGetApp:MailLoop() to not // prematurely start it. wxLuaState::sm_wxAppMainLoop_will_run = true; --- 149,153 ---- // When this function returns wxApp:MainLoop() will be called by wxWidgets ! // and so we want the Lua code wx.wxGetApp:MainLoop() to not // prematurely start it. wxLuaState::sm_wxAppMainLoop_will_run = true; *************** *** 186,193 **** arg_count++; // remove -c arg m_want_console = true; ! // Note: The m_luaConsole will be nulled when it closes in // wxLuaConsole::OnCloseWindow. ! m_luaConsole = new wxLuaConsole(NULL, ID_WXLUA_CONSOLE); ! m_luaConsole->Show(true); } --- 185,192 ---- arg_count++; // remove -c arg m_want_console = true; ! // Note: The wxLuaConsoleWrapper::m_luaConsole will be nulled when it closes in // wxLuaConsole::OnCloseWindow. ! m_luaConsoleWrapper.SetConsole(new wxLuaConsole(&m_luaConsoleWrapper, NULL, ID_WXLUA_CONSOLE)); ! m_luaConsoleWrapper.GetConsole()->Show(true); } *************** *** 238,242 **** } ! return (m_luaConsole != NULL); // will exit app when console is closed } --- 237,241 ---- } ! return (m_luaConsoleWrapper.Ok()); // will exit app when console is closed } *************** *** 257,261 **** wxlua_pushargs(m_wxlState.GetLuaState(), argv, argc, arg_count); ! int rc = m_wxlState.RunBuffer((const char*)wxLuaEditor, wxLuaEditor_len, m_programName); run_ok = (rc == 0); if (rc != 0) --- 256,260 ---- wxlua_pushargs(m_wxlState.GetLuaState(), argv, argc, arg_count); ! int rc = m_wxlState.RunBuffer((const char*)editor_wx_lua, editor_wx_lua_len, m_programName); run_ok = (rc == 0); if (rc != 0) *************** *** 308,312 **** } ! return (m_luaConsole != NULL) || run_ok; } --- 307,311 ---- } ! return m_luaConsoleWrapper.Ok() || run_ok; } *************** *** 326,333 **** m_want_console = false; // no more messages ! if (m_luaConsole && !m_luaConsole->IsBeingDeleted()) { ! m_luaConsole->Destroy(); ! m_luaConsole = NULL; } --- 325,332 ---- m_want_console = false; // no more messages ! if (m_luaConsoleWrapper.Ok() && !m_luaConsoleWrapper.GetConsole()->IsBeingDeleted()) { ! m_luaConsoleWrapper.GetConsole()->Destroy(); ! m_luaConsoleWrapper.SetConsole(NULL); } *************** *** 351,364 **** // If they closed the console, but specified they wanted it // on the command-line, recreate it. ! if (m_want_console && (m_luaConsole == NULL)) { ! m_luaConsole = new wxLuaConsole(NULL, ID_WXLUA_CONSOLE); ! m_luaConsole->Show(true); } if (!is_error) { ! if (m_luaConsole != NULL) ! m_luaConsole->DisplayText(msg); else { --- 350,363 ---- // If they closed the console, but specified they wanted it // on the command-line, recreate it. ! if (m_want_console && (!m_luaConsoleWrapper.Ok())) { ! m_luaConsoleWrapper.SetConsole(new wxLuaConsole(&m_luaConsoleWrapper, NULL, ID_WXLUA_CONSOLE)); ! m_luaConsoleWrapper.GetConsole()->Show(true); } if (!is_error) { ! if (m_luaConsoleWrapper.Ok()) ! m_luaConsoleWrapper.GetConsole()->DisplayText(msg); else { *************** *** 375,384 **** if (m_wxlDebugTarget != NULL) m_wxlDebugTarget->DisplayError(msg); ! else if (m_luaConsole != NULL) { ! m_luaConsole->DisplayText(msg); ! m_luaConsole->SetExitOnError(is_error); if (wxlState.Ok()) ! m_luaConsole->DisplayStack(wxlState); } else --- 374,383 ---- if (m_wxlDebugTarget != NULL) m_wxlDebugTarget->DisplayError(msg); ! else if (m_luaConsoleWrapper.Ok()) { ! m_luaConsoleWrapper.GetConsole()->DisplayText(msg); ! m_luaConsoleWrapper.GetConsole()->SetExitOnError(is_error); if (wxlState.Ok()) ! m_luaConsoleWrapper.GetConsole()->DisplayStack(wxlState); } else Index: wxlua.h =================================================================== RCS file: /cvsroot/wxlua/wxLua/apps/wxlua/src/wxlua.h,v retrieving revision 1.24 retrieving revision 1.25 diff -C2 -d -r1.24 -r1.25 *** wxlua.h 15 Jan 2008 01:04:04 -0000 1.24 --- wxlua.h 5 Dec 2008 05:57:21 -0000 1.25 *************** *** 35,44 **** void OnLua(wxLuaEvent &event); ! wxString m_programName; ! wxLuaState m_wxlState; ! wxLuaConsole *m_luaConsole; ! bool m_want_console; ! bool m_mem_bitmap_added; ! wxLuaDebugTarget *m_wxlDebugTarget; private: --- 35,44 ---- void OnLua(wxLuaEvent &event); ! wxString m_programName; ! wxLuaState m_wxlState; ! wxLuaConsoleWrapper m_luaConsoleWrapper; ! bool m_want_console; ! bool m_mem_bitmap_added; ! wxLuaDebugTarget* m_wxlDebugTarget; private: Index: lconsole.cpp =================================================================== RCS file: /cvsroot/wxlua/wxLua/apps/wxlua/src/lconsole.cpp,v retrieving revision 1.18 retrieving revision 1.19 diff -C2 -d -r1.18 -r1.19 *** lconsole.cpp 20 Jul 2007 01:39:05 -0000 1.18 --- lconsole.cpp 5 Dec 2008 05:57:21 -0000 1.19 *************** *** 28,36 **** #include "lconsole.h" - // Only include this for the wxlua app, wxluaedit includes this whole file. - #ifndef WXLUAEDITOR_APP - #include "wxlua.h" - #endif //WXLUAEDITOR_APP - // ---------------------------------------------------------------------------- // wxLuaConsole --- 28,31 ---- *************** *** 41,48 **** END_EVENT_TABLE() ! wxLuaConsole::wxLuaConsole(wxWindow* parent, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, long style, const wxString& name) ! :wxFrame(parent, id, title, pos, size, style, name), m_exit_on_error(false) { SetIcon(wxICON(LUA)); --- 36,45 ---- END_EVENT_TABLE() ! wxLuaConsole::wxLuaConsole(wxLuaConsoleWrapper* consoleWrapper, ! wxWindow* parent, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, long style, const wxString& name) ! :wxFrame(parent, id, title, pos, size, style, name), ! m_wrapper(consoleWrapper), m_exit_on_error(false) { SetIcon(wxICON(LUA)); *************** *** 65,73 **** void wxLuaConsole::OnCloseWindow(wxCloseEvent&) { ! // Must NULL the console in the app so it won't be used. // Using EVT_DESTROY in the app causes a segfault if this is deleted ! // in wxApp::OnExit and through this is ugly, it works. ! if (wxGetApp().m_luaConsole == this) ! wxGetApp().m_luaConsole = NULL; Destroy(); --- 62,70 ---- void wxLuaConsole::OnCloseWindow(wxCloseEvent&) { ! // Must NULL the console so nobody will try to still use it. // Using EVT_DESTROY in the app causes a segfault if this is deleted ! // in wxApp::OnExit() and though this is ugly, it works. ! if (m_wrapper) ! m_wrapper->SetConsole(NULL); Destroy(); *************** *** 130,131 **** --- 127,140 ---- } } + + // --------------------------------------------------------------------------- + // wxLuaConsoleWrapper + // --------------------------------------------------------------------------- + + wxLuaConsole* wxLuaConsoleWrapper::GetConsole() + { + wxCHECK_MSG(m_luaConsole != NULL, NULL, wxT("Member wxLuaConsole is NULL!")); + return m_luaConsole; + } + + |