mirror of
https://github.com/Hilbis/Hilbish
synced 2025-07-01 16:52:03 +00:00
feat: add hilbish.runner and hilbish.appendPath
This commit is contained in:
parent
3e85e1bf68
commit
19938fa8ef
32
api.go
32
api.go
@ -44,7 +44,6 @@ func hilbishLoader(mlr *moonlight.Runtime) moonlight.Value {
|
|||||||
var exports = map[string]moonlight.Export{
|
var exports = map[string]moonlight.Export{
|
||||||
/*
|
/*
|
||||||
"alias": {hlalias, 2, false},
|
"alias": {hlalias, 2, false},
|
||||||
"appendPath": {hlappendPath, 1, false},
|
|
||||||
"complete": {hlcomplete, 2, false},
|
"complete": {hlcomplete, 2, false},
|
||||||
"exec": {hlexec, 1, false},
|
"exec": {hlexec, 1, false},
|
||||||
"runnerMode": {hlrunnerMode, 1, false},
|
"runnerMode": {hlrunnerMode, 1, false},
|
||||||
@ -54,8 +53,9 @@ func hilbishLoader(mlr *moonlight.Runtime) moonlight.Value {
|
|||||||
"multiprompt": {hlmultiprompt, 1, false},
|
"multiprompt": {hlmultiprompt, 1, false},
|
||||||
"prependPath": {hlprependPath, 1, false},
|
"prependPath": {hlprependPath, 1, false},
|
||||||
*/
|
*/
|
||||||
"cwd": {hlcwd, 0, false},
|
"appendPath": {hlappendPath, 1, false},
|
||||||
"prompt": {hlprompt, 1, true},
|
"cwd": {hlcwd, 0, false},
|
||||||
|
"prompt": {hlprompt, 1, true},
|
||||||
/*
|
/*
|
||||||
"inputMode": {hlinputMode, 1, false},
|
"inputMode": {hlinputMode, 1, false},
|
||||||
"interval": {hlinterval, 2, false},
|
"interval": {hlinterval, 2, false},
|
||||||
@ -112,8 +112,8 @@ func hilbishLoader(mlr *moonlight.Runtime) moonlight.Value {
|
|||||||
hshMod.SetField("completions", moonlight.TableValue(hshcomp))
|
hshMod.SetField("completions", moonlight.TableValue(hshcomp))
|
||||||
|
|
||||||
// hilbish.runner table
|
// hilbish.runner table
|
||||||
//runnerModule := runnerModeLoader(mlr)
|
runnerModule := runnerModeLoader(mlr)
|
||||||
//hshMod.SetField("runner", moonlight.TableValue(runnerModule))
|
hshMod.SetField("runner", moonlight.TableValue(runnerModule))
|
||||||
|
|
||||||
// hilbish.jobs table
|
// hilbish.jobs table
|
||||||
jobs = newJobHandler()
|
jobs = newJobHandler()
|
||||||
@ -475,11 +475,11 @@ hilbish.appendPath {
|
|||||||
}
|
}
|
||||||
#example
|
#example
|
||||||
*/
|
*/
|
||||||
func hlappendPath(mlr *moonlight.Runtime, c *moonlight.GoCont) (moonlight.Cont, error) {
|
func hlappendPath(mlr *moonlight.Runtime) error {
|
||||||
if err := mlr.Check1Arg(); err != nil {
|
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
|
// check if dir is a table or a string
|
||||||
if moonlight.Type(arg) == moonlight.TableType {
|
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 {
|
} else if moonlight.Type(arg) == moonlight.StringType {
|
||||||
appendPath(arg.AsString())
|
appendPath(arg.AsString())
|
||||||
} else {
|
} 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) {
|
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.
|
// will call it to execute user input instead.
|
||||||
// Read [about runner mode](../features/runner-mode) for more information.
|
// Read [about runner mode](../features/runner-mode) for more information.
|
||||||
// #param mode string|function
|
// #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 {
|
if err := mlr.Check1Arg(); err != nil {
|
||||||
return nil, err
|
return err
|
||||||
}
|
}
|
||||||
mode := mlr.Arg(c, 0)
|
mode := mlr.Arg(0)
|
||||||
|
|
||||||
switch moonlight.Type(mode) {
|
switch moonlight.Type(mode) {
|
||||||
case moonlight.StringType:
|
case moonlight.StringType:
|
||||||
@ -782,15 +782,15 @@ func hlrunnerMode(mlr *moonlight.Runtime, c *moonlight.GoCont) (moonlight.Cont,
|
|||||||
case "hybrid", "hybridRev", "lua", "sh":
|
case "hybrid", "hybridRev", "lua", "sh":
|
||||||
runnerMode = mode
|
runnerMode = mode
|
||||||
default:
|
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:
|
case moonlight.FunctionType:
|
||||||
runnerMode = mode
|
runnerMode = mode
|
||||||
default:
|
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)
|
// hinter(line, pos)
|
||||||
|
@ -42,8 +42,8 @@ func (mlr *Runtime) TableArg(num int) (*Table, error) {
|
|||||||
return nil, errors.New("TableArg unimplemented")
|
return nil, errors.New("TableArg unimplemented")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (mlr *Runtime) Arg(c *GoCont, num int) Value {
|
func (mlr *Runtime) Arg(num int) Value {
|
||||||
return c.vals[num]
|
return NilValue
|
||||||
}
|
}
|
||||||
|
|
||||||
func (mlr *Runtime) GoFunction(fun GoToLuaFunc) *GoFunctionFunc {
|
func (mlr *Runtime) GoFunction(fun GoToLuaFunc) *GoFunctionFunc {
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
|
import "hilbish/moonlight"
|
||||||
|
|
||||||
// #interface runner
|
// #interface runner
|
||||||
// interactive command runner customization
|
// interactive command runner customization
|
||||||
/* The runner interface contains functions that allow the user to change
|
/* The runner interface contains functions that allow the user to change
|
||||||
@ -42,10 +44,11 @@ hilbish.runnerMode(function(input)
|
|||||||
return hilbish.runner.sh(input)
|
return hilbish.runner.sh(input)
|
||||||
end)
|
end)
|
||||||
```
|
```
|
||||||
|
*/
|
||||||
func runnerModeLoader(rtm *moonlight.Runtime) *moonlight.Table {
|
func runnerModeLoader(rtm *moonlight.Runtime) *moonlight.Table {
|
||||||
exports := map[string]moonlight.Export{
|
exports := map[string]moonlight.Export{
|
||||||
"sh": {shRunner, 1, false},
|
"sh": {shRunner, 1, false},
|
||||||
"lua": {luaRunner, 1, false},
|
"lua": {luaRunner, 1, false},
|
||||||
"setMode": {hlrunnerMode, 1, false},
|
"setMode": {hlrunnerMode, 1, false},
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -69,13 +72,13 @@ func _runnerMode() {}
|
|||||||
// Runs a command in Hilbish's shell script interpreter.
|
// Runs a command in Hilbish's shell script interpreter.
|
||||||
// This is the equivalent of using `source`.
|
// This is the equivalent of using `source`.
|
||||||
// #param cmd string
|
// #param cmd string
|
||||||
func shRunner(mlr *moonlight.Runtime, c *moonlight.GoCont) (moonlight.Cont, error) {
|
func shRunner(mlr *moonlight.Runtime) error {
|
||||||
if err := mlr.Check1Arg(c); err != nil {
|
if err := mlr.Check1Arg(); err != nil {
|
||||||
return nil, err
|
return err
|
||||||
}
|
}
|
||||||
cmd, err := mlr.StringArg(c, 0)
|
cmd, err := mlr.StringArg(0)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
_, exitCode, cont, err := execSh(aliases.Resolve(cmd))
|
_, 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("continue", moonlight.BoolValue(cont))
|
||||||
runnerRet.SetField("err", luaErr)
|
runnerRet.SetField("err", luaErr)
|
||||||
|
|
||||||
return mlr.PushNext1(c, moonlight.TableValue(runnerRet)), nil
|
mlr.PushNext1(moonlight.TableValue(runnerRet))
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// #interface runner
|
// #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`
|
// Evaluates `cmd` as Lua input. This is the same as using `dofile`
|
||||||
// or `load`, but is appropriated for the runner interface.
|
// or `load`, but is appropriated for the runner interface.
|
||||||
// #param cmd string
|
// #param cmd string
|
||||||
func luaRunner(mlr *moonlight.Runtime, c *moonlight.GoCont) (moonlight.Cont, error) {
|
func luaRunner(mlr *moonlight.Runtime) error {
|
||||||
if err := mlr.Check1Arg(c); err != nil {
|
if err := mlr.Check1Arg(); err != nil {
|
||||||
return nil, err
|
return err
|
||||||
}
|
}
|
||||||
cmd, err := mlr.StringArg(c, 0)
|
cmd, err := mlr.StringArg(0)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
input, exitCode, err := handleLua(cmd)
|
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("exitCode", moonlight.IntValue(int64(exitCode)))
|
||||||
runnerRet.SetField("err", luaErr)
|
runnerRet.SetField("err", luaErr)
|
||||||
|
|
||||||
|
mlr.PushNext1(moonlight.TableValue(runnerRet))
|
||||||
return mlr.PushNext1(c, moonlight.TableValue(runnerRet)), nil
|
return nil
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user