-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlib.go
46 lines (42 loc) · 1.14 KB
/
lib.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
45
46
package io
import (
"io"
"github.com/embly/star"
"go.starlark.net/starlark"
)
var Reader = star.Interface{
Name: "io.Reader",
Methods: map[string]star.Method{
"Read": star.Method{
Args: []starlark.Value{star.ByteArray{}},
Returns: []starlark.Value{starlark.Int{}, star.Error{}},
Call: func(recv interface{}, args []interface{}) (resp []interface{}) {
resp = make([]interface{}, 2)
resp[0], resp[1] = recv.(io.Reader).Read(args[0].([]byte))
return
},
},
},
}
var ReadCloser = star.Interface{
Name: "io.ReadCloser",
Methods: map[string]star.Method{
"Read": star.Method{
Args: []starlark.Value{star.ByteArray{}},
Returns: []starlark.Value{starlark.Int{}, star.Error{}},
Call: func(recv interface{}, args []interface{}) (resp []interface{}) {
resp = make([]interface{}, 2)
resp[0], resp[1] = recv.(io.ReadCloser).Read(args[0].([]byte))
return
},
},
"Close": star.Method{
Returns: []starlark.Value{star.Error{}},
Call: func(recv interface{}, args []interface{}) (resp []interface{}) {
resp = make([]interface{}, 1)
resp[0] = recv.(io.ReadCloser).Close()
return
},
},
},
}