| 163 | } |
| 164 | |
| 165 | static 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 | |
| 219 | ValidationSummary validateBook(const std::string& bookDir, GameState& gs, bool verbose) |
| 220 | { |
no test coverage detected