FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Added sys.argv · ericentin/Source.Python@d44413a · GitHub

Repository navigation

Commit d44413a

Browse files
committed
Added sys.argv
1 parent 7fd6d46 commit d44413a

1 file changed

Lines changed: 19 additions & 0 deletions

File tree

‎src/core/sp_python.cpp‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
#include "utilities/shared_utils.h"
3838
#include "export_main.h"
3939
#include "modules/entities/entities_entity_wrap.h"
40+
#include "icommandline.h"
4041

4142
BOOST_PYTHON_OPAQUE_SPECIALIZED_TYPE_ID(CBaseEntity)
4243

@@ -112,6 +113,24 @@ bool CPythonManager::Initialize( void )
112113

113114
// Print some information
114115
DevMsg(1, MSG_PREFIX "Python version %s initialized!\n", Py_GetVersion());
116+
117+
// Set sys.argv and update sys.path
118+
DevMsg(1, MSG_PREFIX "Setting sys.argv...\n");
119+
ICommandLine* pCommandLine = CommandLine();
120+
121+
int iParamCount = pCommandLine->ParmCount();
122+
wchar_t** argv = new wchar_t*[iParamCount];
123+
for (int i=0; i < iParamCount; i++)
124+
{
125+
const char* szParam = pCommandLine->GetParm(i);
126+
int iParamLength = strlen(szParam);
127+
128+
wchar_t* wszParam = new wchar_t[iParamLength];
129+
V_strtowcs(szParam, -1, wszParam, iParamLength+1);
130+
131+
argv[i] = wszParam;
132+
}
133+
PySys_SetArgv(iParamCount, argv);
115134

116135
// Make sure sys is imported.
117136
PyRun_SimpleString("import sys");

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL