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

Function ioOpenFile

iolib.go:617–652  ·  view source on GitHub ↗
(L *LState)

Source from the content-addressed store, hash-verified

615var ioOpenOpions = []string{"r", "rb", "w", "wb", "a", "ab", "r+", "rb+", "w+", "wb+", "a+", "ab+"}
616
617func ioOpenFile(L *LState) int {
618 path := L.CheckString(1)
619 if L.GetTop() == 1 {
620 L.Push(LString("r"))
621 }
622 mode := os.O_RDONLY
623 perm := 0600
624 writable := true
625 readable := true
626 switch ioOpenOpions[L.CheckOption(2, ioOpenOpions)] {
627 case "r", "rb":
628 mode = os.O_RDONLY
629 writable = false
630 case "w", "wb":
631 mode = os.O_WRONLY | os.O_TRUNC | os.O_CREATE
632 readable = false
633 case "a", "ab":
634 mode = os.O_WRONLY | os.O_APPEND | os.O_CREATE
635 case "r+", "rb+":
636 mode = os.O_RDWR
637 case "w+", "wb+":
638 mode = os.O_RDWR | os.O_TRUNC | os.O_CREATE
639 case "a+", "ab+":
640 mode = os.O_APPEND | os.O_RDWR | os.O_CREATE
641 }
642 file, err := newFile(L, nil, path, mode, os.FileMode(perm), writable, readable)
643 if err != nil {
644 L.Push(LNil)
645 L.Push(LString(err.Error()))
646 L.Push(LNumber(1)) // C-Lua compatibility: Original Lua pushes errno to the stack
647 return 3
648 }
649 L.Push(file)
650 return 1
651
652}
653
654var ioPopenOptions = []string{"r", "w"}
655

Callers

nothing calls this directly

Calls 8

LStringTypeAlias · 0.85
newFileFunction · 0.85
LNumberTypeAlias · 0.85
CheckStringMethod · 0.80
CheckOptionMethod · 0.80
PushMethod · 0.65
ErrorMethod · 0.65
GetTopMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…