File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -152,13 +152,38 @@ void PythonHandler::initPython()
152152
153153 PyRun_SimpleString (initBuffer);
154154
155+ initSysArgv ();
156+
157+
155158 // Init Notepad++/Scintilla modules
156159 initModules ();
157160
158161 mp_mainThreadState = PyEval_SaveThread ();
159162
160163}
161164
165+ void PythonHandler::initSysArgv ()
166+ {
167+ LPWSTR commandLine = ::GetCommandLineW ();
168+ int argc;
169+ LPWSTR* argv = ::CommandLineToArgvW (commandLine, &argc);
170+
171+
172+ boost::python::list argvList;
173+ for (int currentArg = 0 ; currentArg != argc; ++currentArg)
174+ {
175+ std::shared_ptr<char > argInUtf8 = WcharMbcsConverter::wchar2char (argv[currentArg]);
176+ PyObject* unicodeArg = PyUnicode_FromString (argInUtf8.get ());
177+
178+ argvList.append (boost::python::handle<>(unicodeArg));
179+ }
180+
181+ boost::python::object sysModule (boost::python::handle<>(boost::python::borrowed (PyImport_AddModule (" sys" ))));
182+ sysModule.attr (" argv" ) = argvList;
183+
184+
185+ }
186+
162187void PythonHandler::initModules ()
163188{
164189 importScintilla (mp_scintilla, mp_scintilla1, mp_scintilla2);
Original file line number Diff line number Diff line change @@ -89,7 +89,7 @@ class PythonHandler : public PyProducerConsumer<RunScriptArgs>
8989
9090 // Private methods
9191 void initModules ();
92-
92+ void initSysArgv ();
9393 static void stopScriptWorker (PythonHandler *handler);
9494 bool containsExtendedChars (char *s);
9595
You can’t perform that action at this time.
0 commit comments