The “runner mode” of Hilbish is customizable via hilbish.runnerMode, which determines how Hilbish will run user input. By default, this is set to hybrid which is the previously mentioned behaviour of running Lua first then going to shell script." property="og:description"><metacontent="Hilbishisunique,wheninteractiveitfirstattemptstoruninputasLuaandthentriesshellscript.Butifyou’renormal,youwouldn’treallybeusingHilbishanywaybutyou’dalsonotwantthis(ormaybewantLuaonlyinsomecases.)
<emclass=text-muted>by <strong>sammyette</strong></em><divclass=my-4><p>Hilbish is <em>unique,</em> when interactive it first attempts to run input as
Lua and then tries shell script. But if you’re normal, you wouldn’t
really be using Hilbish anyway but you’d also not want this
(or maybe want Lua only in some cases.)</p><p>The “runner mode” of Hilbish is customizable via <code>hilbish.runnerMode</code>,
which determines how Hilbish will run user input. By default, this is
set to <code>hybrid</code> which is the previously mentioned behaviour of running Lua
first then going to shell script. If you want the reverse order, you can
set it to <code>hybridRev</code> and for isolated modes there is <code>sh</code> and <code>lua</code>
respectively.</p><p>You can also set it to a function, which will be called everytime Hilbish
needs to run interactive input. For example, you can set this to a simple
function to compile and evaluate Fennel, and now you can run Fennel.
You can even mix it with sh to make a hybrid mode with Lua replaced by
Fennel.</p><p>An example:
hilbish.runnerMode(function(input)
local ok = pcall(fennel.eval, input)
if ok then
return input, 0, nil
end</p><pre><code>return hilbish.runner.sh(input)
</code></pre><p>end)</p><p>The <code>hilbish.runner</code> interface is an alternative to using <code>hilbish.runnerMode</code>
and also provides the sh and Lua runner functions that Hilbish itself uses.
A runner function is expected to return 3 values: the input, exit code, and an error.
The input return is there incase you need to prompt for more input.
If you don’t, just return the input passed to the runner function.
The exit code has to be a number, it will be 0 otherwise and the error can be
<code>nil</code> to indicate no error.</p><h3id=functionsclass=heading>Functions
<ahref=#functionsclass=heading-link><iclass="fas fa-paperclip"></i></a></h3><p>These are the “low level” functions for the <code>hilbish.runner</code> interface.</p><ul><li>setMode(mode) > The same as <code>hilbish.runnerMode</code></li><li>sh(input) -> table > Runs <code>input</code> in Hilbish’s sh interpreter</li><li>lua(input) -> table > Evals <code>input</code> as Lua code</li></ul><p>The table value that runners return can have at least 4 values:</p><ul><li><p>input (string): The full input text.</p></li><li><p>exitCode (number): Exit code (usually from a command)</p></li><li><p>continue (boolean): Whether to prompt the user for more input
(in the case of incomplete syntax)</p></li><li><p>err (string): A string that represents an error from the runner.
This should only be set when, for example, there is a syntax error.
It can be set to a few special values for Hilbish to throw the right
hooks and have a better looking message.</p></li><li><p><code><command>: not-found</code> will throw a <code>command.not-found</code> hook
based on what <code><command></code> is.</p></li><li><p><code><command>: not-executable</code> will throw a <code>command.not-executable</code> hook.</p></li></ul><p>The others here are defined in Lua and have EmmyLua documentation.
These functions should be preferred over the previous ones.</p><ul><li>setCurrent(mode) > The same as <code>setMode</code>, but works with runners managed
via the functions below.</li><li>add(name, runner) > Adds a runner to a table of available runners. The <code>runner</code>
argument is either a function or a table with a run callback.</li><li>set(name, runner) > The same as <code>add</code> but requires passing a table and
overwrites if the <code>name</code>d runner already exists.</li><li>get(name) > runner > Gets a runner by name. It is a table with at least a
run function, to run input.</li><li>exec(cmd, runnerName) > Runs <code>cmd</code> with a runner. If <code>runnerName</code> isn’t passed,