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

Function LoadFile

auxiliary.go:484–523  ·  view source on GitHub ↗
(l *State, fileName, mode string)

Source from the content-addressed store, hash-verified

482}
483
484func LoadFile(l *State, fileName, mode string) error {
485 var f *os.File
486 fileNameIndex := l.Top() + 1
487 fileError := func(what string) error {
488 fileName, _ := l.ToString(fileNameIndex)
489 l.PushFString("cannot %s %s", what, fileName[1:])
490 l.Remove(fileNameIndex)
491 return FileError
492 }
493 if fileName == "" {
494 l.PushString("=stdin")
495 f = os.Stdin
496 } else {
497 l.PushString("@" + fileName)
498 var err error
499 if f, err = os.Open(fileName); err != nil {
500 return fileError("open")
501 }
502 }
503 r := bufio.NewReader(f)
504 if skipped, err := skipComment(r); err != nil {
505 l.SetTop(fileNameIndex)
506 return fileError("read")
507 } else if skipped {
508 r = bufio.NewReader(io.MultiReader(strings.NewReader("\n"), r))
509 }
510 s, _ := l.ToString(-1)
511 err := l.Load(r, s, mode)
512 if f != os.Stdin {
513 _ = f.Close()
514 }
515 switch err {
516 case nil, SyntaxError, MemoryError: // do nothing
517 default:
518 l.SetTop(fileNameIndex)
519 return fileError("read")
520 }
521 l.Remove(fileNameIndex)
522 return err
523}
524
525func LoadString(l *State, s string) error { return LoadBuffer(l, s, s, "") }
526

Callers 7

base.goFile · 0.85
loadFunction · 0.85
TestLuaFunction · 0.85
searcherLuaFunction · 0.85
DoFileFunction · 0.85
TestLoadFileSyntaxErrorFunction · 0.85

Calls 8

skipCommentFunction · 0.85
TopMethod · 0.80
ToStringMethod · 0.80
PushFStringMethod · 0.80
RemoveMethod · 0.80
PushStringMethod · 0.80
SetTopMethod · 0.80
LoadMethod · 0.80

Tested by 4

loadFunction · 0.68
TestLuaFunction · 0.68
TestLoadFileSyntaxErrorFunction · 0.68