diff --git a/api.go b/api.go index 11c264d2..f3bd14d2 100644 --- a/api.go +++ b/api.go @@ -299,10 +299,11 @@ func hlrun(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) { // cwd() -> string // Returns the current directory of the shell. // #returns string -func hlcwd(mlr *moonlight.Runtime, c *moonlight.GoCont) (moonlight.Cont, error) { +func hlcwd(mlr *moonlight.Runtime) error { cwd, _ := os.Getwd() - return mlr.PushNext1(c, moonlight.StringValue(cwd)), nil + mlr.PushNext1(moonlight.StringValue(cwd)) + return nil } // read(prompt) -> input (string) diff --git a/golibs/commander/commander.go b/golibs/commander/commander.go index 520396ac..e75ccaa1 100644 --- a/golibs/commander/commander.go +++ b/golibs/commander/commander.go @@ -117,7 +117,7 @@ func (c *Commander) cderegister(mlr *moonlight.Runtime) error { // Returns all registered commanders. Returns a list of tables with the following keys: // - `exec`: The function used to run the commander. Commanders require args and sinks to be passed. // #returns table -func (c *Commander) cregistry(mlr *moonlight.Runtime, ct *moonlight.GoCont) (moonlight.Cont, error) { +/*func (c *Commander) cregistry(mlr *moonlight.Runtime, ct *moonlight.GoCont) (moonlight.Cont, error) { registryLua := moonlight.NewTable() for cmdName, cmd := range c.Commands { cmdTbl := moonlight.NewTable() @@ -129,4 +129,4 @@ func (c *Commander) cregistry(mlr *moonlight.Runtime, ct *moonlight.GoCont) (moo } return mlr.PushNext1(ct, moonlight.TableValue(registryLua)), nil -} +}*/ diff --git a/golibs/fs/fs.go b/golibs/fs/fs.go index b5b8ab6e..10d943a4 100644 --- a/golibs/fs/fs.go +++ b/golibs/fs/fs.go @@ -39,14 +39,14 @@ func (f *fs) Loader(rtm *moonlight.Runtime) moonlight.Value { "cd": util.LuaExport{f.fcd, 1, false}, "mkdir": util.LuaExport{f.fmkdir, 2, false}, "stat": util.LuaExport{f.fstat, 1, false}, - "readdir": {f.freaddir, 1, false}, "abs": util.LuaExport{f.fabs, 1, false}, "basename": util.LuaExport{f.fbasename, 1, false}, - "dir": {f.fdir, 1, false}, "glob": util.LuaExport{f.fglob, 1, false}, "join": util.LuaExport{f.fjoin, 0, true}, "pipe": util.LuaExport{f.fpipe, 0, false}, */ + "readdir": {f.freaddir, 1, false}, + "dir": {f.fdir, 1, false}, } mod := moonlight.NewTable() @@ -122,8 +122,7 @@ func (f *fs) fcd(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) { // `~/Documents/doc.txt` then this function will return `~/Documents`. // #param path string Path to get the directory for. // #returns string -/* -func (f *fs) fdir(mlr *moonlight.Runtime, c *moonlight.GoCont) error { +func (f *fs) fdir(mlr *moonlight.Runtime) error { if err := mlr.Check1Arg(); err != nil { return err } @@ -132,11 +131,9 @@ func (f *fs) fdir(mlr *moonlight.Runtime, c *moonlight.GoCont) error { return err } - println(patg) - //next := mlr.PushNext1(c, moonlight.StringValue(filepath.Dir(path))) + mlr.PushNext1(moonlight.StringValue(filepath.Dir(path))) return nil } -*/ // glob(pattern) -> matches (table) // Match all files based on the provided `pattern`. @@ -265,26 +262,27 @@ func (f *fs) fpipe(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) { // Returns a list of all files and directories in the provided path. // #param dir string // #returns table -func (f *fs) freaddir(mlr *moonlight.Runtime, c *moonlight.GoCont) (moonlight.Cont, error) { +func (f *fs) freaddir(mlr *moonlight.Runtime) error { if err := mlr.Check1Arg(); err != nil { - return nil, err + return err } dir, err := mlr.StringArg(0) if err != nil { - return nil, err + return err } dir = util.ExpandHome(dir) names := moonlight.NewTable() dirEntries, err := os.ReadDir(dir) if err != nil { - return nil, err + return err } for i, entry := range dirEntries { names.Set(moonlight.IntValue(int64(i+1)), moonlight.StringValue(entry.Name())) } - return mlr.PushNext1(c, moonlight.TableValue(names)), nil + mlr.PushNext1(moonlight.TableValue(names)) + return nil } // stat(path) -> {} diff --git a/golibs/terminal/terminal.go b/golibs/terminal/terminal.go index 95cafdb5..8e9f7cd7 100644 --- a/golibs/terminal/terminal.go +++ b/golibs/terminal/terminal.go @@ -3,8 +3,6 @@ package terminal import ( - "os" - "hilbish/moonlight" "golang.org/x/term" @@ -28,6 +26,7 @@ func Loader(rtm *moonlight.Runtime) moonlight.Value { return moonlight.TableValue(mod) } +/* // size() // Gets the dimensions of the terminal. Returns a table with `width` and `height` // NOTE: The size refers to the amount of columns and rows of text that can fit in the terminal. @@ -77,3 +76,4 @@ func termsetRaw(mlr *moonlight.Runtime, c *moonlight.GoCont) (moonlight.Cont, er return c.Next(), nil } +*/ diff --git a/moonlight/function_clua.go b/moonlight/function_clua.go index 5d70f025..84cfeffa 100644 --- a/moonlight/function_clua.go +++ b/moonlight/function_clua.go @@ -41,6 +41,8 @@ func (mlr *Runtime) Arg(c *GoCont, num int) Value { } func (mlr *Runtime) GoFunction(fun GoToLuaFunc) *GoFunctionFunc { + mlr.returnNum = 0 + return &GoFunctionFunc{ cf: func(L *lua.State) int { err := fun(mlr) @@ -57,7 +59,7 @@ func (mlr *Runtime) GoFunction(fun GoToLuaFunc) *GoFunctionFunc { }*/ //return len(cont.(*GoCont).vals) - return 0 + return mlr.returnNum }, } } diff --git a/moonlight/runtime_clua.go b/moonlight/runtime_clua.go index f1fc1c8c..5e114da5 100644 --- a/moonlight/runtime_clua.go +++ b/moonlight/runtime_clua.go @@ -7,7 +7,8 @@ import ( ) type Runtime struct { - state *lua.State + state *lua.State + returnNum int } func NewRuntime() *Runtime { @@ -19,10 +20,10 @@ func NewRuntime() *Runtime { } } -func (mlr *Runtime) PushNext1(c *GoCont, v Value) Cont { - c.vals = []Value{v} +func (mlr *Runtime) PushNext1(v Value) { + mlr.returnNum = 1 - return c + mlr.pushToState(v) } func (mlr *Runtime) Call1(f Value, args ...Value) (Value, error) { diff --git a/moonlight/runtime_golua.go b/moonlight/runtime_golua.go index 57c90d00..96ba4c6c 100644 --- a/moonlight/runtime_golua.go +++ b/moonlight/runtime_golua.go @@ -1,15 +1,16 @@ //go:build !midnight + package moonlight import ( "os" - rt "github.com/arnodel/golua/runtime" "github.com/arnodel/golua/lib" "github.com/arnodel/golua/lib/debuglib" + rt "github.com/arnodel/golua/runtime" ) -type Runtime struct{ +type Runtime struct { rt *rt.Runtime } @@ -40,8 +41,8 @@ func (mlr *Runtime) Push(c *GoCont, v Value) { c.cont.Push(c.thread.Runtime, v) } -func (mlr *Runtime) PushNext1(c *GoCont, v Value) Cont { - return c.cont.PushingNext1(c.thread.Runtime, v) +func (mlr *Runtime) PushNext1(v Value) { + mlr.rt.MainThread().CurrentCont().(*rt.GoCont).Next().Push(mlr.rt.MainThread().Runtime, v) } func (mlr *Runtime) Call1(val Value, args ...Value) (Value, error) { diff --git a/nature/commands/init.lua b/nature/commands/init.lua index 93113cd7..824adf41 100644 --- a/nature/commands/init.lua +++ b/nature/commands/init.lua @@ -6,7 +6,8 @@ local fs = require 'fs' -- we will use that to automatically load all commands by reading -- all the files in this dir and just requiring it. local info = debug.getinfo(1) -local commandDir = fs.dir(info.source) +local commandDir = fs.dir(info.source:match './.+') +print(commandDir) if commandDir == '.' then return end local commands = fs.readdir(commandDir) diff --git a/nature/init.lua b/nature/init.lua index 9bfc4ac8..6b696cfd 100644 --- a/nature/init.lua +++ b/nature/init.lua @@ -1,9 +1,4 @@ -- Prelude initializes everything else for our shell -print(require 'hilbish') -print('hilbitch type', type(hilbish)) -print(hilbish.prompt) -print(hilbish.ver) ---[[ local _ = require 'succulent' -- Function additions local bait = require 'bait' --local fs = require 'fs' @@ -97,4 +92,3 @@ end) bait.catch('command.not-executable', function(cmd) print(string.format('hilbish: %s: not executable', cmd)) end) -]]--