Execute the map's Lua, perform substitutions and other transformations, and validate the map
| 177 | // Execute the map's Lua, perform substitutions and other transformations, |
| 178 | // and validate the map |
| 179 | static bool _resolve_map_lua(map_def &map) |
| 180 | { |
| 181 | _dgn_flush_map_environment_for(map.name); |
| 182 | map.reinit(); |
| 183 | |
| 184 | string err = map.run_lua(true); |
| 185 | if (!err.empty()) |
| 186 | { |
| 187 | #ifdef DEBUG_STATISTICS |
| 188 | if (crawl_state.map_stat_gen) |
| 189 | mapstat_report_error(map, err); |
| 190 | #endif |
| 191 | crawl_state.last_builder_error = err; |
| 192 | crawl_state.last_builder_error_fatal = true; |
| 193 | |
| 194 | // Modes like mapstat/objstat that put errors on stderr need to see the |
| 195 | // per-iteration seed. |
| 196 | string seed_inf = ""; |
| 197 | if (msg::uses_stderr(MSGCH_ERROR)) |
| 198 | seed_inf = make_stringf(" in seed %" PRIu64, crawl_state.seed); |
| 199 | mprf(MSGCH_ERROR, "Fatal lua error%s: %s", seed_inf.c_str(), |
| 200 | err.c_str()); |
| 201 | // If we're using stderr, we don't have a morgue, so any dlua stack |
| 202 | // trace should also go to stderr. |
| 203 | if (msg::uses_stderr(MSGCH_ERROR) && !dlua_errors.empty()) |
| 204 | mprf(MSGCH_ERROR, "\n%s", dlua_errors.back().stack_trace.c_str()); |
| 205 | return false; |
| 206 | } |
| 207 | |
| 208 | map.fixup(); |
| 209 | |
| 210 | // this is non-fatal: maps use validation to enforce basic placement |
| 211 | // constraints, and a failure here should mean retrying |
| 212 | if (!map.test_lua_validate(false)) |
| 213 | { |
| 214 | crawl_state.last_builder_error = make_stringf( |
| 215 | "Lua validation for map %s failed.", map.name.c_str()); |
| 216 | dprf("%s", crawl_state.last_builder_error.c_str()); |
| 217 | return false; |
| 218 | } |
| 219 | |
| 220 | return true; |
| 221 | } |
| 222 | |
| 223 | // Resolve Lua and transformation directives, then mirror and rotate the |
| 224 | // map if allowed |
no test coverage detected