git: c54653978ebd - stable/14 - loader: Simplify the loader.has_command

From: Warner Losh <imp_at_FreeBSD.org>
Date: Tue, 16 Apr 2024 20:12:42 UTC
The branch stable/14 has been updated by imp:

URL: https://cgit.FreeBSD.org/src/commit/?id=c54653978ebd2ad8f6cea4b8220bb620b1f3db40

commit c54653978ebd2ad8f6cea4b8220bb620b1f3db40
Author:     Warner Losh <imp@FreeBSD.org>
AuthorDate: 2024-02-16 03:52:41 +0000
Commit:     Warner Losh <imp@FreeBSD.org>
CommitDate: 2024-04-16 19:54:23 +0000

    loader: Simplify the loader.has_command
    
    luaL_checkstring already checks for the right number of
    arguments. There's no need to do that by hand here. Now an exception
    will be thrown like any other function with the wrong args. Also,
    push a boolean instead of an int.
    
    Sponsored by:           Netflix
    Differential Revision:  https://reviews.freebsd.org/D43820
    
    (cherry picked from commit 7fc95c31f007ef01c53aa5f9d8802e9579f408ee)
---
 stand/liblua/lutils.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/stand/liblua/lutils.c b/stand/liblua/lutils.c
index 8066d3f685f7..182bd699dbc3 100644
--- a/stand/liblua/lutils.c
+++ b/stand/liblua/lutils.c
@@ -65,14 +65,15 @@ lua_has_command(lua_State *L)
 {
 	const char	*cmd;
 
-	if (lua_gettop(L) != 1) {
-		lua_pushnil(L);
+	cmd = luaL_checkstring(L, 1);
+	if (interp_has_builtin_cmd(cmd)) {
+		lua_pushboolean(L, 1);
 		return 1;
 	}
-	cmd = luaL_checkstring(L, 1);
-	lua_pushinteger(L, interp_has_builtin_cmd(cmd));
 
-	return 1;
+	lua_pushnil(L);
+	lua_pushstring(L, "Builtin command not found");
+	return 2;
 }
 
 static int