]> granicus.if.org Git - nethack/commitdiff
send lua warnings to paniclog instead to player
authorPatR <rankin@nethack.org>
Wed, 1 Jun 2022 08:03:11 +0000 (01:03 -0700)
committerPatR <rankin@nethack.org>
Wed, 1 Jun 2022 08:03:11 +0000 (01:03 -0700)
Now that the garbage collection problem has been fixed, record lua
warnings in the paniclog file rather than showing them on the screen.

Move nhl_warn()'s warnbuf[] to struct g in case restart ever gets
implemented so that it can be cleared if the restart occurred while
a warning message was under construction.

include/decl.h
src/decl.c
src/nhlua.c

index ba1377698f5e05a05a8e0b97930f40245eb667c7..6628212877d4b41e53a9cbceba6e53afd11e34b0 100644 (file)
@@ -1,4 +1,4 @@
-/* NetHack 3.7  decl.h  $NHDT-Date: 1645000560 2022/02/16 08:36:00 $  $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.283 $ */
+/* NetHack 3.7  decl.h  $NHDT-Date: 1654070559 2022/06/01 08:02:39 $  $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.296 $ */
 /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
 /*-Copyright (c) Michael Allison, 2007. */
 /* NetHack may be freely redistributed.  See license for details. */
@@ -1048,6 +1048,7 @@ struct instance_globals {
 
     /* nhlua.c */
     genericptr_t luacore; /* lua_State * */
+    char lua_warnbuf[BUFSZ];
 
     /* o_init.c */
     short disco[NUM_OBJECTS];
index 19b87151f6a17a337cd1105fecc307efa972f3c6..5cf81733a5c8b5fda2b8b89f4f498785c01147a1 100644 (file)
@@ -1,4 +1,4 @@
-/* NetHack 3.7 decl.c  $NHDT-Date: 1645000574 2022/02/16 08:36:14 $  $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.248 $ */
+/* NetHack 3.7 decl.c  $NHDT-Date: 1654070576 2022/06/01 08:02:56 $  $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.255 $ */
 /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
 /*-Copyright (c) Michael Allison, 2009. */
 /* NetHack may be freely redistributed.  See license for details. */
@@ -511,6 +511,7 @@ const struct instance_globals g_init = {
 
     /* nhlua.c */
     UNDEFINED_VALUE, /* luacore */
+    DUMMY, /* lua_warnbuf[] */
 
     /* o_init.c */
     DUMMY, /* disco */
index 5fc39a7e1ac8b95efbfdac0108825817a214cba4..09709469621871ac9e99f774702cb60aaf746d7c 100644 (file)
@@ -1,4 +1,4 @@
-/* NetHack 3.7 nhlua.c $NHDT-Date: 1652897460 2022/05/18 18:11:00 $  $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.78 $ */
+/* NetHack 3.7 nhlua.c $NHDT-Date: 1654070580 2022/06/01 08:03:00 $  $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.83 $ */
 /*      Copyright (c) 2018 by Pasi Kallinen */
 /* NetHack may be freely redistributed.  See license for details. */
 
@@ -2278,21 +2278,17 @@ nhl_warn(
     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);
+    size_t fraglen, buflen = strlen(g.lua_warnbuf);
 
-    if (msg_fragment && buflen < sizeof warnbuf - 1) {
+    if (msg_fragment && buflen < sizeof g.lua_warnbuf - 1) {
         fraglen = strlen(msg_fragment);
-        if (buflen + fraglen > sizeof warnbuf - 1)
-            fraglen = sizeof warnbuf - 1 - buflen;
-        (void) strncat(warnbuf, msg_fragment, fraglen);
+        if (buflen + fraglen > sizeof g.lua_warnbuf - 1)
+            fraglen = sizeof g.lua_warnbuf - 1 - buflen;
+        (void) strncat(g.lua_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';
+        paniclog("[lua]", g.lua_warnbuf);
+        g.lua_warnbuf[0] = '\0';
     }
 }