lualoader: Print error messages from command failures at the prompt

Previously lualoader would remain silent, rather than printing
command_errmsg or noting that a command had failed or was not found.

Approved by:	re (gjb)
This commit is contained in:
Kyle Evans 2018-08-31 15:02:53 +00:00
parent 505e91f500
commit 2ac6dfb0c2
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=338407

View File

@ -135,7 +135,7 @@ interp_run(const char *line)
char **argv;
lua_State *luap;
struct interp_lua_softc *softc = &lua_softc;
int status;
int status, ret;
luap = softc->luap;
LDBG("executing line...");
@ -147,14 +147,16 @@ interp_run(const char *line)
* run it through cli_execute. If that fails, then we'll try it
* as a builtin.
*/
command_errmsg = NULL;
if (parse(&argc, &argv, line) == 0) {
lua_getglobal(luap, "cli_execute");
for (nargc = 0; nargc < argc; ++nargc) {
lua_pushstring(luap, argv[nargc]);
}
status = lua_pcall(luap, argc, 1, 0);
ret = lua_tointeger(luap, 1);
lua_pop(luap, 1);
if (status != 0) {
if (status != 0 || ret != 0) {
/*
* Lua cli_execute will pass the function back
* through loader.command, which is a proxy to
@ -166,7 +168,10 @@ interp_run(const char *line)
status = interp_builtin_cmd(argc, argv);
}
if (status != 0) {
printf("Command failed\n");
if (command_errmsg != NULL)
printf("%s\n", command_errmsg);
else
printf("Command failed\n");
status = CMD_ERROR;
}
free(argv);