From 3b6284bc7cc83f69420992e844efe2192277368b Mon Sep 17 00:00:00 2001 From: TorchedSammy <38820196+TorchedSammy@users.noreply.github.com> Date: Tue, 1 Mar 2022 18:59:44 -0400 Subject: [PATCH] feat: add hilbish.which (closes #93) --- api.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/api.go b/api.go index 00304e8..2aaa8f1 100644 --- a/api.go +++ b/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 +}