-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathecho.go
44 lines (38 loc) · 1.13 KB
/
echo.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package io
import (
"fmt"
"github.com/lmorg/murex/lang/proc"
"github.com/lmorg/murex/lang/types"
)
func init() {
proc.GoFunctions["echo"] = proc.GoFunction{Func: cmdOut, TypeIn: types.Null, TypeOut: types.String}
proc.GoFunctions["out"] = proc.GoFunction{Func: cmdOut, TypeIn: types.Null, TypeOut: types.String}
proc.GoFunctions["err"] = proc.GoFunction{Func: cmdErr, TypeIn: types.Null, TypeOut: types.Null}
proc.GoFunctions["print"] = proc.GoFunction{Func: cmdPrint, TypeIn: types.Null, TypeOut: types.Null}
}
func cmdOut(p *proc.Process) (err error) {
if f, _ := p.Parameters.String(0); f == "-n" {
_, err = p.Stdout.Write(p.Parameters.ByteAllRange(0, -1))
return
}
_, err = p.Stdout.Writeln(p.Parameters.ByteAll())
return
}
func cmdErr(p *proc.Process) (err error) {
if f, _ := p.Parameters.String(0); f == "-n" {
_, err = p.Stdout.Write(p.Parameters.ByteAllRange(0, -1))
return
}
_, err = p.Stderr.Writeln(p.Parameters.ByteAll())
return
}
func cmdPrint(p *proc.Process) (err error) {
_, err = fmt.Println(p.Parameters.ByteAll())
return
}
/*
func cmdTimeStamp(pid string) (err error) {
//out.StdOut =
//return
}
*/