MCPcopy Index your code
hub / github.com/yuin/gopher-lua / LoadFile

Method LoadFile

auxlib.go:352–390  ·  view source on GitHub ↗

* }}} */ * load and function call operations {{{ */

(path string)

Source from the content-addressed store, hash-verified

350/* load and function call operations {{{ */
351
352func (ls *LState) LoadFile(path string) (*LFunction, error) {
353 var file *os.File
354 var err error
355 if len(path) == 0 {
356 file = os.Stdin
357 } else {
358 file, err = os.Open(path)
359 defer file.Close()
360 if err != nil {
361 return nil, newApiErrorE(ApiErrorFile, err)
362 }
363 }
364
365 reader := bufio.NewReader(file)
366 // get the first character.
367 c, err := reader.ReadByte()
368 if err != nil && err != io.EOF {
369 return nil, newApiErrorE(ApiErrorFile, err)
370 }
371 if c == byte('#') {
372 // Unix exec. file?
373 // skip first line
374 _, err, _ = readBufioLine(reader)
375 if err != nil {
376 return nil, newApiErrorE(ApiErrorFile, err)
377 }
378 }
379
380 if err != io.EOF {
381 // if the file is not empty,
382 // unread the first character of the file or newline character(readBufioLine's last byte).
383 err = reader.UnreadByte()
384 if err != nil {
385 return nil, newApiErrorE(ApiErrorFile, err)
386 }
387 }
388
389 return ls.Load(reader, path)
390}
391
392func (ls *LState) LoadString(source string) (*LFunction, error) {
393 return ls.Load(strings.NewReader(source), "<string>")

Callers 5

DoFileMethod · 0.95
loLoaderLuaFunction · 0.80
baseDoFileFunction · 0.80
TestLoadFileForShebangFunction · 0.80
TestLoadFileForEmptyFileFunction · 0.80

Calls 4

LoadMethod · 0.95
readBufioLineFunction · 0.85
newApiErrorEFunction · 0.70
CloseMethod · 0.45

Tested by 2

TestLoadFileForShebangFunction · 0.64
TestLoadFileForEmptyFileFunction · 0.64