diff --git a/.hilbishrc.lua b/.hilbishrc.lua index 249f97e..28252b8 100644 --- a/.hilbishrc.lua +++ b/.hilbishrc.lua @@ -47,3 +47,9 @@ end) bait.catch('hilbish.notification', function(notif) doNotifyPrompt() end) + +local ops = require 'nature.oxalis.operators' +getmetatable('').__bor = function(l, r) + return ops.pipe(l, r) +end +hilbish.runner.setCurrent 'lua' diff --git a/exec.go b/exec.go index cf1b299..6f66239 100644 --- a/exec.go +++ b/exec.go @@ -207,7 +207,7 @@ func runLuaRunner(runr rt.Value, userInput string) (input string, exitCode uint8 func handleLua(input string) (string, uint8, error) { cmdString := aliases.Resolve(input) // First try to load input, essentially compiling to bytecode - chunk, err := l.CompileAndLoadLuaChunk("", []byte(cmdString), rt.TableValue(l.GlobalEnv())) + chunk, err := l.CompileAndLoadLuaChunkOrExp("", []byte(cmdString), rt.TableValue(l.GlobalEnv())) if err != nil && noexecute { fmt.Println(err) /* if lerr, ok := err.(*lua.ApiError); ok { @@ -221,7 +221,12 @@ func handleLua(input string) (string, uint8, error) { // And if there's no syntax errors and -n isnt provided, run if !noexecute { if chunk != nil { - _, err = rt.Call1(l.MainThread(), rt.FunctionValue(chunk)) + var ret rt.Value + ret, err = rt.Call1(l.MainThread(), rt.FunctionValue(chunk)) + retStr, good := ret.ToString() + if good { + fmt.Println(retStr) + } } } if err == nil { diff --git a/nature/oxalis/init.lua b/nature/oxalis/init.lua new file mode 100644 index 0000000..6f6969d --- /dev/null +++ b/nature/oxalis/init.lua @@ -0,0 +1,11 @@ +local M = {} + +function M.pipe(cmd, cmd2) + -- +end + +hilbish.runner.add('oxalis', { + run = function(input) + + end +}) diff --git a/nature/oxalis/operators.lua b/nature/oxalis/operators.lua new file mode 100644 index 0000000..237f700 --- /dev/null +++ b/nature/oxalis/operators.lua @@ -0,0 +1,17 @@ +local fs = require 'fs' +local M = {} + +function M.pipe(cmd, cmd2) + local pr, pw = fs.pipe() + hilbish.run(cmd, { + out = pw, + err = pw, + }) + pw:close() + hilbish.run(cmd2, { + input = pr + }) + return {command = cmd2, input = pr, out } +end + +return M