mirror of https://github.com/Hilbis/Hilbish
feat: add hilbish.which (closes #93)
parent
52379dbdd7
commit
3b6284bc7c
15
api.go
15
api.go
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue