]> granicus.if.org Git - nethack/commitdiff
display lua warnings instead of ignoring them
authorPatR <rankin@nethack.org>
Sat, 28 May 2022 19:49:08 +0000 (12:49 -0700)
committerPatR <rankin@nethack.org>
Sat, 28 May 2022 19:49:08 +0000 (12:49 -0700)
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.

doc/fixes3-7-0.txt
src/nhlua.c

index bf1f7d471048e271b81c40ccea175ca7e22f795a..223aed27f4f0684ef9c48369ab2ff05d3d70008a 100644 (file)
@@ -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
index a029e82a9ef878bce59276bb500644e42647bcaf..75ab9422dd8919cac832fe9d6613da8c92a298e3 100644 (file)
@@ -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