Compare commits

...

3 Commits

Author SHA1 Message Date
TorchedSammy 062f40e9e5
fix: push hilbish.which return value properly 2022-03-01 19:34:07 -04:00
TorchedSammy 44e2a458f5 docs: [ci] generate new docs 2022-03-01 23:00:20 +00:00
TorchedSammy 3b6284bc7c
feat: add hilbish.which (closes #93) 2022-03-01 18:59:44 -04:00
3 changed files with 20 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(lua.LString(path))
return 1
}

View File

@ -35,3 +35,5 @@ run(cmd) > Runs `cmd` in Hilbish's sh interpreter.
timeout(cb, time) > Runs the `cb` function after `time` in milliseconds
which(binName) > Searches for an executable called `binName` in the directories of $PATH

View File

@ -65,4 +65,7 @@ function hilbish.run(cmd) end
--- @param time number
function hilbish.timeout(cb, time) end
--- Searches for an executable called `binName` in the directories of $PATH
function hilbish.which() end
return hilbish