From: John L. <jr...@us...> - 2008-12-05 21:15:17
|
Update of /cvsroot/wxlua/wxLua/apps/wxlua/src In directory 23jxhf1.ch3.sourceforge.com:/tmp/cvs-serv1652/wxLua/apps/wxlua/src Modified Files: lconsole.h wxlua.cpp wxlua.h Log Message: Allow convertion of wxStrings to const char in wxlua_getstringtype() Make wxLua app allow for printing to stdout, msgdlg, and/or console as cmd line option Check for and don't crash if someone replaces tostring() with garbage Index: wxlua.cpp =================================================================== RCS file: /cvsroot/wxlua/wxLua/apps/wxlua/src/wxlua.cpp,v retrieving revision 1.54 retrieving revision 1.55 diff -C2 -d -r1.54 -r1.55 *** wxlua.cpp 5 Dec 2008 05:57:21 -0000 1.54 --- wxlua.cpp 5 Dec 2008 21:15:10 -0000 1.55 *************** *** 61,74 **** wxCMD_LINE_VAL_NONE, wxCMD_LINE_PARAM_OPTIONAL|wxCMD_LINE_OPTION_HELP }, ! { wxCMD_LINE_SWITCH, wxT("c"), wxT("console"), wxT("Show message console for print statements."), wxCMD_LINE_VAL_NONE, wxCMD_LINE_PARAM_OPTIONAL }, ! { wxCMD_LINE_SWITCH, wxT("q"), wxT("quit"), wxT("Do not exit even if there are no top level windows open."), wxCMD_LINE_VAL_NONE, wxCMD_LINE_PARAM_OPTIONAL }, ! { wxCMD_LINE_OPTION, wxT("e"), wxT("stat"), wxT("Execute lua string 'stat'."), wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL }, ! { wxCMD_LINE_OPTION, wxT("d"), wxT("debuggee"), wxT("Run as debuggee -d[host]:[port]"), wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL }, --- 61,80 ---- wxCMD_LINE_VAL_NONE, wxCMD_LINE_PARAM_OPTIONAL|wxCMD_LINE_OPTION_HELP }, ! { wxCMD_LINE_SWITCH, wxT("s"), wxT("stdout"), wxT("Do NOT print output to command line stdout."), wxCMD_LINE_VAL_NONE, wxCMD_LINE_PARAM_OPTIONAL }, ! { wxCMD_LINE_SWITCH, wxT("m"), wxT("msgdlg"), wxT("Print output to a message dialog."), wxCMD_LINE_VAL_NONE, wxCMD_LINE_PARAM_OPTIONAL }, ! { wxCMD_LINE_SWITCH, wxT("c"), wxT("console"), wxT("Print output to a persistent message console."), ! wxCMD_LINE_VAL_NONE, wxCMD_LINE_PARAM_OPTIONAL }, ! ! { wxCMD_LINE_SWITCH, wxT("q"), wxT("quit"), wxT("Do not exit even if there are no top-level windows open."), ! wxCMD_LINE_VAL_NONE, wxCMD_LINE_PARAM_OPTIONAL }, ! ! { wxCMD_LINE_OPTION, wxT("e"), wxT("stat"), wxT("Execute a Lua string 'stat'."), wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL }, ! { wxCMD_LINE_OPTION, wxT("d"), wxT("debuggee"), wxT("Run as debuggee -d[host]:[port] (for internal use)"), wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL }, *************** *** 76,83 **** wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL|wxCMD_LINE_PARAM_MULTIPLE }, ! { wxCMD_LINE_OPTION, wxT("r"), wxT("run"), wxT("Run lua program with command line args."), wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL|wxCMD_LINE_PARAM_MULTIPLE}, ! { wxCMD_LINE_PARAM, wxT(""), wxT(""), wxT("Run lua program with command line args."), wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL|wxCMD_LINE_PARAM_MULTIPLE }, --- 82,89 ---- wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL|wxCMD_LINE_PARAM_MULTIPLE }, ! { wxCMD_LINE_OPTION, wxT("r"), wxT("run"), wxT("Run a Lua program with command line args."), wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL|wxCMD_LINE_PARAM_MULTIPLE}, ! { wxCMD_LINE_PARAM, wxT(""), wxT(""), wxT("Run a Lua program with command line args."), wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL|wxCMD_LINE_PARAM_MULTIPLE }, *************** *** 87,91 **** // Find the index into the argv that matches name starting at arg start_n // This is necessary since the wxCmdLineParser drops -- and all -X ! // params so we use this to make sure that the lua program is at 0. int FindFirstCmdParam(int start_n, const wxString& name, int argc, wxChar** argv) --- 93,97 ---- // Find the index into the argv that matches name starting at arg start_n // This is necessary since the wxCmdLineParser drops -- and all -X ! // params so we use this to make sure that the Lua program is at 0. int FindFirstCmdParam(int start_n, const wxString& name, int argc, wxChar** argv) *************** *** 114,117 **** --- 120,125 ---- { m_programName = argv[0]; // The name of this program + m_print_stdout = true; + m_print_msgdlg = false; m_want_console = false; m_wxlDebugTarget = NULL; *************** *** 119,123 **** int arg_count = 0; // counter for args used during parsing ! bool run_ok = false; // has the lua program executed ok bool dont_quit = false; // user specified -q switch to not quit --- 127,131 ---- int arg_count = 0; // counter for args used during parsing ! bool run_ok = false; // has the Lua program executed ok bool dont_quit = false; // user specified -q switch to not quit *************** *** 180,183 **** --- 188,203 ---- } + if (parser.Found(wxT("s"))) + { + arg_count++; // remove -s arg + m_print_stdout = false; + } + + if (parser.Found(wxT("m"))) + { + arg_count++; // remove -m arg + m_print_msgdlg = true; + } + // Check if we are to display the console if (parser.Found(wxT("c"))) *************** *** 191,195 **** } ! // Check if we are to run some lua code stat wxString luaCode; if (parser.Found(wxT("e"), &luaCode)) --- 211,215 ---- } ! // Check if we are to run some Lua code stat wxString luaCode; if (parser.Found(wxT("e"), &luaCode)) *************** *** 358,378 **** if (!is_error) { if (m_luaConsoleWrapper.Ok()) m_luaConsoleWrapper.GetConsole()->DisplayText(msg); ! else ! { ! #ifdef __WXMSW__ wxMessageBox(msg, wxT("wxLua Print")); - #else - //fprintf(stderr, wx2lua(msg + wxT("\n"))); - wxPrintf(msg + wxT("\n")); - #endif // __WXMSW__ - } } else { ! if (m_wxlDebugTarget != NULL) ! m_wxlDebugTarget->DisplayError(msg); ! else if (m_luaConsoleWrapper.Ok()) { m_luaConsoleWrapper.GetConsole()->DisplayText(msg); --- 378,398 ---- if (!is_error) { + //fprintf(stderr, wx2lua(msg + wxT("\n"))); + + if (m_print_stdout) + wxPrintf(msg + wxT("\n")); + if (m_luaConsoleWrapper.Ok()) m_luaConsoleWrapper.GetConsole()->DisplayText(msg); ! ! if (m_print_msgdlg) wxMessageBox(msg, wxT("wxLua Print")); } else { ! //if (m_print_stdout) // always print errors, FIXME: to stderr or is stdout ok? ! wxPrintf(msg + wxT("\n")); ! ! if (m_luaConsoleWrapper.Ok()) { m_luaConsoleWrapper.GetConsole()->DisplayText(msg); *************** *** 381,393 **** m_luaConsoleWrapper.GetConsole()->DisplayStack(wxlState); } ! else ! { ! #ifdef __WXMSW__ wxMessageBox(msg, wxT("wxLua Error")); - #else - //fprintf(stderr, wx2lua(msg + wxT("\n"))); - wxPrintf(msg + wxT("\n")); - #endif // __WXMSW__ - } } } --- 401,410 ---- m_luaConsoleWrapper.GetConsole()->DisplayStack(wxlState); } ! ! if (m_wxlDebugTarget != NULL) ! m_wxlDebugTarget->DisplayError(msg); ! ! if (m_print_msgdlg) wxMessageBox(msg, wxT("wxLua Error")); } } Index: lconsole.h =================================================================== RCS file: /cvsroot/wxlua/wxLua/apps/wxlua/src/lconsole.h,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** lconsole.h 5 Dec 2008 05:57:21 -0000 1.11 --- lconsole.h 5 Dec 2008 21:15:10 -0000 1.12 *************** *** 42,54 **** void SetExitOnError(bool is_error) { m_exit_on_error = m_exit_on_error || is_error; } - wxLuaConsoleWrapper* m_wrapper; - protected: void OnCloseWindow(wxCloseEvent& event); ! wxSplitterWindow *m_splitter; ! wxTextCtrl *m_textCtrl; ! wxListBox *m_debugListBox; ! bool m_exit_on_error; private: --- 42,53 ---- void SetExitOnError(bool is_error) { m_exit_on_error = m_exit_on_error || is_error; } protected: void OnCloseWindow(wxCloseEvent& event); ! wxLuaConsoleWrapper *m_wrapper; ! wxSplitterWindow *m_splitter; ! wxTextCtrl *m_textCtrl; ! wxListBox *m_debugListBox; ! bool m_exit_on_error; private: Index: wxlua.h =================================================================== RCS file: /cvsroot/wxlua/wxLua/apps/wxlua/src/wxlua.h,v retrieving revision 1.25 retrieving revision 1.26 diff -C2 -d -r1.25 -r1.26 *** wxlua.h 5 Dec 2008 05:57:21 -0000 1.25 --- wxlua.h 5 Dec 2008 21:15:10 -0000 1.26 *************** *** 38,41 **** --- 38,43 ---- wxLuaState m_wxlState; wxLuaConsoleWrapper m_luaConsoleWrapper; + bool m_print_stdout; + bool m_print_msgdlg; bool m_want_console; bool m_mem_bitmap_added; |