summaryrefslogtreecommitdiff
path: root/meta/template/io.lua
blob: 1af572b660ca5923ba882cb9cedc4af0c41de298 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
---@meta

---#DES 'io'
---@class iolib
---#DES 'io.stdin'
---@field stdin  file*
---#DES 'io.stdout'
---@field stdout file*
---#DES 'io.stderr'
---@field stderr file*
io = {}

---@alias openmode
---|>'"r"'   # ---#DESTAIL 'openmode.r'
---| '"w"'   # ---#DESTAIL 'openmode.w'
---| '"a"'   # ---#DESTAIL 'openmode.a'
---| '"r+"'  # ---#DESTAIL 'openmode.r+'
---| '"w+"'  # ---#DESTAIL 'openmode.w+'
---| '"a+"'  # ---#DESTAIL 'openmode.a+'
---| '"rb"'  # ---#DESTAIL 'openmode.rb'
---| '"wb"'  # ---#DESTAIL 'openmode.wb'
---| '"ab"'  # ---#DESTAIL 'openmode.ab'
---| '"r+b"' # ---#DESTAIL 'openmode.r+b'
---| '"w+b"' # ---#DESTAIL 'openmode.w+b'
---| '"a+b"' # ---#DESTAIL 'openmode.a+b'

---#DES 'io.close'
---@param file? file*
---@return boolean?  suc
---@return exitcode? exitcode
---@return integer?  code
function io.close(file) end

---#DES 'io.flush'
function io.flush() end

---#DES 'io.input'
---@overload fun():file*
---@param file string|file*
function io.input(file) end

---#DES 'io.lines'
---@param filename string?
---@vararg readmode
---@return fun():string|number
function io.lines(filename, ...) end

---#DES 'io.open'
---@param filename string
---@param mode     openmode
---@return file*?
---@return string? errmsg
---@nodiscard
function io.open(filename, mode) end

---#DES 'io.output'
---@overload fun():file*
---@param file string|file*
function io.output(file) end

---@alias popenmode
---| '"r"' # ---#DESTAIL 'popenmode.r'
---| '"w"' # ---#DESTAIL 'popenmode.w'

---#DES 'io.popen'
---@param prog  string
---@param mode? popenmode
---@return file*?
---@return string? errmsg
function io.popen(prog, mode) end

---#DES 'io.read'
---@vararg readmode
---@return string|number
---@return ...
---@nodiscard
function io.read(...) end

---#DES 'io.tmpfile'
---@return file*
---@nodiscard
function io.tmpfile() end

---@alias filetype
---| '"file"'        # ---#DESTAIL 'filetype.file'
---| '"closed file"' # ---#DESTAIL 'filetype.closed file'
---| 'nil'           # ---#DESTAIL 'filetype.nil'

---#DES 'io.type'
---@param file file*
---@return filetype
---@nodiscard
function io.type(file) end

---#DES 'io.write'
---@return file*
---@return string? errmsg
function io.write(...) end

---#DES 'file'
---@class file*
local file = {}

---@alias readmode number
---#if VERSION >= 5.3 then
---| '"n"'  # ---#DESTAIL 'readmode.n'
---| '"a"'  # ---#DESTAIL 'readmode.a'
---|>'"l"'  # ---#DESTAIL 'readmode.l'
---| '"L"'  # ---#DESTAIL 'readmode.L'
---#else
---| '"*n"' # ---#DESTAIL 'readmode.n'
---| '"*a"' # ---#DESTAIL 'readmode.a'
---|>'"*l"' # ---#DESTAIL 'readmode.l'
---#if JIT then
---| '"*L"' # ---#DESTAIL 'readmode.L'
---#end
---#end

---@alias exitcode '"exit"'|'"signal"'

---#DES 'file:close'
---@return boolean?  suc
---@return exitcode? exitcode
---@return integer?  code
function file:close() end

---#DES 'file:flush'
function file:flush() end

---#DES 'file:lines'
---@vararg readmode
---@return fun():string|number
function file:lines(...) end

---#DES 'file:read'
---@vararg readmode
---@return string|number
---@nodiscard
function file:read(...) end

---@alias seekwhence
---| '"set"' # ---#DESTAIL 'seekwhence.set'
---|>'"cur"' # ---#DESTAIL 'seekwhence.cur'
---| '"end"' # ---#DESTAIL 'seekwhence.end'

---#DES 'file:seek'
---@param whence? seekwhence
---@param offset? integer
---@return integer offset
---@return string? errmsg
function file:seek(whence, offset) end

---@alias vbuf
---| '"no"'   # ---#DESTAIL 'vbuf.no'
---| '"full"' # ---#DESTAIL 'vbuf.full'
---| '"line"' # ---#DESTAIL 'vbuf.line'

---#DES 'file:setvbuf'
---@param mode vbuf
---@param size integer
function file:setvbuf(mode, size) end

---#DES 'file:write'
---@vararg string|number
---@return file*?
---@return string? errmsg
function file:write(...) end

return io