(L *LState)
| 615 | var ioOpenOpions = []string{"r", "rb", "w", "wb", "a", "ab", "r+", "rb+", "w+", "wb+", "a+", "ab+"} |
| 616 | |
| 617 | func 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 | |
| 654 | var ioPopenOptions = []string{"r", "w"} |
| 655 |
nothing calls this directly
no test coverage detected
searching dependent graphs…