mirror of
https://github.com/Hilbis/Hilbish
synced 2025-03-31 18:53:22 +00:00
feat: add hilbish.which (closes #93)
This commit is contained in:
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…
x
Reference in New Issue
Block a user