feat: allow command defined by commander to return exit code

pull/59/head
sammy 2021-05-11 18:53:24 -04:00
parent cc995e0f34
commit 0ddfc5bea0
No known key found for this signature in database
GPG Key ID: 50EE40A2809851F5
1 changed files with 10 additions and 1 deletions

View File

@ -52,9 +52,17 @@ func RunInput(input string) {
l.GetGlobal("commanding"), l.GetGlobal("commanding"),
lua.LString("__commands")), lua.LString("__commands")),
cmdArgs[0]), cmdArgs[0]),
NRet: 0, NRet: 1,
Protect: true, Protect: true,
}, luar.New(l, cmdArgs[1:])) }, 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 { if err != nil {
fmt.Fprintln(os.Stderr, fmt.Fprintln(os.Stderr,
"Error in command:\n\n" + err.Error()) "Error in command:\n\n" + err.Error())
@ -62,6 +70,7 @@ func RunInput(input string) {
if cmdArgs[0] != "exit" { if cmdArgs[0] != "exit" {
HandleHistory(cmdString) HandleHistory(cmdString)
} }
hooks.Em.Emit("command.exit", exitcode)
return return
} }