git: 69c6f6347c12 - stable/13 - stand: Add lua binding loader.has_command
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Tue, 24 Jan 2023 22:12:20 UTC
The branch stable/13 has been updated by imp: URL: https://cgit.FreeBSD.org/src/commit/?id=69c6f6347c126df97245499a18d94537de5cdefd commit 69c6f6347c126df97245499a18d94537de5cdefd Author: Warner Losh <imp@FreeBSD.org> AuthorDate: 2022-09-01 17:06:19 +0000 Commit: Warner Losh <imp@FreeBSD.org> CommitDate: 2023-01-24 21:49:32 +0000 stand: Add lua binding loader.has_command Give scripts the ability to determine if the currently running loader has provided a command. Sponsored by: Netflix Differential Revision: https://reviews.freebsd.org/D36365 (cherry picked from commit 29fc4075e69fd27de0cded313ac6000165d99f8b) --- stand/liblua/lutils.c | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/stand/liblua/lutils.c b/stand/liblua/lutils.c index 9243edd07e8f..1649ac9fd508 100644 --- a/stand/liblua/lutils.c +++ b/stand/liblua/lutils.c @@ -63,6 +63,21 @@ lua_command(lua_State *L) return 1; } +static int +lua_has_command(lua_State *L) +{ + const char *cmd; + + if (lua_gettop(L) != 1) { + lua_pushnil(L); + return 1; + } + cmd = luaL_checkstring(L, 1); + lua_pushinteger(L, interp_has_builtin_cmd(cmd)); + + return 1; +} + static int lua_perform(lua_State *L) { @@ -539,9 +554,9 @@ static const struct luaL_Reg loaderlib[] = { REG_SIMPLE(interpret), REG_SIMPLE(parse), REG_SIMPLE(getenv), + REG_SIMPLE(has_command), REG_SIMPLE(perform), - /* Also registered as the global 'printc' */ - REG_SIMPLE(printc), + REG_SIMPLE(printc), /* Also registered as the global 'printc' */ REG_SIMPLE(setenv), REG_SIMPLE(time), REG_SIMPLE(unsetenv),