2
2
mirror of https://github.com/Hilbis/Hilbish synced 2025-07-01 08:42:04 +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))
// hilbish.completion table
//hshcomp := completionLoader(rtm)
hshcomp := completionLoader(mlr)
// TODO: REMOVE "completion" AND ONLY USE "completions" WITH AN S
//mod.Set(rt.StringValue("completion"), rt.TableValue(hshcomp))
//mod.Set(rt.StringValue("completions"), rt.TableValue(hshcomp))
hshMod.SetField("completion", moonlight.TableValue(hshcomp))
hshMod.SetField("completions", moonlight.TableValue(hshcomp))
// hilbish.runner table
//runnerModule := runnerModeLoader(mlr)

View File

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

View File

@ -3,6 +3,7 @@
package moonlight
import (
"errors"
"fmt"
"github.com/aarzilli/golua/lua"
@ -36,6 +37,11 @@ func (mlr *Runtime) StringArg(num int) (string, error) {
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 {
return c.vals[num]
}

View File

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