1
0
mirror of https://git.FreeBSD.org/src.git synced 2024-11-29 08:08:37 +00:00

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
This commit is contained in:
Warner Losh 2022-09-01 11:06:19 -06:00
parent a5948d40ad
commit 29fc4075e6

View File

@ -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),