From: John L. <jr...@us...> - 2006-09-07 04:20:57
|
Update of /cvsroot/wxlua/wxLua/apps/wxluaedit/src In directory sc8-pr-cvs9.sourceforge.net:/tmp/cvs-serv22903/wxLua/apps/wxluaedit/src Modified Files: wxluaedit.cpp Log Message: cleanup and formatting in the wxlua editor.wx.lua move SetStackDialog to the wxLuaHandler so it can be used by other programs more easily start work on using the socket code in the wxluaeditor formatting in wxldserv.cpp Index: wxluaedit.cpp =================================================================== RCS file: /cvsroot/wxlua/wxLua/apps/wxluaedit/src/wxluaedit.cpp,v retrieving revision 1.21 retrieving revision 1.22 diff -C2 -d -r1.21 -r1.22 *** wxluaedit.cpp 28 Aug 2006 05:26:19 -0000 1.21 --- wxluaedit.cpp 7 Sep 2006 04:20:54 -0000 1.22 *************** *** 27,35 **** #include "wxledit.h" // Declare the binding initialization functions as extern so we don't have to // #include the binding header for simplicity. extern bool wxLuaBinding_wx_init(); extern bool wxLuaBinding_wxstc_init(); ! //extern bool wxLuaBinding_wxluasocket_init(); // ---------------------------------------------------------------------------- --- 27,44 ---- #include "wxledit.h" + #include "wxluasocket/include/wxldserv.h" + #include "wxluasocket/include/wxldtarg.h" + #include "wxluasocket/include/wxlhandl.h" + #include "wxluadebug/include/staktree.h" + // Declare the binding initialization functions as extern so we don't have to // #include the binding header for simplicity. extern bool wxLuaBinding_wx_init(); extern bool wxLuaBinding_wxstc_init(); ! extern bool wxLuaBinding_wxluasocket_init(); ! ! class LuaHandler; ! ! wxWindowID ID_WXLUASTATE_DEBUG = 200; // ---------------------------------------------------------------------------- *************** *** 44,47 **** --- 53,62 ---- wxCMD_LINE_VAL_NONE, wxCMD_LINE_OPTION_HELP }, + { wxCMD_LINE_OPTION, wxT("d"), wxT("debuggee"), wxT("run as debuggee, internal use"), + wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL }, + + // { wxCMD_LINE_OPTION, wxT("r"), wxT("run"), wxT("run wxLua program w/ command line args"), + // wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL|wxCMD_LINE_NEEDS_SEPARATOR }, + // filenames to open in the editor { wxCMD_LINE_PARAM, wxEmptyString, wxEmptyString, *************** *** 67,70 **** --- 82,117 ---- virtual bool OnInit(); + virtual int OnExit(); + + void OnLua(wxLuaEvent &event); + void OnDebugStackEnum(wxLuaDebugEvent &event); + void OnDebugTableEnum(wxLuaDebugEvent &event); + void OnDebugStackEntryEnum(wxLuaDebugEvent &event); + + void DisplayError(const wxString &strError) const; + + LuaHandler *m_luaHandler; + wxLuaDebugTarget *m_pDebugTarget; + wxLuaState m_wxlState; + wxString m_programName; + + private: + DECLARE_EVENT_TABLE(); + }; + + // --------------------------------------------------------------------------- + // LuaHandler - routes commands from the wxLuaHandler to the app + // --------------------------------------------------------------------------- + + class LuaHandler : public wxLuaHandler + { + public: + LuaHandler(wxLuaEditorApp *app) : m_app(app) {} + + virtual void AddPendingEvent(wxEvent& event) { m_app->AddPendingEvent(event); } + virtual bool ProcessEvent(wxEvent& event) { return m_app->ProcessEvent(event); } + virtual void DisplayError(const wxString &strError) const { m_app->DisplayError(strError); } + + wxLuaEditorApp *m_app; }; *************** *** 103,108 **** --- 150,178 ---- IMPLEMENT_APP(wxLuaEditorApp) + BEGIN_EVENT_TABLE(wxLuaEditorApp, wxApp) + EVT_LUA_PRINT (ID_WXLUASTATE_DEBUG, wxLuaEditorApp::OnLua) + EVT_LUA_ERROR (ID_WXLUASTATE_DEBUG, wxLuaEditorApp::OnLua) + EVT_LUA_DEBUG_HOOK (ID_WXLUASTATE_DEBUG, wxLuaEditorApp::OnLua) + + EVT_WXLUA_DEBUG_STACK_ENUM( wxLuaEditorApp::OnDebugStackEnum) + EVT_WXLUA_DEBUG_STACK_ENTRY_ENUM(wxLuaEditorApp::OnDebugStackEntryEnum) + EVT_WXLUA_DEBUG_TABLE_ENUM( wxLuaEditorApp::OnDebugTableEnum) + END_EVENT_TABLE() + bool wxLuaEditorApp::OnInit() { + m_luaHandler = new LuaHandler(this); + m_pDebugTarget = NULL; + m_programName = argv[0]; + + #if defined(__WXMSW__) && wxCHECK_VERSION(2, 3, 3) + WSADATA wsaData; + WORD wVersionRequested = MAKEWORD(1, 1); + WSAStartup(wVersionRequested, &wsaData); + #endif // defined(__WXMSW__) && wxCHECK_VERSION(2, 3, 3) + + wxLuaDebugServer::SetProgramName(argv[0]); + wxLuaDebugServer::SetNetworkName(wxGetHostName()); + wxInitAllImageHandlers(); *************** *** 122,132 **** wxLuaBinding_wx_init(); wxLuaBinding_wxstc_init(); ! //wxLuaBinding_wxluasocket_init(); ! // parse command line wxCmdLineParser parser(g_cmdLineDesc, argc, argv); ! if (parser.Parse() != 0) ! return 0; // help was shown / an error occurred // These are the options for the frame --- 192,239 ---- wxLuaBinding_wx_init(); wxLuaBinding_wxstc_init(); ! wxLuaBinding_wxluasocket_init(); // parse command line wxCmdLineParser parser(g_cmdLineDesc, argc, argv); ! ! switch ( parser.Parse() ) ! { ! case -1 : ! { ! // help should be given by the wxCmdLineParser, exit program ! return false; ! } ! case 0: ! { ! wxString value; ! if (parser.Found(wxT("d"), &value)) ! { ! // wxLuaDebugServer::StartClient() runs wxExecute(m_programName -d[host]:[port], ...) ! ! m_wxlState = wxLuaState(this, ID_WXLUASTATE_DEBUG); ! if (!m_wxlState.Ok()) ! return false; ! ! // Set up for debugging ! wxString serverName(value.BeforeFirst(wxT(':'))); ! ! long portNumber = 0; ! if (value.AfterFirst(wxT(':')).ToLong(&portNumber)) ! { ! m_pDebugTarget = new wxLuaDebugTarget(m_wxlState, serverName, (int)portNumber); ! if (m_pDebugTarget != NULL) ! return m_pDebugTarget->Run(); ! } ! return false; ! } ! ! break; ! } ! default: ! { ! wxLogMessage(wxT("Unknown command line option, aborting.")); ! return false; ! } ! } // These are the options for the frame *************** *** 220,223 **** --- 327,419 ---- } + int wxLuaEditorApp::OnExit() + { + // If acting as a debuggee, we're done - disconnect from the debugger. + if (m_pDebugTarget != NULL) + { + m_pDebugTarget->Stop(); + delete m_pDebugTarget; + m_pDebugTarget = NULL; + } + + if (m_wxlState.Ok()) + { + m_wxlState.CloseLuaState(true); + m_wxlState.Destroy(); + delete m_luaHandler; + } + + wxSafeYield(); // make sure windows get destroyed + + wxApp::OnExit(); + + #if defined(__WXMSW__) && wxCHECK_VERSION(2, 3, 3) + WSACleanup(); + #endif // defined(__WXMSW__) && wxCHECK_VERSION(2, 3, 3) + + return 0; + } + + void wxLuaEditorApp::OnLua( wxLuaEvent &event ) + { + if (event.GetEventType() == wxEVT_LUA_PRINT) + { + //if (m_pConsole != NULL) + // m_pConsole->DisplayText(event.GetString()); + //else + #ifdef __WXMSW__ + wxMessageBox(event.GetString(), wxT("wxLua")); + #else + fprintf(stderr, wx2lua(event.GetString() + wxT("\n"))); + #endif // __WXMSW__ + } + else if (event.GetEventType() == wxEVT_LUA_ERROR) + { + DisplayError(event.GetString()); + } + } + + void wxLuaEditorApp::OnDebugStackEnum(wxLuaDebugEvent &event) + { + if (wxLuaHandler::GetHandler().GetStackDialog() != NULL) + wxLuaHandler::GetHandler().GetStackDialog()->FillStackCombobox(event.GetDebugData()); + else + event.Skip(); + } + + void wxLuaEditorApp::OnDebugStackEntryEnum(wxLuaDebugEvent &event) + { + if (wxLuaHandler::GetHandler().GetStackDialog() != NULL) + wxLuaHandler::GetHandler().GetStackDialog()->FillStackEntry(event.GetReference(), event.GetDebugData()); + else + event.Skip(); + } + + void wxLuaEditorApp::OnDebugTableEnum(wxLuaDebugEvent &event) + { + if (wxLuaHandler::GetHandler().GetStackDialog() != NULL) + wxLuaHandler::GetHandler().GetStackDialog()->FillTableEntry(wxTreeItemId((wxTreeItemIdValue)event.GetReference()), event.GetDebugData()); + else + event.Skip(); + } + + void wxLuaEditorApp::DisplayError(const wxString &errorStr) const + { + if (m_pDebugTarget != NULL) + m_pDebugTarget->DisplayError(errorStr); + else + { + //if (m_pConsole != NULL) + // m_pConsole->DisplayText(errorStr, true); + //else + #ifdef __WXMSW__ + wxMessageBox(errorStr, wxT("wxLua")); + #else + fprintf(stderr, wx2lua(errorStr + wxT("\n"))); + #endif // __WXMSW__ + + } + } + // ---------------------------------------------------------------------------- // wxLuaEditorFrame |