MCPcopy Create free account
hub / github.com/BohemiaInteractive/CWR / tryEval

Function tryEval

engine/Evaluator/Validate.cpp:165–217  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

163}
164
165static ValidationResult tryEval(const std::string& source, int index, const std::string& code, const std::string& lang,
166 EvalState& state)
167{
168 ValidationResult res;
169 res.source = source;
170 res.index = index;
171 res.code = code;
172 res.status = "pass";
173
174 if (needsGameObjects(code))
175 {
176 res.status = "skip";
177 res.error = "uses game-object commands";
178 return res;
179 }
180
181 std::string safeCode = sanitizeAscii(code);
182 state.clearOutput();
183
184 if (lang == "sqs")
185 {
186 SqsRunner runner(source);
187 runner.parse(safeCode);
188 int ret = runner.run(state, GameValue());
189 if (ret != 0)
190 {
191 res.status = "fail";
192 RString errText = state.GetLastErrorText();
193 if (errText.GetLength() > 0)
194 res.error = (const char*)errText;
195 else
196 res.error = "SQS execution error";
197 }
198 }
199 else
200 {
201 GameVarSpace local(state.GetContext());
202 state.BeginContext(&local);
203 state.EvaluateMultiple(safeCode.c_str());
204 EvalError err = state.GetLastError();
205 state.EndContext();
206 if (err != EvalOK)
207 {
208 res.status = "fail";
209 RString errText = state.GetLastErrorText();
210 if (errText.GetLength() > 0)
211 res.error = (const char*)errText;
212 else
213 res.error = "evaluation error";
214 }
215 }
216 return res;
217}
218
219ValidationSummary validateBook(const std::string& bookDir, GameState& gs, bool verbose)
220{

Callers 2

validateBookFunction · 0.85
validateRefFunction · 0.85

Calls 13

needsGameObjectsFunction · 0.85
sanitizeAsciiFunction · 0.85
clearOutputMethod · 0.80
runMethod · 0.80
GetLastErrorTextMethod · 0.80
BeginContextMethod · 0.80
EvaluateMultipleMethod · 0.80
GetLastErrorMethod · 0.80
EndContextMethod · 0.80
GameValueClass · 0.70
parseMethod · 0.45
GetLengthMethod · 0.45

Tested by

no test coverage detected