MCPcopy Create free account
hub / github.com/codereader/DarkRadiant / executeString

Method executeString

plugins/script/PythonModule.cpp:101–135  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

99}
100
101ExecutionResultPtr PythonModule::executeString(const std::string& scriptString)
102{
103 ExecutionResultPtr result = std::make_shared<ExecutionResult>();
104
105 result->errorOccurred = false;
106
107 // Clear the output buffers before starting to execute
108 _outputBuffer.clear();
109 _errorBuffer.clear();
110
111 try
112 {
113 std::string fullScript = "import " + std::string(ModuleName) + " as DR\n"
114 "from " + std::string(ModuleName) + " import *\n";
115 fullScript.append(scriptString);
116
117 // Attempt to run the specified script
118 py::eval<py::eval_statements>(fullScript, getGlobals());
119 }
120 catch (py::error_already_set& ex)
121 {
122 _errorBuffer.append(ex.what());
123 result->errorOccurred = true;
124
125 rError() << "Error executing script: " << ex.what() << std::endl;
126 }
127
128 result->output += _outputBuffer + "\n";
129 result->output += _errorBuffer + "\n";
130
131 _outputBuffer.clear();
132 _errorBuffer.clear();
133
134 return result;
135}
136
137void PythonModule::executeScriptFile(const std::string& scriptBasePath, const std::string& relativeScriptPath, bool setExecuteCommandAttr)
138{

Callers 1

onRunScriptMethod · 0.45

Calls 4

rErrorFunction · 0.85
whatMethod · 0.80
clearMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected