From: John L. <jr...@us...> - 2006-12-07 22:05:59
|
Update of /cvsroot/wxlua/wxLua/apps/wxlua/src In directory sc8-pr-cvs9.sourceforge.net:/tmp/cvs-serv11065/wxLua/apps/wxlua/src Modified Files: lconsole.cpp lconsole.h wxlua.cpp Log Message: cleanup arg processing for wxLua program to match the lua program Index: wxlua.cpp =================================================================== RCS file: /cvsroot/wxlua/wxLua/apps/wxlua/src/wxlua.cpp,v retrieving revision 1.40 retrieving revision 1.41 diff -C2 -d -r1.40 -r1.41 *** wxlua.cpp 7 Dec 2006 01:22:02 -0000 1.40 --- wxlua.cpp 7 Dec 2006 22:05:52 -0000 1.41 *************** *** 54,76 **** static const wxCmdLineEntryDesc cmdLineDesc[] = { ! { wxCMD_LINE_SWITCH, wxT("h"), wxT("help"), wxT("help on command line switches"), 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_OPTION, wxT("d"), wxT("debuggee"), wxT("run as debuggee, -d[host]:[port]"), wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL }, ! { wxCMD_LINE_OPTION, wxT("e"), wxT("edit"), wxT("open file(s) to edit"), ! wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL|wxCMD_LINE_PARAM_MULTIPLE|wxCMD_LINE_NEEDS_SEPARATOR }, ! { 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 }, ! { 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_PARAM, wxT(""), wxT(""), wxT("run wxLua program w/ command line args"), wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL|wxCMD_LINE_PARAM_MULTIPLE }, --- 54,79 ---- static const wxCmdLineEntryDesc cmdLineDesc[] = { ! { wxCMD_LINE_SWITCH, wxT("h"), wxT("help"), wxT("Help on command line switches."), 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 }, ! { wxCMD_LINE_OPTION, wxT("o"), wxT("open"), wxT("Open file(s) to edit."), ! 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 }, *************** *** 78,81 **** --- 81,99 ---- }; + // 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) + { + for (int arg_n = start_n; arg_n < argc; arg_n++) + { + if (argv[arg_n] == name) + return arg_n - 1; + } + + return start_n; //oops? just return what was given. + } + // --------------------------------------------------------------------------- // wxLuaStandaloneApp *************** *** 134,137 **** --- 152,160 ---- wxCmdLineParser parser(cmdLineDesc, argc, argv); + parser.SetLogo(wxString::Format(wxT("Welcome to %s\n") + wxT("The editor is opened if no parameters are given.\n") + wxT("Note: specify the parameters in the order shown and -d, -o, -r are exclusive.\n") + wxT("To stop this program from processing command line args use '--'.\n"), + WXLUA_VERSION_STRING)); switch ( parser.Parse() ) *************** *** 139,169 **** case -1 : { ! // help should be given by the wxCmdLineParser, exit program return false; } case 0: { ! wxString value; ! ! // don't quit the program for no top level windows if (parser.Found(wxT("q"))) dont_quit = true; // Check if we are to display the console if (parser.Found(wxT("c"))) { ! arg_count++; m_want_console = true; m_luaConsole = new wxLuaConsole(NULL, ID_WXLUA_CONSOLE); m_luaConsole->Show(true); } ! // set up for debugging ! if (parser.Found(wxT("d"), &value)) { // Note: wxLuaDebuggerServer::StartClient() runs // wxExecute(m_programName -d[host]:[port], ...) ! wxString serverName(value.BeforeFirst(wxT(':'))); if (serverName.IsEmpty()) --- 162,211 ---- case -1 : { ! // Help should be given by the wxCmdLineParser, exit program return false; } case 0: { ! // Don't quit the program even if no top level windows open if (parser.Found(wxT("q"))) + { + arg_count++; // remove -q arg dont_quit = true; + } // Check if we are to display the console if (parser.Found(wxT("c"))) { ! 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); } ! // Check if we are to run some lua code stat ! wxString luaCode; ! if (parser.Found(wxT("e"), &luaCode)) ! { ! arg_count++; // remove -e arg ! int rc = m_wxlState.RunString(luaCode, wxT("=(command line)")); ! wxString errorStr; ! run_ok = wxLuaState::CheckRunError(rc, &errorStr); ! if (!run_ok) ! { ! DisplayMessage(errorStr, true, m_wxlState); ! break; ! } ! } ! ! // Set up for debugging ! wxString debugString; ! if (parser.Found(wxT("d"), &debugString)) { // Note: wxLuaDebuggerServer::StartClient() runs // wxExecute(m_programName -d[host]:[port], ...) ! wxString serverName(debugString.BeforeFirst(wxT(':'))); if (serverName.IsEmpty()) *************** *** 174,178 **** { long portNumber = 0; ! if (value.AfterFirst(wxT(':')).ToLong(&portNumber)) { m_pDebugTarget = new wxLuaDebugTarget(m_wxlState, serverName, (int)portNumber); --- 216,220 ---- { long portNumber = 0; ! if (debugString.AfterFirst(wxT(':')).ToLong(&portNumber)) { m_pDebugTarget = new wxLuaDebugTarget(m_wxlState, serverName, (int)portNumber); *************** *** 189,198 **** } ! // See if a file has been specified to edit or just start editor ! bool run_editor = parser.Found(wxT("e"), &value); ! if (run_editor || (parser.GetParamCount() == 0)) ! { ! // remove -e arg, but push the args in any case ! if (run_editor) arg_count++; PushArgs(argv, argc, arg_count); --- 231,248 ---- } ! ! // See if a file has been specified to open or just start editor ! // if there are no parameters. ! wxString openFileName; ! bool open_file = parser.Found(wxT("o"), &openFileName); ! if (open_file) arg_count++; // remove -o arg ! ! if (open_file || (parser.GetParamCount() == 0)) ! { ! if (openFileName.IsEmpty() && (parser.GetParamCount() > 0u)) ! openFileName = parser.GetParam(0); ! if (!openFileName.IsEmpty()) ! arg_count = FindFirstCmdParam(arg_count, openFileName, argc, argv); ! PushArgs(argv, argc, arg_count); *************** *** 212,220 **** //if (parser.Found(wxT("r"), &value)) { arg_count++; // skip the program we're running - wxString fileName = parser.GetParam(0); // already handled 0 params PushArgs(argv, argc, arg_count); ! int rc = m_wxlState.RunFile(fileName); wxString errorStr; run_ok = wxLuaState::CheckRunError(rc, &errorStr); --- 262,275 ---- //if (parser.Found(wxT("r"), &value)) { + wxString runFileName; + if (!parser.Found(wxT("r"), &runFileName) && (parser.GetParamCount() > 0u)) + runFileName = parser.GetParam(0); + if (!runFileName.IsEmpty()) + arg_count = FindFirstCmdParam(arg_count, runFileName, argc, argv); + arg_count++; // skip the program we're running PushArgs(argv, argc, arg_count); ! int rc = m_wxlState.RunFile(runFileName); wxString errorStr; run_ok = wxLuaState::CheckRunError(rc, &errorStr); *************** *** 259,263 **** m_want_console = false; // no more messages ! if (m_luaConsole) { m_luaConsole->Destroy(); --- 314,318 ---- m_want_console = false; // no more messages ! if (m_luaConsole && !m_luaConsole->IsBeingDeleted()) { m_luaConsole->Destroy(); *************** *** 299,304 **** wxMessageBox(msg, wxT("wxLua Print")); #else ! fprintf(stderr, wx2lua(msg + wxT("\n"))); ! //wxPrintf(msg + wxT("\n")); #endif // __WXMSW__ } --- 354,359 ---- wxMessageBox(msg, wxT("wxLua Print")); #else ! //fprintf(stderr, wx2lua(msg + wxT("\n"))); ! wxPrintf(msg + wxT("\n")); #endif // __WXMSW__ } *************** *** 312,316 **** m_luaConsole->DisplayText(msg); m_luaConsole->SetExitOnError(is_error); ! m_luaConsole->DisplayStack(wxlState); } else --- 367,372 ---- m_luaConsole->DisplayText(msg); m_luaConsole->SetExitOnError(is_error); ! if (wxlState.Ok()) ! m_luaConsole->DisplayStack(wxlState); } else *************** *** 319,323 **** wxMessageBox(msg, wxT("wxLua Error")); #else ! fprintf(stderr, wx2lua(msg + wxT("\n"))); #endif // __WXMSW__ } --- 375,380 ---- wxMessageBox(msg, wxT("wxLua Error")); #else ! //fprintf(stderr, wx2lua(msg + wxT("\n"))); ! wxPrintf(msg + wxT("\n")); #endif // __WXMSW__ } *************** *** 346,350 **** // no real args, just stick in the name of this program lua_newtable(L); ! lua_pushstring(L, wx2lua(m_programName)); lua_rawseti(L, -2, 0); lua_setglobal(L, "arg"); --- 403,407 ---- // no real args, just stick in the name of this program lua_newtable(L); ! lua_pushstring(L, wx2lua(argv[0])); lua_rawseti(L, -2, 0); lua_setglobal(L, "arg"); Index: lconsole.h =================================================================== RCS file: /cvsroot/wxlua/wxLua/apps/wxlua/src/lconsole.h,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** lconsole.h 7 Dec 2006 01:22:02 -0000 1.8 --- lconsole.h 7 Dec 2006 22:05:52 -0000 1.9 *************** *** 17,20 **** --- 17,24 ---- #include "wxlua/include/wxlua.h" + class WXDLLEXPORT wxSplitterWindow; + class WXDLLEXPORT wxTextCtrl; + class WXDLLEXPORT wxListBox; + // ---------------------------------------------------------------------------- // wxLuaConsole - define a console class to display print statements Index: lconsole.cpp =================================================================== RCS file: /cvsroot/wxlua/wxLua/apps/wxlua/src/lconsole.cpp,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** lconsole.cpp 7 Dec 2006 01:22:02 -0000 1.13 --- lconsole.cpp 7 Dec 2006 22:05:52 -0000 1.14 *************** *** 65,68 **** --- 65,71 ---- 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; |