mirror of
https://github.com/Hilbis/Hilbish
synced 2025-04-04 20:53:24 +00:00
refactor: move sink to util
This commit is contained in:
parent
8d51c6304a
commit
cdd31e1c4f
3
api.go
3
api.go
@ -23,7 +23,6 @@ import (
|
||||
"syscall"
|
||||
"time"
|
||||
|
||||
"hilbish/sink"
|
||||
"hilbish/util"
|
||||
|
||||
rt "github.com/arnodel/golua/runtime"
|
||||
@ -133,7 +132,7 @@ func hilbishLoad(rtm *rt.Runtime) (rt.Value, func()) {
|
||||
pluginModule := moduleLoader(rtm)
|
||||
mod.Set(rt.StringValue("module"), rt.TableValue(pluginModule))
|
||||
|
||||
sinkModule := sink.Loader(l)
|
||||
sinkModule := util.SinkLoader(l)
|
||||
mod.Set(rt.StringValue("sink"), rt.TableValue(sinkModule))
|
||||
|
||||
return rt.TableValue(mod), nil
|
||||
|
@ -6,7 +6,6 @@ import (
|
||||
"io"
|
||||
"strings"
|
||||
|
||||
"hilbish/sink"
|
||||
"hilbish/util"
|
||||
|
||||
rt "github.com/arnodel/golua/runtime"
|
||||
@ -139,7 +138,7 @@ func handleStream(v rt.Value, strms *util.Streams, errStream, inStream bool) err
|
||||
varstrm = f.Handle()
|
||||
}
|
||||
|
||||
if f, ok := val.(*sink.Sink); ok {
|
||||
if f, ok := val.(*util.Sink); ok {
|
||||
varstrm = f.Rw
|
||||
}
|
||||
|
||||
|
@ -13,7 +13,6 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"hilbish/sink"
|
||||
"hilbish/util"
|
||||
|
||||
rt "github.com/arnodel/golua/runtime"
|
||||
@ -118,9 +117,9 @@ func (s *snail) Run(cmd string, strms *util.Streams) (bool, io.Writer, io.Writer
|
||||
cmds[k.AsString()] = v.AsTable().Get(rt.StringValue("exec")).AsClosure()
|
||||
})
|
||||
if cmd := cmds[args[0]]; cmd != nil {
|
||||
stdin := sink.NewSinkInput(s.runtime, hc.Stdin)
|
||||
stdout := sink.NewSinkOutput(s.runtime, hc.Stdout)
|
||||
stderr := sink.NewSinkOutput(s.runtime, hc.Stderr)
|
||||
stdin := util.NewSinkInput(s.runtime, hc.Stdin)
|
||||
stdout := util.NewSinkOutput(s.runtime, hc.Stdout)
|
||||
stderr := util.NewSinkOutput(s.runtime, hc.Stderr)
|
||||
|
||||
sinks := rt.NewTable()
|
||||
sinks.Set(rt.StringValue("in"), rt.UserDataValue(stdin.UserData))
|
||||
|
@ -1,4 +1,4 @@
|
||||
package sink
|
||||
package util
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
@ -8,8 +8,6 @@ import (
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"hilbish/util"
|
||||
|
||||
rt "github.com/arnodel/golua/runtime"
|
||||
)
|
||||
|
||||
@ -25,11 +23,11 @@ type Sink struct{
|
||||
autoFlush bool
|
||||
}
|
||||
|
||||
func Loader(rtm *rt.Runtime) *rt.Table {
|
||||
func SinkLoader(rtm *rt.Runtime) *rt.Table {
|
||||
sinkMeta := rt.NewTable()
|
||||
|
||||
sinkMethods := rt.NewTable()
|
||||
sinkFuncs := map[string]util.LuaExport{
|
||||
sinkFuncs := map[string]LuaExport{
|
||||
"flush": {luaSinkFlush, 1, false},
|
||||
"read": {luaSinkRead, 1, false},
|
||||
"readAll": {luaSinkReadAll, 1, false},
|
||||
@ -37,7 +35,7 @@ func Loader(rtm *rt.Runtime) *rt.Table {
|
||||
"write": {luaSinkWrite, 2, false},
|
||||
"writeln": {luaSinkWriteln, 2, false},
|
||||
}
|
||||
util.SetExports(rtm, sinkMethods, sinkFuncs)
|
||||
SetExports(rtm, sinkMethods, sinkFuncs)
|
||||
|
||||
sinkIndex := func(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
|
||||
s, _ := sinkArg(c, 0)
|
||||
@ -66,12 +64,12 @@ func Loader(rtm *rt.Runtime) *rt.Table {
|
||||
sinkMeta.Set(rt.StringValue("__index"), rt.FunctionValue(rt.NewGoFunction(sinkIndex, "__index", 2, false)))
|
||||
rtm.SetRegistry(sinkMetaKey, rt.TableValue(sinkMeta))
|
||||
|
||||
exports := map[string]util.LuaExport{
|
||||
exports := map[string]LuaExport{
|
||||
"new": {luaSinkNew, 0, false},
|
||||
}
|
||||
|
||||
mod := rt.NewTable()
|
||||
util.SetExports(rtm, mod, exports)
|
||||
SetExports(rtm, mod, exports)
|
||||
|
||||
return mod
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user