feat: add hilbish.which (closes #93)

windows-fixes
TorchedSammy 2022-03-01 18:59:44 -04:00
parent 52379dbdd7
commit 3b6284bc7c
Signed by: sammyette
GPG Key ID: 904FC49417B44DCD
1 changed files with 15 additions and 0 deletions

15
api.go
View File

@ -30,6 +30,7 @@ var exports = map[string]lua.LGFunction {
"read": hlread,
"run": hlrun,
"timeout": hltimeout,
"which": hlwhich,
}
var greeting string
@ -331,3 +332,17 @@ func hlprependPath(L *lua.LState) int {
return 0
}
// which(binName)
// Searches for an executable called `binName` in the directories of $PATH
func hlwhich(L *lua.LState) int {
binName := L.CheckString(1)
path, err := exec.LookPath(binName)
if err != nil {
l.Push(lua.LNil)
return 1
}
l.Push(path)
return 1
}