diff --git a/api.go b/api.go index 3800d150..823b2a32 100644 --- a/api.go +++ b/api.go @@ -44,7 +44,6 @@ func hilbishLoader(mlr *moonlight.Runtime) moonlight.Value { var exports = map[string]moonlight.Export{ /* "alias": {hlalias, 2, false}, - "appendPath": {hlappendPath, 1, false}, "complete": {hlcomplete, 2, false}, "exec": {hlexec, 1, false}, "runnerMode": {hlrunnerMode, 1, false}, @@ -54,8 +53,9 @@ func hilbishLoader(mlr *moonlight.Runtime) moonlight.Value { "multiprompt": {hlmultiprompt, 1, false}, "prependPath": {hlprependPath, 1, false}, */ - "cwd": {hlcwd, 0, false}, - "prompt": {hlprompt, 1, true}, + "appendPath": {hlappendPath, 1, false}, + "cwd": {hlcwd, 0, false}, + "prompt": {hlprompt, 1, true}, /* "inputMode": {hlinputMode, 1, false}, "interval": {hlinterval, 2, false}, @@ -112,8 +112,8 @@ func hilbishLoader(mlr *moonlight.Runtime) moonlight.Value { hshMod.SetField("completions", moonlight.TableValue(hshcomp)) // hilbish.runner table - //runnerModule := runnerModeLoader(mlr) - //hshMod.SetField("runner", moonlight.TableValue(runnerModule)) + runnerModule := runnerModeLoader(mlr) + hshMod.SetField("runner", moonlight.TableValue(runnerModule)) // hilbish.jobs table jobs = newJobHandler() @@ -475,11 +475,11 @@ hilbish.appendPath { } #example */ -func hlappendPath(mlr *moonlight.Runtime, c *moonlight.GoCont) (moonlight.Cont, error) { +func hlappendPath(mlr *moonlight.Runtime) error { if err := mlr.Check1Arg(); err != nil { - return nil, err + return err } - arg := mlr.Arg(c, 0) + arg := mlr.Arg(0) // check if dir is a table or a string if moonlight.Type(arg) == moonlight.TableType { @@ -491,10 +491,10 @@ func hlappendPath(mlr *moonlight.Runtime, c *moonlight.GoCont) (moonlight.Cont, } else if moonlight.Type(arg) == moonlight.StringType { appendPath(arg.AsString()) } else { - return nil, errors.New("bad argument to appendPath (expected string or table, got " + arg.TypeName() + ")") + return errors.New("bad argument to appendPath (expected string or table, got " + arg.TypeName() + ")") } - return c.Next(), nil + return nil } func appendPath(dir string) { @@ -770,11 +770,11 @@ func hlinputMode(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) { // will call it to execute user input instead. // Read [about runner mode](../features/runner-mode) for more information. // #param mode string|function -func hlrunnerMode(mlr *moonlight.Runtime, c *moonlight.GoCont) (moonlight.Cont, error) { +func hlrunnerMode(mlr *moonlight.Runtime) error { if err := mlr.Check1Arg(); err != nil { - return nil, err + return err } - mode := mlr.Arg(c, 0) + mode := mlr.Arg(0) switch moonlight.Type(mode) { case moonlight.StringType: @@ -782,15 +782,15 @@ func hlrunnerMode(mlr *moonlight.Runtime, c *moonlight.GoCont) (moonlight.Cont, case "hybrid", "hybridRev", "lua", "sh": runnerMode = mode default: - return nil, errors.New("execMode: expected either a function or hybrid, hybridRev, lua, sh. Received " + mode.AsString()) + return errors.New("execMode: expected either a function or hybrid, hybridRev, lua, sh. Received " + mode.AsString()) } case moonlight.FunctionType: runnerMode = mode default: - return nil, errors.New("execMode: expected either a function or hybrid, hybridRev, lua, sh. Received " + mode.TypeName()) + return errors.New("execMode: expected either a function or hybrid, hybridRev, lua, sh. Received " + mode.TypeName()) } - return c.Next(), nil + return nil } // hinter(line, pos) diff --git a/moonlight/function_clua.go b/moonlight/function_clua.go index 27b3ab61..5b5dc202 100644 --- a/moonlight/function_clua.go +++ b/moonlight/function_clua.go @@ -42,8 +42,8 @@ func (mlr *Runtime) TableArg(num int) (*Table, error) { return nil, errors.New("TableArg unimplemented") } -func (mlr *Runtime) Arg(c *GoCont, num int) Value { - return c.vals[num] +func (mlr *Runtime) Arg(num int) Value { + return NilValue } func (mlr *Runtime) GoFunction(fun GoToLuaFunc) *GoFunctionFunc { diff --git a/runnermode.go b/runnermode.go index 4da015b2..9dcd40d2 100644 --- a/runnermode.go +++ b/runnermode.go @@ -1,5 +1,7 @@ package main +import "hilbish/moonlight" + // #interface runner // interactive command runner customization /* The runner interface contains functions that allow the user to change @@ -42,10 +44,11 @@ hilbish.runnerMode(function(input) return hilbish.runner.sh(input) end) ``` +*/ func runnerModeLoader(rtm *moonlight.Runtime) *moonlight.Table { exports := map[string]moonlight.Export{ - "sh": {shRunner, 1, false}, - "lua": {luaRunner, 1, false}, + "sh": {shRunner, 1, false}, + "lua": {luaRunner, 1, false}, "setMode": {hlrunnerMode, 1, false}, } @@ -69,13 +72,13 @@ func _runnerMode() {} // Runs a command in Hilbish's shell script interpreter. // This is the equivalent of using `source`. // #param cmd string -func shRunner(mlr *moonlight.Runtime, c *moonlight.GoCont) (moonlight.Cont, error) { - if err := mlr.Check1Arg(c); err != nil { - return nil, err +func shRunner(mlr *moonlight.Runtime) error { + if err := mlr.Check1Arg(); err != nil { + return err } - cmd, err := mlr.StringArg(c, 0) + cmd, err := mlr.StringArg(0) if err != nil { - return nil, err + return err } _, exitCode, cont, err := execSh(aliases.Resolve(cmd)) @@ -89,7 +92,8 @@ func shRunner(mlr *moonlight.Runtime, c *moonlight.GoCont) (moonlight.Cont, erro runnerRet.SetField("continue", moonlight.BoolValue(cont)) runnerRet.SetField("err", luaErr) - return mlr.PushNext1(c, moonlight.TableValue(runnerRet)), nil + mlr.PushNext1(moonlight.TableValue(runnerRet)) + return nil } // #interface runner @@ -97,13 +101,13 @@ func shRunner(mlr *moonlight.Runtime, c *moonlight.GoCont) (moonlight.Cont, erro // Evaluates `cmd` as Lua input. This is the same as using `dofile` // or `load`, but is appropriated for the runner interface. // #param cmd string -func luaRunner(mlr *moonlight.Runtime, c *moonlight.GoCont) (moonlight.Cont, error) { - if err := mlr.Check1Arg(c); err != nil { - return nil, err +func luaRunner(mlr *moonlight.Runtime) error { + if err := mlr.Check1Arg(); err != nil { + return err } - cmd, err := mlr.StringArg(c, 0) + cmd, err := mlr.StringArg(0) if err != nil { - return nil, err + return err } input, exitCode, err := handleLua(cmd) @@ -116,7 +120,6 @@ func luaRunner(mlr *moonlight.Runtime, c *moonlight.GoCont) (moonlight.Cont, err runnerRet.SetField("exitCode", moonlight.IntValue(int64(exitCode))) runnerRet.SetField("err", luaErr) - - return mlr.PushNext1(c, moonlight.TableValue(runnerRet)), nil + mlr.PushNext1(moonlight.TableValue(runnerRet)) + return nil } -*/