mirror of
https://github.com/Hilbis/Hilbish
synced 2025-04-02 03:33: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,
|
"read": hlread,
|
||||||
"run": hlrun,
|
"run": hlrun,
|
||||||
"timeout": hltimeout,
|
"timeout": hltimeout,
|
||||||
|
"which": hlwhich,
|
||||||
}
|
}
|
||||||
|
|
||||||
var greeting string
|
var greeting string
|
||||||
@ -331,3 +332,17 @@ func hlprependPath(L *lua.LState) int {
|
|||||||
|
|
||||||
return 0
|
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