From 0ddfc5bea052f12a7ac6cce532484a278a1731df Mon Sep 17 00:00:00 2001 From: sammy <38820196+TorchedSammy@users.noreply.github.com> Date: Tue, 11 May 2021 18:53:24 -0400 Subject: [PATCH] feat: allow command defined by commander to return exit code --- shell.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/shell.go b/shell.go index d9b6c05..3ae8349 100644 --- a/shell.go +++ b/shell.go @@ -52,9 +52,17 @@ func RunInput(input string) { l.GetGlobal("commanding"), lua.LString("__commands")), cmdArgs[0]), - NRet: 0, + NRet: 1, Protect: true, }, luar.New(l, cmdArgs[1:])) + luaexitcode := l.Get(-1) + exitcode := lua.LNumber(0) + + l.Pop(1) + + if luaexitcode != lua.LNil { + exitcode = luaexitcode.(lua.LNumber) + } if err != nil { fmt.Fprintln(os.Stderr, "Error in command:\n\n" + err.Error()) @@ -62,6 +70,7 @@ func RunInput(input string) { if cmdArgs[0] != "exit" { HandleHistory(cmdString) } + hooks.Em.Emit("command.exit", exitcode) return }