github.com/arnodel/golua@v0.0.0-20230215163904-e0b5347eaaa1/lib/iolib/lua/popen_windows.lua (about)

     1  -- tags: windows
     2  
     3  local function testf(f)
     4      return function(...)
     5          (function(ok, ...) 
     6              if ok then
     7                  print("OK", ...)
     8              else
     9                  print("ERR", ...)
    10              end
    11          end)(pcall(f, ...))
    12      end
    13  end
    14  
    15  do
    16      print(pcall(io.popen))
    17      --> ~^false\t.*value needed
    18  
    19      print(pcall(io.popen, {}))
    20      --> ~^false\t.*must be a string
    21  
    22      print(pcall(io.popen, "aaa", false))
    23      --> ~^false\t.*must be a string
    24  
    25      local fh = io.popen("hello")
    26      print(fh)
    27      --> =file ("hello")
    28  
    29      local f = io.popen("type files\\iotest.txt")
    30  
    31      print(pcall(f.read))
    32      --> ~^false\t.*value needed
    33  
    34      print(pcall(f.read, 123))
    35      --> ~^false\t
    36  
    37      print(pcall(f.read, f, "?"))
    38      --> ~^false\t.*invalid format
    39  
    40      testf(io.type)()
    41      --> ~ERR	.*value needed
    42  
    43      print(io.type(123))
    44      --> =nil
    45  
    46      print(io.type(f))
    47      --> =file
    48  
    49      print(pcall(f.lines))
    50      --> ~^false\t.*value needed
    51  
    52      print(pcall(f.lines, 123))
    53      --> ~^false\t.*must be a file
    54  
    55      print(pcall(f.lines, f, "wat"))
    56      --> ~^false\t.*invalid format
    57  
    58  
    59      for line in f:lines() do
    60          print(line)
    61      end
    62      --> =hello
    63      --> =123
    64      --> =bye
    65  
    66      testf(f.close)()
    67      --> ~ERR	.*value needed
    68  
    69      testf(f.flush)()
    70      --> ~ERR	.*value needed
    71  
    72      testf(f.flush)(123)
    73      --> ~ERR	.*must be a file
    74  
    75      f:close()
    76      print(io.type(f))
    77      --> =closed file
    78  end
    79