git: 29fc4075e69f - main - stand: Add lua binding loader.has_command
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Thu, 01 Sep 2022 17:11:21 UTC
The branch main has been updated by imp:
URL: https://cgit.FreeBSD.org/src/commit/?id=29fc4075e69fd27de0cded313ac6000165d99f8b
commit 29fc4075e69fd27de0cded313ac6000165d99f8b
Author: Warner Losh <imp@FreeBSD.org>
AuthorDate: 2022-09-01 17:06:19 +0000
Commit: Warner Losh <imp@FreeBSD.org>
CommitDate: 2022-09-01 17:08:22 +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
---
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),