MCPcopy Index your code
hub / github.com/Shopify/go-lua / Read

Method Read

base.go:90–115  ·  view source on GitHub ↗
(b []byte)

Source from the content-addressed store, hash-verified

88}
89
90func (r *genericReader) Read(b []byte) (n int, err error) {
91 if r.e != nil {
92 return 0, r.e
93 }
94 if l := r.l; r.r == nil {
95 CheckStackWithMessage(l, 2, "too many nested functions")
96 l.PushValue(1)
97 if l.Call(0, 1); l.IsNil(-1) {
98 l.Pop(1)
99 return 0, io.EOF
100 } else if !l.IsString(-1) {
101 Errorf(l, "reader function must return a string")
102 }
103 if s, ok := l.ToString(-1); ok {
104 r.r = strings.NewReader(s)
105 } else {
106 return 0, io.EOF
107 }
108 }
109 if n, err = r.r.Read(b); err == io.EOF {
110 r.r, err = nil, nil
111 } else if err != nil {
112 r.e = err
113 }
114 return
115}
116
117var baseLibrary = []RegistryFunction{
118 {"assert", func(l *State) int {

Callers 2

readMethod · 0.80
skipCommentFunction · 0.80

Calls 8

CheckStackWithMessageFunction · 0.85
ErrorfFunction · 0.85
PushValueMethod · 0.80
CallMethod · 0.80
IsNilMethod · 0.80
PopMethod · 0.80
IsStringMethod · 0.80
ToStringMethod · 0.80

Tested by

no test coverage detected