.des file so that level-designers can find the lines that are causing the problem.
git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@1641 c06c8d41-db1a-0410-9941-cceddc491573
B3SRWSFITQMJRVEBHGQQJARETYPSSDV6XKMQSSUTXEHTXRZKIQJQC NCDWWDJQLAU5ORSAQGZKJJ5E22VTDGGPJMVVBWQFHQ2B3U3UFHDQC 34C4U6EQWERY75GZJKUCM5KVGU2OUICETS5LGZF6RMKMZT4R5SQAC RPOZZWKG5GLPHVZZ7ZKMKS64ZMV2LDCQSARBJFJ6FZOTOKCQO7FAC W52PCSHX72WAMWKG6L4BPUBVMO6E72KYYBNKAA7554KNOTY6V7WQC KXUQB3WNWC5IFL6VFWADEPQMMU3VV3NDI5FLA666PGOEWFYUHCLQC AUXHSGS4EFOPZ6TVZYWNVOUDO7NYKUKE3HBKGQQWTALSVFOE3HAAC SDLKLUNFGVKDS55DDJZCBAVIB7NL3RRYPTACAY65SCUQKV6APFSAC }bool dlua_chunk::rewrite_chunk_errors(std::string &s) const{if (s.find(context) == std::string::npos)return (false);// Our chunk is mentioned, go back through and rewrite lines.std::vector<std::string> lines = split_string("\n", s);std::string newmsg = lines[0];bool wrote_prefix = false;for (int i = 2, size = lines.size() - 1; i < size; ++i){const std::string &st = lines[i];if (st.find(context) != std::string::npos){if (!wrote_prefix){newmsg = get_chunk_prefix(st) + ": " + newmsg;wrote_prefix = true;}elsenewmsg += "\n" + rewrite_chunk_prefix(st);}}s = newmsg;return (true);
std::string dlua_chunk::rewrite_chunk_prefix(const std::string &line) const{std::string s = line;const std::string contextm = "[string \"" + context + "\"]:";const std::string::size_type ps = s.find(contextm);if (ps == std::string::npos)return (s);std::string::size_type pe = s.find(':', ps + contextm.length());if (pe != std::string::npos){const std::string::size_type lns = ps + contextm.length();const std::string line_num = s.substr(lns, pe - lns);const int lnum = atoi(line_num.c_str());s = s.substr(0, lns) + make_stringf("%d", lnum + first - 1)+ s.substr(pe);}return s.substr(0, ps) + (file.empty()? context : file) + ":"+ s.substr(ps + contextm.length());}std::string dlua_chunk::get_chunk_prefix(const std::string &sorig) const{std::string s = rewrite_chunk_prefix(sorig);const std::string::size_type cpos = s.find(':');if (cpos == std::string::npos)return (s);const std::string::size_type cnpos = s.find(':', cpos + 1);if (cnpos == std::string::npos)return (s);return s.substr(0, cnpos);}
}LUARET1(crawl_game_started, boolean, crawl_state.need_save)static int crawl_err_trace(lua_State *ls){const int nargs = lua_gettop(ls);const int err = lua_pcall(ls, nargs - 1, LUA_MULTRET, 0);if (err){// This code from lua.c:traceback() (mostly)const char *errs = lua_tostring(ls, 1);std::string errstr = errs? errs : "";lua_getfield(ls, LUA_GLOBALSINDEX, "debug");if (!lua_istable(ls, -1)){lua_pop(ls, 1);return lua_error(ls);}lua_getfield(ls, -1, "traceback");if (!lua_isfunction(ls, -1)){lua_pop(ls, 2);return lua_error(ls);}lua_pushvalue(ls, 1);lua_pushinteger(ls, 2); // Skip crawl_err_trace and traceback.lua_call(ls, 2, 1);// What's on top should be the error.lua_error(ls);}return (lua_gettop(ls));