mirror of https://github.com/Hilbis/Hilbish
Compare commits
No commits in common. "29c3c6e55a35a399a94984704d15403daf244a32" and "54f89db5783bbe3c359b4a7115662eec940d767d" have entirely different histories.
29c3c6e55a
...
54f89db578
26
sink.go
26
sink.go
|
@ -4,7 +4,6 @@ import (
|
||||||
"bufio"
|
"bufio"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"os"
|
|
||||||
|
|
||||||
"hilbish/util"
|
"hilbish/util"
|
||||||
|
|
||||||
|
@ -19,7 +18,6 @@ var sinkMetaKey = rt.StringValue("hshsink")
|
||||||
type sink struct{
|
type sink struct{
|
||||||
writer *bufio.Writer
|
writer *bufio.Writer
|
||||||
reader *bufio.Reader
|
reader *bufio.Reader
|
||||||
file *os.File
|
|
||||||
ud *rt.UserData
|
ud *rt.UserData
|
||||||
autoFlush bool
|
autoFlush bool
|
||||||
}
|
}
|
||||||
|
@ -29,34 +27,16 @@ func setupSinkType(rtm *rt.Runtime) {
|
||||||
|
|
||||||
sinkMethods := rt.NewTable()
|
sinkMethods := rt.NewTable()
|
||||||
sinkFuncs := map[string]util.LuaExport{
|
sinkFuncs := map[string]util.LuaExport{
|
||||||
"flush": {luaSinkFlush, 1, false},
|
"read": {luaSinkRead, 0, false},
|
||||||
"read": {luaSinkRead, 1, false},
|
|
||||||
"write": {luaSinkWrite, 2, false},
|
"write": {luaSinkWrite, 2, false},
|
||||||
"writeln": {luaSinkWriteln, 2, false},
|
"writeln": {luaSinkWriteln, 2, false},
|
||||||
}
|
}
|
||||||
util.SetExports(l, sinkMethods, sinkFuncs)
|
util.SetExports(l, sinkMethods, sinkFuncs)
|
||||||
|
|
||||||
sinkIndex := func(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
|
sinkIndex := func(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
|
||||||
s, _ := sinkArg(c, 0)
|
|
||||||
|
|
||||||
arg := c.Arg(1)
|
arg := c.Arg(1)
|
||||||
val := sinkMethods.Get(arg)
|
val := sinkMethods.Get(arg)
|
||||||
|
|
||||||
if val != rt.NilValue {
|
|
||||||
return c.PushingNext1(t.Runtime, val), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
keyStr, _ := arg.TryString()
|
|
||||||
|
|
||||||
switch keyStr {
|
|
||||||
case "pipe":
|
|
||||||
val = rt.BoolValue(false)
|
|
||||||
if s.file != nil {
|
|
||||||
fileInfo, _ := s.file.Stat();
|
|
||||||
val = rt.BoolValue(fileInfo.Mode() & os.ModeCharDevice == 0)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return c.PushingNext1(t.Runtime, val), nil
|
return c.PushingNext1(t.Runtime, val), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -157,10 +137,6 @@ func newSinkInput(r io.Reader) *sink {
|
||||||
}
|
}
|
||||||
s.ud = sinkUserData(s)
|
s.ud = sinkUserData(s)
|
||||||
|
|
||||||
if f, ok := r.(*os.File); ok {
|
|
||||||
s.file = f
|
|
||||||
}
|
|
||||||
|
|
||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue