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

refactor: change go function types

this is the only way i could think of to be able
to push go functions to lua on the clua side.

this may or may not need adjustments on golua side
though...
This commit is contained in:
sammyette 2025-06-14 10:06:20 -04:00
parent 95391d74f6
commit 9e77f0ba32
Signed by: sammyette
GPG Key ID: 904FC49417B44DCD
20 changed files with 312 additions and 246 deletions

52
api.go
View File

@ -15,13 +15,16 @@ package main
import ( import (
"bytes" "bytes"
"errors" "errors"
//"fmt" //"fmt"
"io" "io"
"os" "os"
//"os/exec" //"os/exec"
"runtime" "runtime"
"strings" "strings"
//"syscall"
//"syscall
//"time" //"time"
//"hilbish/util" //"hilbish/util"
@ -134,8 +137,8 @@ func hilbishLoader(mlr *moonlight.Runtime) moonlight.Value {
// very meta // very meta
if moonlight.IsMidnight() { if moonlight.IsMidnight() {
moduleModule := moduleLoader(mlr) //moduleModule := moduleLoader(mlr)
hshMod.SetField("module", moonlight.TableValue(moduleModule)) //hshMod.SetField("module", moonlight.TableValue(moduleModule))
} }
return moonlight.TableValue(hshMod) return moonlight.TableValue(hshMod)
@ -302,7 +305,6 @@ func hlcwd(mlr *moonlight.Runtime, c *moonlight.GoCont) (moonlight.Cont, error)
return mlr.PushNext1(c, moonlight.StringValue(cwd)), nil return mlr.PushNext1(c, moonlight.StringValue(cwd)), nil
} }
// read(prompt) -> input (string) // read(prompt) -> input (string)
// Read input from the user, using Hilbish's line editor/input reader. // Read input from the user, using Hilbish's line editor/input reader.
// This is a separate instance from the one Hilbish actually uses. // This is a separate instance from the one Hilbish actually uses.
@ -352,14 +354,14 @@ hilbish.prompt '%u@%h :%d $'
-- prompt: user@hostname: ~/directory $ -- prompt: user@hostname: ~/directory $
#example #example
*/ */
func hlprompt(mlr *moonlight.Runtime, c *moonlight.GoCont) (moonlight.Cont, error) { func hlprompt(mlr *moonlight.Runtime) error {
err := mlr.Check1Arg(c) err := mlr.Check1Arg()
if err != nil { if err != nil {
return nil, err return err
} }
p, err := mlr.StringArg(c, 0) p, err := mlr.StringArg(0)
if err != nil { if err != nil {
return nil, err return err
} }
typ := "left" typ := "left"
// optional 2nd arg // optional 2nd arg
@ -378,11 +380,13 @@ func hlprompt(mlr *moonlight.Runtime, c *moonlight.GoCont) (moonlight.Cont, erro
case "left": case "left":
prompt = p prompt = p
lr.SetPrompt(fmtPrompt(prompt)) lr.SetPrompt(fmtPrompt(prompt))
case "right": lr.SetRightPrompt(fmtPrompt(p)) case "right":
default: return nil, errors.New("expected prompt type to be right or left, got " + typ) lr.SetRightPrompt(fmtPrompt(p))
default:
return errors.New("expected prompt type to be right or left, got " + typ)
} }
return c.Next(), nil return nil
} }
// multiprompt(str) // multiprompt(str)
@ -437,15 +441,15 @@ hilbish.alias('dircount', 'ls %1 | wc -l')
*/ */
//func hlalias(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) { //func hlalias(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
func hlalias(mlr *moonlight.Runtime, c *moonlight.GoCont) (moonlight.Cont, error) { func hlalias(mlr *moonlight.Runtime, c *moonlight.GoCont) (moonlight.Cont, error) {
if err := mlr.CheckNArgs(c, 2); err != nil { if err := mlr.CheckNArgs(2); err != nil {
return nil, err return nil, err
} }
cmd, err := mlr.StringArg(c, 0) cmd, err := mlr.StringArg(0)
if err != nil { if err != nil {
return nil, err return nil, err
} }
orig, err := mlr.StringArg(c, 1) orig, err := mlr.StringArg(1)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -471,7 +475,7 @@ hilbish.appendPath {
#example #example
*/ */
func hlappendPath(mlr *moonlight.Runtime, c *moonlight.GoCont) (moonlight.Cont, error) { func hlappendPath(mlr *moonlight.Runtime, c *moonlight.GoCont) (moonlight.Cont, error) {
if err := mlr.Check1Arg(c); err != nil { if err := mlr.Check1Arg(); err != nil {
return nil, err return nil, err
} }
arg := mlr.Arg(c, 0) arg := mlr.Arg(c, 0)
@ -498,7 +502,7 @@ func appendPath(dir string) {
// if dir isnt already in $PATH, add it // if dir isnt already in $PATH, add it
if !strings.Contains(pathenv, dir) { if !strings.Contains(pathenv, dir) {
os.Setenv("PATH", pathenv + string(os.PathListSeparator) + dir) os.Setenv("PATH", pathenv+string(os.PathListSeparator)+dir)
} }
} }
@ -766,7 +770,7 @@ func hlinputMode(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
// 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, c *moonlight.GoCont) (moonlight.Cont, error) {
if err := mlr.Check1Arg(c); err != nil { if err := mlr.Check1Arg(); err != nil {
return nil, err return nil, err
} }
mode := mlr.Arg(c, 0) mode := mlr.Arg(c, 0)
@ -774,11 +778,15 @@ func hlrunnerMode(mlr *moonlight.Runtime, c *moonlight.GoCont) (moonlight.Cont,
switch moonlight.Type(mode) { switch moonlight.Type(mode) {
case moonlight.StringType: case moonlight.StringType:
switch mode.AsString() { switch mode.AsString() {
case "hybrid", "hybridRev", "lua", "sh": runnerMode = mode case "hybrid", "hybridRev", "lua", "sh":
default: return nil, errors.New("execMode: expected either a function or hybrid, hybridRev, lua, sh. Received " + mode.AsString()) runnerMode = mode
default:
return nil, errors.New("execMode: expected either a function or hybrid, hybridRev, lua, sh. Received " + mode.AsString())
} }
case moonlight.FunctionType: runnerMode = mode case moonlight.FunctionType:
default: return nil, errors.New("execMode: expected either a function or hybrid, hybridRev, lua, sh. Received " + mode.TypeName()) runnerMode = mode
default:
return nil, errors.New("execMode: expected either a function or hybrid, hybridRev, lua, sh. Received " + mode.TypeName())
} }
return c.Next(), nil return c.Next(), nil

26
go.mod
View File

@ -1,20 +1,20 @@
module hilbish module hilbish
go 1.21 go 1.23.0
toolchain go1.22.2 toolchain go1.24.3
require ( require (
github.com/aarzilli/golua v0.0.0-20210507130708-11106aa57765 github.com/aarzilli/golua v0.0.0-20250217091409-248753f411c4
github.com/arnodel/golua v0.0.0-20230215163904-e0b5347eaaa1 github.com/arnodel/golua v0.1.0
github.com/atsushinee/go-markdown-generator v0.0.0-20191121114853-83f9e1f68504 github.com/atsushinee/go-markdown-generator v0.0.0-20231027094725-92d26ffbe778
github.com/blackfireio/osinfo v1.0.5 github.com/blackfireio/osinfo v1.1.0
github.com/maxlandon/readline v1.0.14 github.com/maxlandon/readline v1.1.3
github.com/pborman/getopt v1.1.0 github.com/pborman/getopt v1.1.0
github.com/sahilm/fuzzy v0.1.1 github.com/sahilm/fuzzy v0.1.1
golang.org/x/sys v0.22.0 golang.org/x/sys v0.33.0
golang.org/x/term v0.22.0 golang.org/x/term v0.32.0
mvdan.cc/sh/v3 v3.8.0 mvdan.cc/sh/v3 v3.11.0
) )
require ( require (
@ -25,8 +25,8 @@ require (
github.com/muesli/cancelreader v0.2.2 // indirect github.com/muesli/cancelreader v0.2.2 // indirect
github.com/olekukonko/ts v0.0.0-20171002115256-78ecb04241c0 // indirect github.com/olekukonko/ts v0.0.0-20171002115256-78ecb04241c0 // indirect
github.com/rivo/uniseg v0.4.7 // indirect github.com/rivo/uniseg v0.4.7 // indirect
golang.org/x/sync v0.7.0 // indirect golang.org/x/sync v0.15.0 // indirect
golang.org/x/text v0.14.0 // indirect golang.org/x/text v0.26.0 // indirect
) )
replace mvdan.cc/sh/v3 => github.com/Rosettea/sh/v3 v3.4.0-0.dev.0.20240720131751-805c301321fd replace mvdan.cc/sh/v3 => github.com/Rosettea/sh/v3 v3.4.0-0.dev.0.20240720131751-805c301321fd
@ -35,4 +35,4 @@ replace github.com/maxlandon/readline => ./readline
replace layeh.com/gopher-luar => github.com/layeh/gopher-luar v1.0.10 replace layeh.com/gopher-luar => github.com/layeh/gopher-luar v1.0.10
replace github.com/arnodel/golua => github.com/Rosettea/golua v0.0.0-20240427174124-d239074c1749 replace github.com/arnodel/golua => github.com/Rosettea/golua v0.0.0-20241104031959-5551ea280f23

16
go.sum
View File

@ -1,17 +1,25 @@
github.com/Rosettea/golua v0.0.0-20240427174124-d239074c1749 h1:jIFnWBTsYw8s7RX7H2AOXjDVhWP3ol7OzUVaPN2KnGI= github.com/Rosettea/golua v0.0.0-20240427174124-d239074c1749 h1:jIFnWBTsYw8s7RX7H2AOXjDVhWP3ol7OzUVaPN2KnGI=
github.com/Rosettea/golua v0.0.0-20240427174124-d239074c1749/go.mod h1:9jzpYPiU2is0HVGCiuIOBSXdergHUW44IEjmuN1UrIE= github.com/Rosettea/golua v0.0.0-20240427174124-d239074c1749/go.mod h1:9jzpYPiU2is0HVGCiuIOBSXdergHUW44IEjmuN1UrIE=
github.com/Rosettea/golua v0.0.0-20241104031959-5551ea280f23 h1:mUZnT0gmDEmTkqXsbnDbuJ3CNil7DCOMiCQYgjbKIdI=
github.com/Rosettea/golua v0.0.0-20241104031959-5551ea280f23/go.mod h1:9jzpYPiU2is0HVGCiuIOBSXdergHUW44IEjmuN1UrIE=
github.com/Rosettea/sh/v3 v3.4.0-0.dev.0.20240720131751-805c301321fd h1:THNle0FR2g7DMO1y3Bx1Zr7rYeiLXt3st3UkxEsMzL4= github.com/Rosettea/sh/v3 v3.4.0-0.dev.0.20240720131751-805c301321fd h1:THNle0FR2g7DMO1y3Bx1Zr7rYeiLXt3st3UkxEsMzL4=
github.com/Rosettea/sh/v3 v3.4.0-0.dev.0.20240720131751-805c301321fd/go.mod h1:YZalN5H7WNQw3DGij6IvHsEhn5YMW7M2FCwG6gnfKy4= github.com/Rosettea/sh/v3 v3.4.0-0.dev.0.20240720131751-805c301321fd/go.mod h1:YZalN5H7WNQw3DGij6IvHsEhn5YMW7M2FCwG6gnfKy4=
github.com/aarzilli/golua v0.0.0-20210507130708-11106aa57765 h1:N6gB4UCRBZz8twlJbMFiCKj0zX5Et2nFU/LRafT4x80= github.com/aarzilli/golua v0.0.0-20210507130708-11106aa57765 h1:N6gB4UCRBZz8twlJbMFiCKj0zX5Et2nFU/LRafT4x80=
github.com/aarzilli/golua v0.0.0-20210507130708-11106aa57765/go.mod h1:hMjfaJVSqVnxenMlsxrq3Ni+vrm9Hs64tU4M7dhUoO4= github.com/aarzilli/golua v0.0.0-20210507130708-11106aa57765/go.mod h1:hMjfaJVSqVnxenMlsxrq3Ni+vrm9Hs64tU4M7dhUoO4=
github.com/aarzilli/golua v0.0.0-20250217091409-248753f411c4 h1:gW5i3FQAMcbkNgo/A87gCKAbBMalAO8BlPIMo9Gk2Ow=
github.com/aarzilli/golua v0.0.0-20250217091409-248753f411c4/go.mod h1:hMjfaJVSqVnxenMlsxrq3Ni+vrm9Hs64tU4M7dhUoO4=
github.com/acarl005/stripansi v0.0.0-20180116102854-5a71ef0e047d h1:licZJFw2RwpHMqeKTCYkitsPqHNxTmd4SNR5r94FGM8= github.com/acarl005/stripansi v0.0.0-20180116102854-5a71ef0e047d h1:licZJFw2RwpHMqeKTCYkitsPqHNxTmd4SNR5r94FGM8=
github.com/acarl005/stripansi v0.0.0-20180116102854-5a71ef0e047d/go.mod h1:asat636LX7Bqt5lYEZ27JNDcqxfjdBQuJ/MM4CN/Lzo= github.com/acarl005/stripansi v0.0.0-20180116102854-5a71ef0e047d/go.mod h1:asat636LX7Bqt5lYEZ27JNDcqxfjdBQuJ/MM4CN/Lzo=
github.com/arnodel/strftime v0.1.6 h1:0hc0pUvk8KhEMXE+htyaOUV42zNcf/csIbjzEFCJqsw= github.com/arnodel/strftime v0.1.6 h1:0hc0pUvk8KhEMXE+htyaOUV42zNcf/csIbjzEFCJqsw=
github.com/arnodel/strftime v0.1.6/go.mod h1:5NbK5XqYK8QpRZpqKNt4OlxLtIB8cotkLk4KTKzJfWs= github.com/arnodel/strftime v0.1.6/go.mod h1:5NbK5XqYK8QpRZpqKNt4OlxLtIB8cotkLk4KTKzJfWs=
github.com/atsushinee/go-markdown-generator v0.0.0-20191121114853-83f9e1f68504 h1:R1/AOzdMbopSliUTTEHvHbyNmnZ3YxY5GvdhTkpPsSY= github.com/atsushinee/go-markdown-generator v0.0.0-20191121114853-83f9e1f68504 h1:R1/AOzdMbopSliUTTEHvHbyNmnZ3YxY5GvdhTkpPsSY=
github.com/atsushinee/go-markdown-generator v0.0.0-20191121114853-83f9e1f68504/go.mod h1:kHBCvAXJIatTX1pw6tLiOspjGc3MhUDRlog9yrCUS+k= github.com/atsushinee/go-markdown-generator v0.0.0-20191121114853-83f9e1f68504/go.mod h1:kHBCvAXJIatTX1pw6tLiOspjGc3MhUDRlog9yrCUS+k=
github.com/atsushinee/go-markdown-generator v0.0.0-20231027094725-92d26ffbe778 h1:iBzH7EQLFyjkpwXihHWf7QbbzfYfxAlyP4pTjCJbnMw=
github.com/atsushinee/go-markdown-generator v0.0.0-20231027094725-92d26ffbe778/go.mod h1:kHBCvAXJIatTX1pw6tLiOspjGc3MhUDRlog9yrCUS+k=
github.com/blackfireio/osinfo v1.0.5 h1:6hlaWzfcpb87gRmznVf7wSdhysGqLRz9V/xuSdCEXrA= github.com/blackfireio/osinfo v1.0.5 h1:6hlaWzfcpb87gRmznVf7wSdhysGqLRz9V/xuSdCEXrA=
github.com/blackfireio/osinfo v1.0.5/go.mod h1:Pd987poVNmd5Wsx6PRPw4+w7kLlf9iJxoRKPtPAjOrA= github.com/blackfireio/osinfo v1.0.5/go.mod h1:Pd987poVNmd5Wsx6PRPw4+w7kLlf9iJxoRKPtPAjOrA=
github.com/blackfireio/osinfo v1.1.0 h1:1LMkMiFL42+Brx7r3MKuf7UTlXBRgebFLJQAfoFafj8=
github.com/blackfireio/osinfo v1.1.0/go.mod h1:Pd987poVNmd5Wsx6PRPw4+w7kLlf9iJxoRKPtPAjOrA=
github.com/creack/pty v1.1.21 h1:1/QdRyBaHHJP61QkWMXlOIBfsgdDeeKfK8SYVUWJKf0= github.com/creack/pty v1.1.21 h1:1/QdRyBaHHJP61QkWMXlOIBfsgdDeeKfK8SYVUWJKf0=
github.com/creack/pty v1.1.21/go.mod h1:MOBLtS5ELjhRRrroQr9kyvTxUAFNvYEK993ew/Vr4O4= github.com/creack/pty v1.1.21/go.mod h1:MOBLtS5ELjhRRrroQr9kyvTxUAFNvYEK993ew/Vr4O4=
github.com/evilsocket/islazy v1.11.0 h1:B5w6uuS6ki6iDG+aH/RFeoMb8ijQh/pGabewqp2UeJ0= github.com/evilsocket/islazy v1.11.0 h1:B5w6uuS6ki6iDG+aH/RFeoMb8ijQh/pGabewqp2UeJ0=
@ -40,9 +48,17 @@ github.com/sahilm/fuzzy v0.1.1 h1:ceu5RHF8DGgoi+/dR5PsECjCDH1BE3Fnmpo7aVXOdRA=
github.com/sahilm/fuzzy v0.1.1/go.mod h1:VFvziUEIMCrT6A6tw2RFIXPXXmzXbOsSHF0DOI8ZK9Y= github.com/sahilm/fuzzy v0.1.1/go.mod h1:VFvziUEIMCrT6A6tw2RFIXPXXmzXbOsSHF0DOI8ZK9Y=
golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M= golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M=
golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sync v0.15.0 h1:KWH3jNZsfyT6xfAfKiz6MRNmd46ByHDYaZ7KSkCtdW8=
golang.org/x/sync v0.15.0/go.mod h1:1dzgHSNfp02xaA81J2MS99Qcpr2w7fw1gpm99rleRqA=
golang.org/x/sys v0.22.0 h1:RI27ohtqKCnwULzJLqkv897zojh5/DwS/ENaMzUOaWI= golang.org/x/sys v0.22.0 h1:RI27ohtqKCnwULzJLqkv897zojh5/DwS/ENaMzUOaWI=
golang.org/x/sys v0.22.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/sys v0.22.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.33.0 h1:q3i8TbbEz+JRD9ywIRlyRAQbM0qF7hu24q3teo2hbuw=
golang.org/x/sys v0.33.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
golang.org/x/term v0.22.0 h1:BbsgPEJULsl2fV/AT3v15Mjva5yXKQDyKf+TbDz7QJk= golang.org/x/term v0.22.0 h1:BbsgPEJULsl2fV/AT3v15Mjva5yXKQDyKf+TbDz7QJk=
golang.org/x/term v0.22.0/go.mod h1:F3qCibpT5AMpCRfhfT53vVJwhLtIVHhB9XDjfFvnMI4= golang.org/x/term v0.22.0/go.mod h1:F3qCibpT5AMpCRfhfT53vVJwhLtIVHhB9XDjfFvnMI4=
golang.org/x/term v0.32.0 h1:DR4lr0TjUs3epypdhTOkMmuF5CDFJ/8pOnbzMZPQ7bg=
golang.org/x/term v0.32.0/go.mod h1:uZG1FhGx848Sqfsq4/DlJr3xGGsYMu/L5GW4abiaEPQ=
golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ= golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
golang.org/x/text v0.26.0 h1:P42AVeLghgTYr4+xUnTRKDMqpar+PtX7KWuNQL21L8M=
golang.org/x/text v0.26.0/go.mod h1:QK15LZJUUQVJxhz7wXgxSy/CJaTFjd0G+YLonydOVQA=

View File

@ -35,6 +35,7 @@ import (
) )
type listenerType int type listenerType int
const ( const (
goListener listenerType = iota goListener listenerType = iota
luaListener luaListener
@ -44,14 +45,14 @@ const (
type Recoverer func(event string, handler *Listener, err interface{}) type Recoverer func(event string, handler *Listener, err interface{})
// Listener is a struct that holds the handler for an event. // Listener is a struct that holds the handler for an event.
type Listener struct{ type Listener struct {
typ listenerType typ listenerType
once bool once bool
caller func(...interface{}) caller func(...interface{})
luaCaller *moonlight.Closure luaCaller *moonlight.Closure
} }
type Bait struct{ type Bait struct {
recoverer Recoverer recoverer Recoverer
handlers map[string][]*Listener handlers map[string][]*Listener
rtm *moonlight.Runtime rtm *moonlight.Runtime
@ -87,8 +88,10 @@ func (b *Bait) Emit(event string, args ...interface{}) {
for _, arg := range args { for _, arg := range args {
var luarg moonlight.Value var luarg moonlight.Value
switch arg.(type) { switch arg.(type) {
case moonlight.Value: luarg = arg.(moonlight.Value) case moonlight.Value:
default: luarg = moonlight.AsValue(arg) luarg = arg.(moonlight.Value)
default:
luarg = moonlight.AsValue(arg)
} }
luaArgs = append(luaArgs, luarg) luaArgs = append(luaArgs, luarg)
} }
@ -195,11 +198,10 @@ func (b *Bait) addListener(event string, listener *Listener) {
b.handlers[event] = append(b.handlers[event], listener) b.handlers[event] = append(b.handlers[event], listener)
} }
func (b *Bait) removeListener(event string, idx int) { func (b *Bait) removeListener(event string, idx int) {
b.handlers[event][idx] = b.handlers[event][len(b.handlers[event]) - 1] b.handlers[event][idx] = b.handlers[event][len(b.handlers[event])-1]
b.handlers[event] = b.handlers[event][:len(b.handlers[event]) - 1] b.handlers[event] = b.handlers[event][:len(b.handlers[event])-1]
} }
func (b *Bait) callRecoverer(event string, handler *Listener, err interface{}) { func (b *Bait) callRecoverer(event string, handler *Listener, err interface{}) {
@ -211,8 +213,8 @@ func (b *Bait) callRecoverer(event string, handler *Listener, err interface{}) {
func (b *Bait) Loader(rtm *moonlight.Runtime) moonlight.Value { func (b *Bait) Loader(rtm *moonlight.Runtime) moonlight.Value {
exports := map[string]moonlight.Export{ exports := map[string]moonlight.Export{
"catch": {b.bcatch, 2, false},
/* /*
"catch": {b.bcatch, 2, false},
"catchOnce": util.LuaExport{b.bcatchOnce, 2, false}, "catchOnce": util.LuaExport{b.bcatchOnce, 2, false},
"throw": util.LuaExport{b.bthrow, 1, true}, "throw": util.LuaExport{b.bthrow, 1, true},
"release": util.LuaExport{b.brelease, 2, false}, "release": util.LuaExport{b.brelease, 2, false},
@ -231,8 +233,10 @@ func handleHook(t *rt.Thread, c *rt.GoCont, name string, catcher *rt.Closure, ar
for _, arg := range args { for _, arg := range args {
var luarg rt.Value var luarg rt.Value
switch arg.(type) { switch arg.(type) {
case rt.Value: luarg = arg.(rt.Value) case rt.Value:
default: luarg = rt.AsValue(arg) luarg = arg.(rt.Value)
default:
luarg = rt.AsValue(arg)
} }
luaArgs = append(luaArgs, luarg) luaArgs = append(luaArgs, luarg)
} }

View File

@ -33,12 +33,12 @@ This sink is for writing errors, as the name would suggest.
package commander package commander
import ( import (
"hilbish/golibs/bait"
"hilbish/moonlight" "hilbish/moonlight"
"hilbish/util" "hilbish/util"
"hilbish/golibs/bait"
) )
type Commander struct{ type Commander struct {
Events *bait.Bait Events *bait.Bait
Commands map[string]*moonlight.Closure Commands map[string]*moonlight.Closure
} }
@ -54,9 +54,11 @@ func New(rtm *moonlight.Runtime) *Commander {
func (c *Commander) Loader(rtm *moonlight.Runtime) moonlight.Value { func (c *Commander) Loader(rtm *moonlight.Runtime) moonlight.Value {
exports := map[string]moonlight.Export{ exports := map[string]moonlight.Export{
/*
"register": {c.cregister, 2, false}, "register": {c.cregister, 2, false},
"deregister": {c.cderegister, 1, false}, "deregister": {c.cderegister, 1, false},
"registry": {c.cregistry, 0, false}, "registry": {c.cregistry, 0, false},
*/
} }
mod := moonlight.NewTable() mod := moonlight.NewTable()
rtm.SetExports(mod, exports) rtm.SetExports(mod, exports)
@ -95,19 +97,21 @@ func (c *Commander) cregister(mlr *moonlight.Runtime, ct *moonlight.GoCont) (moo
// deregister(name) // deregister(name)
// Removes the named command. Note that this will only remove Commander-registered commands. // Removes the named command. Note that this will only remove Commander-registered commands.
// #param name string Name of the command to remove. // #param name string Name of the command to remove.
func (c *Commander) cderegister(mlr *moonlight.Runtime, ct *moonlight.GoCont) (moonlight.Cont, error) { /*
if err := mlr.Check1Arg(ct); err != nil { func (c *Commander) cderegister(mlr *moonlight.Runtime) error {
return nil, err if err := mlr.Check1Arg(); err != nil {
return err
} }
cmdName, err := mlr.StringArg(ct, 0) cmdName, err := mlr.StringArg(0)
if err != nil { if err != nil {
return nil, err return err
} }
delete(c.Commands, cmdName) delete(c.Commands, cmdName)
return ct.Next(), err return err
} }
*/
// registry() -> table // registry() -> table
// Returns all registered commanders. Returns a list of tables with the following keys: // Returns all registered commanders. Returns a list of tables with the following keys:

View File

@ -9,20 +9,20 @@ package fs
import ( import (
"fmt" "fmt"
"os"
"path/filepath" "path/filepath"
"strconv" "strconv"
"os"
"strings" "strings"
"hilbish/moonlight" "hilbish/moonlight"
"hilbish/util" "hilbish/util"
rt "github.com/arnodel/golua/runtime"
"github.com/arnodel/golua/lib/iolib" "github.com/arnodel/golua/lib/iolib"
rt "github.com/arnodel/golua/runtime"
"mvdan.cc/sh/v3/interp" "mvdan.cc/sh/v3/interp"
) )
type fs struct{ type fs struct {
runner *interp.Runner runner *interp.Runner
} }
@ -39,14 +39,10 @@ func (f *fs) Loader(rtm *moonlight.Runtime) moonlight.Value {
"cd": util.LuaExport{f.fcd, 1, false}, "cd": util.LuaExport{f.fcd, 1, false},
"mkdir": util.LuaExport{f.fmkdir, 2, false}, "mkdir": util.LuaExport{f.fmkdir, 2, false},
"stat": util.LuaExport{f.fstat, 1, false}, "stat": util.LuaExport{f.fstat, 1, false},
*/
"readdir": {f.freaddir, 1, false}, "readdir": {f.freaddir, 1, false},
/*
"abs": util.LuaExport{f.fabs, 1, false}, "abs": util.LuaExport{f.fabs, 1, false},
"basename": util.LuaExport{f.fbasename, 1, false}, "basename": util.LuaExport{f.fbasename, 1, false},
*/
"dir": {f.fdir, 1, false}, "dir": {f.fdir, 1, false},
/*
"glob": util.LuaExport{f.fglob, 1, false}, "glob": util.LuaExport{f.fglob, 1, false},
"join": util.LuaExport{f.fjoin, 0, true}, "join": util.LuaExport{f.fjoin, 0, true},
"pipe": util.LuaExport{f.fpipe, 0, false}, "pipe": util.LuaExport{f.fpipe, 0, false},
@ -126,18 +122,21 @@ func (f *fs) fcd(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
// `~/Documents/doc.txt` then this function will return `~/Documents`. // `~/Documents/doc.txt` then this function will return `~/Documents`.
// #param path string Path to get the directory for. // #param path string Path to get the directory for.
// #returns string // #returns string
func (f *fs) fdir(mlr *moonlight.Runtime, c *moonlight.GoCont) (moonlight.Cont, error) { /*
if err := mlr.Check1Arg(c); err != nil { func (f *fs) fdir(mlr *moonlight.Runtime, c *moonlight.GoCont) error {
return nil, err if err := mlr.Check1Arg(); err != nil {
return err
} }
path, err := mlr.StringArg(c, 0) path, err := mlr.StringArg(0)
if err != nil { if err != nil {
return nil, err return err
} }
next := mlr.PushNext1(c, moonlight.StringValue(filepath.Dir(path))) println(patg)
return next, nil //next := mlr.PushNext1(c, moonlight.StringValue(filepath.Dir(path)))
return nil
} }
*/
// glob(pattern) -> matches (table) // glob(pattern) -> matches (table)
// Match all files based on the provided `pattern`. // Match all files based on the provided `pattern`.
@ -175,7 +174,7 @@ func (f *fs) fglob(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
luaMatches := rt.NewTable() luaMatches := rt.NewTable()
for i, match := range matches { for i, match := range matches {
luaMatches.Set(rt.IntValue(int64(i + 1)), rt.StringValue(match)) luaMatches.Set(rt.IntValue(int64(i+1)), rt.StringValue(match))
} }
return c.PushingNext(t.Runtime, rt.TableValue(luaMatches)), nil return c.PushingNext(t.Runtime, rt.TableValue(luaMatches)), nil
@ -197,7 +196,7 @@ func (f *fs) fjoin(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
for i, v := range c.Etc() { for i, v := range c.Etc() {
if v.Type() != rt.StringType { if v.Type() != rt.StringType {
// +2; go indexes of 0 and first arg from above // +2; go indexes of 0 and first arg from above
return nil, fmt.Errorf("bad argument #%d to run (expected string, got %s)", i + 1, v.TypeName()) return nil, fmt.Errorf("bad argument #%d to run (expected string, got %s)", i+1, v.TypeName())
} }
strs[i] = v.AsString() strs[i] = v.AsString()
} }
@ -261,15 +260,16 @@ func (f *fs) fpipe(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
return c.PushingNext(t.Runtime, rfLua.Value(t.Runtime), wfLua.Value(t.Runtime)), nil return c.PushingNext(t.Runtime, rfLua.Value(t.Runtime), wfLua.Value(t.Runtime)), nil
} }
// readdir(path) -> table[string] // readdir(path) -> table[string]
// Returns a list of all files and directories in the provided path. // Returns a list of all files and directories in the provided path.
// #param dir string // #param dir string
// #returns table // #returns table
func (f *fs) freaddir(mlr *moonlight.Runtime, c *moonlight.GoCont) (moonlight.Cont, error) { func (f *fs) freaddir(mlr *moonlight.Runtime, c *moonlight.GoCont) (moonlight.Cont, error) {
if err := mlr.Check1Arg(c); err != nil { if err := mlr.Check1Arg(); err != nil {
return nil, err return nil, err
} }
dir, err := mlr.StringArg(c, 0) dir, err := mlr.StringArg(0)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -281,7 +281,7 @@ func (f *fs) freaddir(mlr *moonlight.Runtime, c *moonlight.GoCont) (moonlight.Co
return nil, err return nil, err
} }
for i, entry := range dirEntries { for i, entry := range dirEntries {
names.Set(moonlight.IntValue(int64(i + 1)), moonlight.StringValue(entry.Name())) names.Set(moonlight.IntValue(int64(i+1)), moonlight.StringValue(entry.Name()))
} }
return mlr.PushNext1(c, moonlight.TableValue(names)), nil return mlr.PushNext1(c, moonlight.TableValue(names)), nil
@ -330,9 +330,8 @@ func (f *fs) fstat(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
statTbl := rt.NewTable() statTbl := rt.NewTable()
statTbl.Set(rt.StringValue("name"), rt.StringValue(pathinfo.Name())) statTbl.Set(rt.StringValue("name"), rt.StringValue(pathinfo.Name()))
statTbl.Set(rt.StringValue("size"), rt.IntValue(pathinfo.Size())) statTbl.Set(rt.StringValue("size"), rt.IntValue(pathinfo.Size()))
statTbl.Set(rt.StringValue("mode"), rt.StringValue("0" + strconv.FormatInt(int64(pathinfo.Mode().Perm()), 8))) statTbl.Set(rt.StringValue("mode"), rt.StringValue("0"+strconv.FormatInt(int64(pathinfo.Mode().Perm()), 8)))
statTbl.Set(rt.StringValue("isDir"), rt.BoolValue(pathinfo.IsDir())) statTbl.Set(rt.StringValue("isDir"), rt.BoolValue(pathinfo.IsDir()))
return c.PushingNext1(t.Runtime, rt.TableValue(statTbl)), nil return c.PushingNext1(t.Runtime, rt.TableValue(statTbl)), nil
} }

View File

@ -14,10 +14,12 @@ var termState *term.State
func Loader(rtm *moonlight.Runtime) moonlight.Value { func Loader(rtm *moonlight.Runtime) moonlight.Value {
exports := map[string]moonlight.Export{ exports := map[string]moonlight.Export{
/*
"setRaw": {termsetRaw, 0, false}, "setRaw": {termsetRaw, 0, false},
"restoreState": {termrestoreState, 0, false}, "restoreState": {termrestoreState, 0, false},
"size": {termsize, 0, false}, "size": {termsize, 0, false},
"saveState": {termsaveState, 0, false}, "saveState": {termsaveState, 0, false},
*/
} }
mod := moonlight.NewTable() mod := moonlight.NewTable()

2
lua.go
View File

@ -38,7 +38,7 @@ func luaInit() {
hooks.Off(event, handler) hooks.Off(event, handler)
}) })
l.LoadLibrary(hooks.Loader, "bait") l.LoadLibrary(hooks.Loader, "bait")
/* /*
// Add Ctrl-C handler // Add Ctrl-C handler
hooks.On("signal.sigint", func(...interface{}) { hooks.On("signal.sigint", func(...interface{}) {
if !interactive { if !interactive {

View File

@ -1,8 +1,6 @@
package main package main
import ( import (
"plugin"
"hilbish/moonlight" "hilbish/moonlight"
) )
@ -46,7 +44,7 @@ If you attempt to require and print the result (`print(require 'plugin')`), it w
*/ */
func moduleLoader(mlr *moonlight.Runtime) *moonlight.Table { func moduleLoader(mlr *moonlight.Runtime) *moonlight.Table {
exports := map[string]moonlight.Export{ exports := map[string]moonlight.Export{
"load": {moduleLoad, 2, false}, //"load": {moduleLoad, 2, false},
} }
mod := moonlight.NewTable() mod := moonlight.NewTable()
@ -60,6 +58,7 @@ func moduleLoader(mlr *moonlight.Runtime) *moonlight.Table {
// Loads a module at the designated `path`. // Loads a module at the designated `path`.
// It will throw if any error occurs. // It will throw if any error occurs.
// #param path string // #param path string
/*
func moduleLoad(mlr *moonlight.Runtime, c *moonlight.GoCont) (moonlight.Cont, error) { func moduleLoad(mlr *moonlight.Runtime, c *moonlight.GoCont) (moonlight.Cont, error) {
if err := mlr.Check1Arg(c); err != nil { if err := mlr.Check1Arg(c); err != nil {
return nil, err return nil, err
@ -89,3 +88,4 @@ func moduleLoad(mlr *moonlight.Runtime, c *moonlight.GoCont) (moonlight.Cont, er
return mlr.PushNext1(c, val), nil return mlr.PushNext1(c, val), nil
} }
*/

View File

@ -1,20 +1,21 @@
//go:build midnight //go:build midnight
package moonlight package moonlight
import ( import (
"fmt" "fmt"
) )
type Callable interface{ type Callable interface {
Continuation(*Runtime, Cont) Cont Continuation(*Runtime, Cont) Cont
} }
type Closure struct{ type Closure struct {
refIdx int // so since we cant store the actual lua closure, refIdx int // so since we cant store the actual lua closure,
// we need a index to the ref in the lua registry... or something like that. // we need a index to the ref in the lua registry... or something like that.
} }
func (mlr *Runtime) ClosureArg(c *GoCont, num int) (*Closure, error) { func (mlr *Runtime) ClosureArg(num int) (*Closure, error) {
fmt.Println("type at ", num, "is", mlr.state.LTypename(num)) fmt.Println("type at ", num, "is", mlr.state.LTypename(num))
return &Closure{ return &Closure{

View File

@ -1,4 +1,5 @@
//go:build midnight //go:build midnight
package moonlight package moonlight
func (mlr *Runtime) SetExports(tbl *Table, exports map[string]Export) { func (mlr *Runtime) SetExports(tbl *Table, exports map[string]Export) {

View File

@ -1,3 +1,3 @@
package moonlight package moonlight
type GoToLuaFunc func(mlr *Runtime, c *GoCont) (Cont, error) type GoToLuaFunc func(mlr *Runtime) error

View File

@ -1,4 +1,5 @@
//go:build midnight //go:build midnight
package moonlight package moonlight
import ( import (
@ -7,7 +8,7 @@ import (
"github.com/aarzilli/golua/lua" "github.com/aarzilli/golua/lua"
) )
type GoFunctionFunc struct{ type GoFunctionFunc struct {
cf lua.LuaGoFunction cf lua.LuaGoFunction
} }
@ -18,7 +19,7 @@ func (gf GoFunctionFunc) Continuation(mlr *Runtime, c Cont) Cont {
} }
} }
func (mlr *Runtime) CheckNArgs(c *GoCont, num int) error { func (mlr *Runtime) CheckNArgs(num int) error {
args := mlr.state.GetTop() args := mlr.state.GetTop()
if args < num { if args < num {
return fmt.Errorf("%d arguments needed", num) return fmt.Errorf("%d arguments needed", num)
@ -27,11 +28,11 @@ func (mlr *Runtime) CheckNArgs(c *GoCont, num int) error {
return nil return nil
} }
func (mlr *Runtime) Check1Arg(c *GoCont) error { func (mlr *Runtime) Check1Arg() error {
return mlr.CheckNArgs(c, 1) return mlr.CheckNArgs(1)
} }
func (mlr *Runtime) StringArg(c *GoCont, num int) (string, error) { func (mlr *Runtime) StringArg(num int) (string, error) {
return mlr.state.CheckString(num + 1), nil return mlr.state.CheckString(num + 1), nil
} }
@ -39,23 +40,24 @@ func (mlr *Runtime) Arg(c *GoCont, num int) Value {
return c.vals[num] return c.vals[num]
} }
func (mlr *Runtime) GoFunction(fun GoToLuaFunc) GoFunctionFunc { func (mlr *Runtime) GoFunction(fun GoToLuaFunc) *GoFunctionFunc {
return GoFunctionFunc{ return &GoFunctionFunc{
cf: func(L *lua.State) int { cf: func(L *lua.State) int {
cont, err := fun(mlr, &GoCont{}) err := fun(mlr)
if err != nil { if err != nil {
L.RaiseError(err.Error()) L.RaiseError(err.Error())
return 0 return 0
} }
for _, val := range cont.(*GoCont).vals { /*for _, val := range cont.(*GoCont).vals {
switch Type(val) { switch Type(val) {
case StringType: case StringType:
L.PushString(val.AsString()) L.PushString(val.AsString())
} }
} }*/
return len(cont.(*GoCont).vals) //return len(cont.(*GoCont).vals)
return 0
}, },
} }
} }

View File

@ -1,4 +1,5 @@
//go:build !midnight //go:build !midnight
package moonlight package moonlight
import ( import (
@ -7,32 +8,28 @@ import (
type GoFunctionFunc = rt.GoFunctionFunc type GoFunctionFunc = rt.GoFunctionFunc
func (mlr *Runtime) CheckNArgs(c *GoCont, num int) error { func (mlr *Runtime) CheckNArgs(num int) error {
return c.cont.CheckNArgs(num) return mlr.rt.MainThread().CurrentCont().(*rt.GoCont).CheckNArgs(num)
} }
func (mlr *Runtime) Check1Arg(c *GoCont) error { func (mlr *Runtime) Check1Arg() error {
return c.cont.CheckNArgs(1) return mlr.rt.MainThread().CurrentCont().(*rt.GoCont).Check1Arg()
} }
func (mlr *Runtime) StringArg(c *GoCont, num int) (string, error) { func (mlr *Runtime) StringArg(num int) (string, error) {
return c.cont.StringArg(num) return mlr.rt.MainThread().CurrentCont().(*rt.GoCont).StringArg(num)
} }
func (mlr *Runtime) ClosureArg(c *GoCont, num int) (*Closure, error) { func (mlr *Runtime) ClosureArg(num int) (*Closure, error) {
return c.cont.ClosureArg(num) return mlr.rt.MainThread().CurrentCont().(*rt.GoCont).ClosureArg(num)
} }
func (mlr *Runtime) Arg(c *GoCont, num int) Value { func (mlr *Runtime) Arg(c *GoCont, num int) Value {
return c.cont.Arg(num) return mlr.rt.MainThread().CurrentCont().(*rt.GoCont).Arg(num)
} }
func (mlr *Runtime) GoFunction(fun GoToLuaFunc) GoFunctionFunc { func (mlr *Runtime) GoFunction(fun GoToLuaFunc) GoFunctionFunc {
return func(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) { return func(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
gocont := GoCont{ return c.Next(), fun(mlr)
cont: c,
thread: t,
}
return fun(mlr, &gocont)
} }
} }

View File

@ -1,11 +1,12 @@
//go:build midnight //go:build midnight
package moonlight package moonlight
import ( import (
"github.com/aarzilli/golua/lua" "github.com/aarzilli/golua/lua"
) )
type Runtime struct{ type Runtime struct {
state *lua.State state *lua.State
} }
@ -43,12 +44,17 @@ func (mlr *Runtime) Call1(f Value, args ...Value) (Value, error) {
func (mlr *Runtime) pushToState(v Value) { func (mlr *Runtime) pushToState(v Value) {
switch v.Type() { switch v.Type() {
case NilType: mlr.state.PushNil() case NilType:
case StringType: mlr.state.PushString(v.AsString()) mlr.state.PushNil()
case StringType:
mlr.state.PushString(v.AsString())
case TableType: case TableType:
tbl := v.AsTable() tbl := v.AsTable()
tbl.SetRuntime(mlr) tbl.SetRuntime(mlr)
tbl.Push() tbl.Push()
default: mlr.state.PushNil() case FunctionType:
mlr.state.PushGoClosure(v.AsLuaFunction())
default:
mlr.state.PushNil()
} }
} }

View File

@ -69,6 +69,7 @@ func (t *Table) syncToLua() {
t.SetField(k.AsString(), v) t.SetField(k.AsString(), v)
} }
} }
func ForEach(tbl *Table, cb func(key Value, val Value)) { func ForEach(tbl *Table, cb func(key Value, val Value)) {
} }

View File

@ -1,7 +1,10 @@
//go:build midnight //go:build midnight
package moonlight package moonlight
type Value struct{ import "github.com/aarzilli/golua/lua"
type Value struct {
iface interface{} iface interface{}
relIdx int relIdx int
refIdx int refIdx int
@ -10,6 +13,7 @@ type Value struct{
var NilValue = Value{nil, -1, -1} var NilValue = Value{nil, -1, -1}
type ValueType uint8 type ValueType uint8
const ( const (
NilType ValueType = iota NilType ValueType = iota
BoolType BoolType
@ -50,11 +54,16 @@ func AsValue(i interface{}) Value {
} }
switch v := i.(type) { switch v := i.(type) {
case bool: return BoolValue(v) case bool:
case int64: return IntValue(v) return BoolValue(v)
case string: return StringValue(v) case int64:
case *Table: return TableValue(v) return IntValue(v)
case Value: return v case string:
return StringValue(v)
case *Table:
return TableValue(v)
case Value:
return v
default: default:
return Value{iface: i} return Value{iface: i}
} }
@ -66,12 +75,18 @@ func (v Value) Type() ValueType {
} }
switch v.iface.(type) { switch v.iface.(type) {
case bool: return BoolType case bool:
case int64: return IntType return BoolType
case string: return StringType case int64:
case *Table: return TableType return IntType
case *Closure: return FunctionType case string:
default: return UnknownType return StringType
case *Table:
return TableType
case *GoFunctionFunc:
return FunctionType
default:
return UnknownType
} }
} }
@ -91,18 +106,28 @@ func (v Value) AsTable() *Table {
return v.iface.(*Table) return v.iface.(*Table)
} }
func (v Value) AsLuaFunction() lua.LuaGoFunction {
return v.iface.(*GoFunctionFunc).cf
}
func ToString(v Value) string { func ToString(v Value) string {
return v.AsString() return v.AsString()
} }
func (v Value) TypeName() string { func (v Value) TypeName() string {
switch v.iface.(type) { switch v.iface.(type) {
case bool: return "bool" case bool:
case int64: return "number" return "bool"
case string: return "string" case int64:
case *Table: return "table" return "number"
case *Closure: return "function" case string:
default: return "<unknown type>" return "string"
case *Table:
return "table"
case *Closure:
return "function"
default:
return "<unknown type>"
} }
} }

View File

@ -1,4 +1,8 @@
-- Prelude initializes everything else for our shell -- 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 _ = require 'succulent' -- Function additions
local bait = require 'bait' local bait = require 'bait'

View File

@ -1,9 +1,5 @@
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
@ -46,7 +42,6 @@ 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},
@ -124,3 +119,4 @@ func luaRunner(mlr *moonlight.Runtime, c *moonlight.GoCont) (moonlight.Cont, err
return mlr.PushNext1(c, moonlight.TableValue(runnerRet)), nil return mlr.PushNext1(c, moonlight.TableValue(runnerRet)), nil
} }
*/

View File

@ -1,8 +1,8 @@
package util package util
import ( import (
"strings"
"os/user" "os/user"
"strings"
"hilbish/moonlight" "hilbish/moonlight"
@ -18,14 +18,14 @@ func SetField(module *rt.Table, field string, value rt.Value) {
// HandleStrCallback handles function parameters for Go functions which take // HandleStrCallback handles function parameters for Go functions which take
// a string and a closure. // a string and a closure.
func HandleStrCallback(mlr *moonlight.Runtime, c *moonlight.GoCont) (string, *moonlight.Closure, error) { func HandleStrCallback(mlr *moonlight.Runtime, c *moonlight.GoCont) (string, *moonlight.Closure, error) {
if err := mlr.CheckNArgs(c, 2); err != nil { if err := mlr.CheckNArgs(2); err != nil {
return "", nil, err return "", nil, err
} }
name, err := mlr.StringArg(c, 0) name, err := mlr.StringArg(0)
if err != nil { if err != nil {
return "", nil, err return "", nil, err
} }
cb, err := mlr.ClosureArg(c, 1) cb, err := mlr.ClosureArg(1)
if err != nil { if err != nil {
return "", nil, err return "", nil, err
} }