From: Pasi Kallinen Date: Wed, 16 Mar 2022 14:58:42 +0000 (+0200) Subject: Lua: allow calling impossible X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=811299edafb9efe106d900123ae63eb1735a15d9;p=nethack Lua: allow calling impossible --- diff --git a/doc/lua.adoc b/doc/lua.adoc index e0360347c..584895bd6 100644 --- a/doc/lua.adoc +++ b/doc/lua.adoc @@ -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). diff --git a/src/nhlua.c b/src/nhlua.c index 3cfce4b92..ad8eb7756 100644 --- a/src/nhlua.c +++ b/src/nhlua.c @@ -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},