}
boolean
-com_pager_core(section, msgid)
+com_pager_core(section, msgid, showerror)
const char *section;
const char *msgid;
+boolean showerror;
{
const char *const howtoput[] = { "pline", "window", "text", "menu", "default", NULL };
const int howtoput2i[] = { 1, 2, 2, 3, 0, 0 };
lua_State *L;
char *synopsis;
char *text;
+ char *fallback_msgid = NULL;
if (skip_pager(TRUE))
return FALSE;
L = nhl_init();
if (!nhl_loadlua(L, QTEXT_FILE)) {
- impossible("com_pager: %s not found.", QTEXT_FILE);
+ if (showerror)
+ impossible("com_pager: %s not found.", QTEXT_FILE);
lua_close(L);
return FALSE;
}
lua_settop(L, 0);
lua_getglobal(L, "questtext");
if (!lua_istable(L, -1)) {
- impossible("com_pager: questtext in %s is not a lua table", QTEXT_FILE);
+ if (showerror)
+ impossible("com_pager: questtext in %s is not a lua table",
+ QTEXT_FILE);
lua_close(L);
return FALSE;
}
lua_getfield(L, -1, section);
if (!lua_istable(L, -1)) {
- impossible("com_pager: questtext[%s] in %s is not a lua table", section, QTEXT_FILE);
+ if (showerror)
+ impossible("com_pager: questtext[%s] in %s is not a lua table",
+ section, QTEXT_FILE);
lua_close(L);
return FALSE;
}
- lua_getfield(L, -1, msgid);
+tryagain:
+ lua_getfield(L, -1, fallback_msgid ? fallback_msgid : msgid);
if (!lua_istable(L, -1)) {
- impossible("com_pager: questtext[%s][%s] in %s is not a lua table", section, msgid, QTEXT_FILE);
+ if (!fallback_msgid) {
+ /* Do we have questtxt[msg_fallbacks][<msgid>]? */
+ lua_getfield(L, -3, "msg_fallbacks");
+ if (lua_istable(L, -1)) {
+ fallback_msgid = get_table_str_opt(L, msgid, NULL);
+ lua_pop(L, 2);
+ if (fallback_msgid)
+ goto tryagain;
+ }
+ }
+
+ if (showerror)
+ impossible("com_pager: questtext[%s][%s] in %s is not a lua table",
+ section, msgid, QTEXT_FILE);
+ free(fallback_msgid);
lua_close(L);
return FALSE;
}
nelems = (int) lua_tointeger(L, -1);
lua_pop(L, 1);
if (nelems < 2) {
- impossible(
- "com_pager: questtext[%s][%s] in %s in not an array of strings",
+ if (showerror)
+ impossible(
+ "com_pager: questtext[%s][%s] in %s in not an array of strings",
section, msgid, QTEXT_FILE);
+ free(fallback_msgid);
lua_close(L);
return FALSE;
}
free(synopsis);
}
+ free(fallback_msgid);
free(text);
lua_close(L);
return TRUE;
com_pager(msgid)
const char *msgid;
{
- com_pager_core("common", msgid);
+ com_pager_core("common", msgid, TRUE);
}
void
qt_pager(msgid)
const char *msgid;
{
- if (!com_pager_core(g.urole.filecode, msgid))
- com_pager_core("common", msgid);
+ if (!com_pager_core(g.urole.filecode, msgid, FALSE))
+ com_pager_core("common", msgid, TRUE);
}
struct permonst *