From: PatR Date: Sat, 28 May 2022 19:49:08 +0000 (-0700) Subject: display lua warnings instead of ignoring them X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=07a2ba6b540403a5cd4122a59ff8a53835eb7040;p=nethack display lua warnings instead of ignoring them This will be an annoyance for wizard mode until someone actually figures out and fixes the problem. The complaints from lua during garbage collection aren't new, they were just being ignored before. --- diff --git a/doc/fixes3-7-0.txt b/doc/fixes3-7-0.txt index bf1f7d471..223aed27f 100644 --- a/doc/fixes3-7-0.txt +++ b/doc/fixes3-7-0.txt @@ -911,6 +911,11 @@ using a marker to write "novel" or "paperback book" on a known blank spellbook was producing a randomly chosen Pratchett novel; make it fail instead when a monster killed a pudding and it left a glob, that glob might not be displayed on the map (wasn't an issue for killed-by-hero case) +lua's garbage collection doesn't like the way nethack is trying to use it and + issues a pair of warnings each time the relevant code gets run; they + were vanishing into a bit bucket but now they will be displayed when + running in wizard mode; we need to fix the usage rather than just + hide the feedback Fixes to 3.7.0-x Problems that Were Exposed Via git Repository diff --git a/src/nhlua.c b/src/nhlua.c index a029e82a9..75ab9422d 100644 --- a/src/nhlua.c +++ b/src/nhlua.c @@ -2273,6 +2273,32 @@ nhl_panic(lua_State *L) return 0; /* return to Lua to abort */ } +/* called when lua issues a warning message; the text of the message + is passed to us in pieces across multiple function calls */ +static void +nhl_warn( + void *userdata UNUSED, + const char *msg_fragment, + int to_be_continued) /* 0: last fragment; 1: more to come */ +{ + static char warnbuf[BUFSZ]; + size_t fraglen, buflen = strlen(warnbuf); + + if (msg_fragment && buflen < sizeof warnbuf - 1) { + fraglen = strlen(msg_fragment); + if (buflen + fraglen > sizeof warnbuf - 1) + fraglen = sizeof warnbuf - 1 - buflen; + (void) strncat(warnbuf, msg_fragment, fraglen); + } + if (!to_be_continued) { + /* this is a warning so probably ought to be delivered via + impossible() but until the current garbage collection issue + gets fixed that would be way too verbose */ + pline("[lua] %s", warnbuf); + warnbuf[0] = '\0'; + } +} + #ifdef NHL_SANDBOX static void nhl_hookfn(lua_State *L, lua_Debug *ar UNUSED) @@ -2311,7 +2337,9 @@ nhlL_newstate(nhl_sandbox_info *sbi) lua_atpanic(L, nhl_panic); #if LUA_VERSION_NUM == 504 - lua_setwarnf(L, (lua_WarnFunction) 0, L); + /* issue lua warnings only when in wizard mode, at least until + someone figures out and fixes the garbage collection problem */ + lua_setwarnf(L, wizard ? nhl_warn : (lua_WarnFunction) 0, L); #endif #ifdef NHL_SANDBOX