]> granicus.if.org Git - nethack/commitdiff
Lua: allow calling impossible
authorPasi Kallinen <paxed@alt.org>
Wed, 16 Mar 2022 14:58:42 +0000 (16:58 +0200)
committerPasi Kallinen <paxed@alt.org>
Wed, 16 Mar 2022 14:58:42 +0000 (16:58 +0200)
doc/lua.adoc
src/nhlua.c

index e0360347c37ca621e2ccbfe12a34be2dd498c317..584895bd6e87b853c3295259194c1ed6c5de5450 100644 (file)
@@ -187,6 +187,15 @@ Example:
  nh.deltrap(x, y);
 
 
+=== impossible
+
+Issue an impossible, signaling a possible error in the code.
+
+Example:
+
+ nh.impossible("Something errory happened!");
+
+
 === ing_suffix
 
 Construct a gerund (a verb formed by appending "ing" to a noun).
index 3cfce4b92f6a72e4e5725f6df651a8e554576f03..ad8eb7756bdee3e28b95a9847ac9261263f67e05 100644 (file)
@@ -34,6 +34,7 @@ static int nhl_deltrap(lua_State *);
 #if 0
 static int nhl_setmap(lua_State *);
 #endif
+static int nhl_impossible(lua_State *);
 static int nhl_pline(lua_State *);
 static int nhl_verbalize(lua_State *);
 static int nhl_parse_config(lua_State *);
@@ -491,6 +492,19 @@ nhl_getmap(lua_State *L)
 
 RESTORE_WARNING_CONDEXPR_IS_CONSTANT
 
+/* impossible("Error!") */
+static int
+nhl_impossible(lua_State *L)
+{
+    int argc = lua_gettop(L);
+
+    if (argc == 1)
+        impossible("%s", luaL_checkstring(L, 1));
+    else
+        nhl_error(L, "Wrong args");
+    return 0;
+}
+
 /* pline("It hits!") */
 static int
 nhl_pline(lua_State *L)
@@ -1154,6 +1168,7 @@ static const struct luaL_Reg nhl_functions[] = {
 
     {"abscoord", nhl_abs_coord},
 
+    {"impossible", nhl_impossible},
     {"pline", nhl_pline},
     {"verbalize", nhl_verbalize},
     {"menu", nhl_menu},