2
2
mirror of https://github.com/Hilbis/Hilbish synced 2025-07-01 16:52:03 +00:00

feat: add hilbish.completion (enough to init nature)

This commit is contained in:
sammyette 2025-06-14 13:26:41 -04:00
parent 417ccf7ca8
commit 3e85e1bf68
Signed by: sammyette
GPG Key ID: 904FC49417B44DCD
4 changed files with 47 additions and 44 deletions

6
api.go
View File

@ -106,10 +106,10 @@ func hilbishLoader(mlr *moonlight.Runtime) moonlight.Value {
//mod.Set(rt.StringValue("history"), rt.TableValue(historyModule)) //mod.Set(rt.StringValue("history"), rt.TableValue(historyModule))
// hilbish.completion table // hilbish.completion table
//hshcomp := completionLoader(rtm) hshcomp := completionLoader(mlr)
// TODO: REMOVE "completion" AND ONLY USE "completions" WITH AN S // TODO: REMOVE "completion" AND ONLY USE "completions" WITH AN S
//mod.Set(rt.StringValue("completion"), rt.TableValue(hshcomp)) hshMod.SetField("completion", moonlight.TableValue(hshcomp))
//mod.Set(rt.StringValue("completions"), rt.TableValue(hshcomp)) hshMod.SetField("completions", moonlight.TableValue(hshcomp))
// hilbish.runner table // hilbish.runner table
//runnerModule := runnerModeLoader(mlr) //runnerModule := runnerModeLoader(mlr)

View File

@ -2,13 +2,12 @@ package main
import ( import (
//"errors" //"errors"
"os"
"path/filepath" "path/filepath"
"strings" "strings"
"os"
"hilbish/moonlight"
"hilbish/util" "hilbish/util"
//rt "github.com/arnodel/golua/runtime"
) )
var charEscapeMap = []string{ var charEscapeMap = []string{
@ -191,21 +190,19 @@ func escapeFilename(fname string) string {
// #interface completion // #interface completion
// tab completions // tab completions
// The completions interface deals with tab completions. // The completions interface deals with tab completions.
/* func completionLoader(mlr *moonlight.Runtime) *moonlight.Table {
func completionLoader(rtm *rt.Runtime) *rt.Table { exports := map[string]moonlight.Export{
exports := map[string]util.LuaExport{
"bins": {hcmpBins, 3, false}, "bins": {hcmpBins, 3, false},
"call": {hcmpCall, 4, false}, //"call": {hcmpCall, 4, false},
"files": {hcmpFiles, 3, false}, // "files": {hcmpFiles, 3, false},
"handler": {hcmpHandler, 2, false}, // "handler": {hcmpHandler, 2, false},
} }
mod := rt.NewTable() mod := moonlight.NewTable()
util.SetExports(rtm, mod, exports) mlr.SetExports(mod, exports)
return mod return mod
} }
*/
// #interface completion // #interface completion
// bins(query, ctx, fields) -> entries (table), prefix (string) // bins(query, ctx, fields) -> entries (table), prefix (string)
@ -233,23 +230,23 @@ hilbish.complete('command.sudo', function(query, ctx, fields)
end) end)
#example #example
*/ */
/* func hcmpBins(mlr *moonlight.Runtime) error {
func hcmpBins(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) { query, ctx, fds, err := getCompleteParams(mlr)
query, ctx, fds, err := getCompleteParams(t, c)
if err != nil { if err != nil {
return nil, err return err
} }
completions, pfx := binaryComplete(query, ctx, fds) completions, _ := binaryComplete(query, ctx, fds)
luaComps := rt.NewTable() luaComps := moonlight.NewTable()
for i, comp := range completions { for i, comp := range completions {
luaComps.Set(rt.IntValue(int64(i + 1)), rt.StringValue(comp)) luaComps.Set(moonlight.IntValue(int64(i+1)), moonlight.StringValue(comp))
} }
return c.PushingNext(t.Runtime, rt.TableValue(luaComps), rt.StringValue(pfx)), nil mlr.PushNext1(moonlight.TableValue(luaComps))
//return c.PushingNext(t.Runtime, rt.TableValue(luaComps), rt.StringValue(pfx)), nil
return nil
} }
*/
// #interface completion // #interface completion
// call(name, query, ctx, fields) -> completionGroups (table), prefix (string) // call(name, query, ctx, fields) -> completionGroups (table), prefix (string)
@ -352,35 +349,33 @@ function hilbish.completion.handler(line, pos)
end end
#example #example
*/ */
/* func hcmpHandler(mlr *moonlight.Runtime) error {
func hcmpHandler(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) { return nil
return c.Next(), nil
} }
func getCompleteParams(t *rt.Thread, c *rt.GoCont) (string, string, []string, error) { func getCompleteParams(mlr *moonlight.Runtime) (string, string, []string, error) {
if err := c.CheckNArgs(3); err != nil { if err := mlr.CheckNArgs(3); err != nil {
return "", "", []string{}, err return "", "", []string{}, err
} }
query, err := c.StringArg(0) query, err := mlr.StringArg(0)
if err != nil { if err != nil {
return "", "", []string{}, err return "", "", []string{}, err
} }
ctx, err := c.StringArg(1) ctx, err := mlr.StringArg(1)
if err != nil { if err != nil {
return "", "", []string{}, err return "", "", []string{}, err
} }
fields, err := c.TableArg(2) fields, err := mlr.TableArg(2)
if err != nil { if err != nil {
return "", "", []string{}, err return "", "", []string{}, err
} }
var fds []string var fds []string
util.ForEach(fields, func(k rt.Value, v rt.Value) { moonlight.ForEach(fields, func(k moonlight.Value, v moonlight.Value) {
if v.Type() == rt.StringType { if v.Type() == moonlight.StringType {
fds = append(fds, v.AsString()) fds = append(fds, v.AsString())
} }
}) })
return query, ctx, fds, err return query, ctx, fds, err
} }
*/

View File

@ -3,6 +3,7 @@
package moonlight package moonlight
import ( import (
"errors"
"fmt" "fmt"
"github.com/aarzilli/golua/lua" "github.com/aarzilli/golua/lua"
@ -36,6 +37,11 @@ func (mlr *Runtime) StringArg(num int) (string, error) {
return mlr.state.CheckString(num + 1), nil return mlr.state.CheckString(num + 1), nil
} }
func (mlr *Runtime) TableArg(num int) (*Table, error) {
//return mlr.state.CheckType(num+1, lua.LUA_TTABLE)
return nil, errors.New("TableArg unimplemented")
}
func (mlr *Runtime) Arg(c *GoCont, num int) Value { func (mlr *Runtime) Arg(c *GoCont, num int) Value {
return c.vals[num] return c.vals[num]
} }

View File

@ -18,6 +18,8 @@ if not hilbish.midnightEdition then
-- it didnt work normally, idk -- it didnt work normally, idk
return function() return hilbish.module.load(path) end, path return function() return hilbish.module.load(path) end, path
end) end)
else
pcall = unsafe_pcall
end end
require 'nature.commands' require 'nature.commands'