Skip to content

Commit debde57

Browse files
author
efve.zff
committed
fix: std functions should match official manuals
1 parent adc1f1f commit debde57

8 files changed

Lines changed: 113 additions & 38 deletions

File tree

‎crates/emmylua_code_analysis/resources/std/coroutine.lua‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ function coroutine.create(f) end
3232
---@param co? thread
3333
---@return boolean
3434
---@nodiscard
35-
function coroutine.isyieldable() end
35+
function coroutine.isyieldable(co) end
3636

3737
---@version > 5.4
3838
---
@@ -61,10 +61,18 @@ function coroutine.close(co) end
6161
---@return any ...
6262
function coroutine.resume(co, val1, ...) end
6363

64+
---@version 5.1
65+
---
66+
--- Returns the running coroutine, or nil when called by the main thread.
67+
---@return thread?
68+
---@nodiscard
69+
function coroutine.running() end
70+
71+
---@version > 5.2
6472
---
6573
--- Returns the running coroutine plus a boolean, true when the running
6674
--- coroutine is the main one.
67-
---@return thread, string
75+
---@return thread, boolean
6876
---@nodiscard
6977
function coroutine.running() end
7078

‎crates/emmylua_code_analysis/resources/std/debug.lua‎

Lines changed: 40 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,11 @@ function debug.getfenv(o) end
4040
--- Returns the current hook settings of the thread, as three values: the
4141
--- current hook function, the current hook mask, and the current hook count
4242
--- (as set by the `debug.sethook` function).
43-
---@overload fun():thread
43+
---@overload fun():function?, string, integer
4444
---@param thread thread
45-
---@return thread
45+
---@return function? hook
46+
---@return string mask
47+
---@return integer count
4648
function debug.gethook(thread) end
4749

4850
---@class debuglib.DebugInfo
@@ -65,7 +67,7 @@ function debug.gethook(thread) end
6567

6668
---@alias debuglib.InfoWhat
6769
---|+"n" # `name`, `namewhat`
68-
---|+"S" # `source`, `short_src`, `linedefined`, `lalinedefined`, `what`
70+
---|+"S" # `source`, `short_src`, `linedefined`, `lastlinedefined`, `what`
6971
---|+"l" # `currentline`
7072
---|+"t" # `istailcall`
7173
---|+"u" # `nups`, `nparams`, `isvararg`
@@ -177,8 +179,8 @@ function debug.getregistry() end
177179
--- no known names (variables from chunks saved without debug information).
178180
---@param f function
179181
---@param up integer
180-
---@return string name
181-
---@return any value
182+
---@return string? name
183+
---@return any? value
182184
---@nodiscard
183185
function debug.getupvalue(f, up) end
184186

@@ -254,12 +256,12 @@ function debug.sethook(thread, hook, mask, count) end
254256
--- raises an error when called with a `level` out of range. (You can call
255257
--- `getinfo` to check whether the level is valid.) Otherwise, it returns the
256258
--- name of the local variable.
257-
---@overload fun(level:integer, var:string, value:any):string
259+
---@overload fun(level:integer, var:string, value:any):string?
258260
---@param thread thread
259261
---@param level integer
260262
---@param var string
261263
---@param value any
262-
---@return string
264+
---@return string?
263265
function debug.setlocal(thread, level, var, value) end
264266

265267
---
@@ -279,7 +281,7 @@ function debug.setmetatable(value, meta) end
279281
---@param f fun():any
280282
---@param up integer
281283
---@param value any
282-
---@return string
284+
---@return string?
283285
function debug.setupvalue(f, up, value) end
284286

285287
--- Sets the given `value` as the `n`-th associated to the given `udata`.
@@ -289,22 +291,40 @@ function debug.setupvalue(f, up, value) end
289291
---@param udata userdata
290292
---@param value any
291293
---@param n integer
292-
---@return userdata
294+
---@return userdata?
293295
function debug.setuservalue(udata, value, n) end
294296

295-
--- Generates a traceback of the call stack.
296-
--- When called with no arguments, returns a traceback of the current thread.
297-
--- When the first argument is a thread, the traceback is generated for that thread;
298-
--- the optional second argument (if a string) is prepended to the traceback, and the
299-
--- optional third argument sets the level where the traceback should start (default is 1).
300-
--- When the first argument is not a thread and not nil, it is treated as an optional message.
301-
--- In that case, the traceback is generated for the current thread and the second argument,
302-
--- if provided, specifies the starting level.
297+
---@version 5.1
298+
---
299+
--- Returns a string with a traceback of the call stack. An optional message
300+
--- string is appended at the beginning of the traceback. An optional level
301+
--- number tells at which level to start the traceback (default is 1, the
302+
--- function calling traceback).
303+
---@overload fun(): string
304+
---@overload fun(message?: string, level?: integer): string
305+
---@param thread? thread
306+
---@param message? string
307+
---@param level? integer
308+
---@return string
309+
function debug.traceback(thread, message, level) end
310+
311+
---@version > 5.2
312+
---
313+
--- If message is present but is neither a string nor nil, this function
314+
--- returns message without further processing. Otherwise, it returns a string
315+
--- with a traceback of the call stack. The optional message string is appended
316+
--- at the beginning of the traceback. An optional level number tells at which
317+
--- level to start the traceback (default is 1, the function calling traceback).
318+
---@generic T
303319
---@overload fun(): string
304320
---@overload fun(message?: string, level?: integer): string
305-
---@param thread? thread|integer Optional thread or nil. If not a thread, it is interpreted as the message.
306-
---@param message? string Optional message to prepend to the traceback. If not a string (or nil), it is returned as is.
307-
---@param level? integer Optional level from which to start the traceback (default is 1).
321+
---@overload fun(message: T, level?: integer): T
322+
---@overload fun(thread: thread): string
323+
---@overload fun(thread: thread, message?: string, level?: integer): string
324+
---@overload fun(thread: thread, message: T, level?: integer): T
325+
---@param thread? thread
326+
---@param message? string|T
327+
---@param level? integer
308328
---@return string
309329
function debug.traceback(thread, message, level) end
310330

‎crates/emmylua_code_analysis/resources/std/global.lua‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ function collectgarbage(opt, ...) end
8484
--- `dofile` propagates the error to its caller (that is, `dofile` does not run
8585
--- in protected mode).
8686
---@param filename? string
87-
---@return table
87+
---@return any ...
8888
function dofile(filename) end
8989

9090
---
@@ -299,6 +299,7 @@ function rawlen(v) end
299299
---@param table table
300300
---@param index any
301301
---@param value any
302+
---@return table
302303
function rawset(table, index, value) end
303304

304305
---
@@ -469,8 +470,9 @@ function unpack(list, i, j) end
469470

470471
---@version > 5.4
471472
---
472-
---@param message string
473-
function warn(message) end
473+
---@param msg1 string
474+
---@param ... string
475+
function warn(msg1, ...) end
474476

475477
---@type string[]
476478
arg = {}

‎crates/emmylua_code_analysis/resources/std/math.lua‎

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
math = {}
1818

1919
---
20-
--- Returns the absolute value of `x`. (integer/float)
20+
--- Returns the maximum value between `x` and `-x`. (integer/float)
2121
---@overload fun(x:integer):integer
2222
---@param x number
2323
---@return number
@@ -160,12 +160,30 @@ function math.rad(x) end
160160
---@return integer
161161
function math.random(m, n) end
162162

163+
---@version 5.1, 5.2, 5.3
163164
---
164165
--- Sets `x` as the "seed" for the pseudo-random generator: equal seeds
165166
--- produce equal sequences of numbers.
166167
---@param x integer
167168
function math.randomseed(x) end
168169

170+
---@version > 5.3
171+
---
172+
--- When called with at least one argument, the integer parameters `x` and `y`
173+
--- are joined into a 128-bit seed that is used to reinitialize the pseudo-random
174+
--- generator; equal seeds produce equal sequences of numbers. The default for
175+
--- `y` is zero.
176+
---
177+
--- When called with no arguments, Lua generates a seed with a weak attempt
178+
--- for randomness.
179+
---
180+
--- This function returns the two seed components that were effectively used,
181+
--- so that setting them again repeats the sequence.
182+
---@param x? integer
183+
---@param y? integer
184+
---@return integer, integer
185+
function math.randomseed(x, y) end
186+
169187
---
170188
--- Returns the sine of `x` (assumed to be in radians).
171189
---@param x number
@@ -198,7 +216,7 @@ function math.tointeger(x) end
198216
--- Returns "`integer`" if `x` is an integer, "`float`" if it is a float, or
199217
--- **nil** if `x` is not a number.
200218
---@param x any
201-
---@return 'integer'|'float'|'nil'
219+
---@return 'integer'|'float'|nil
202220
function math.type(x) end
203221

204222
---@version >5.3

‎crates/emmylua_code_analysis/resources/std/os.lua‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -132,17 +132,15 @@ function os.execute(command) end
132132
---
133133
--- If the optional second argument `close` is true, closes the Lua state before
134134
--- exiting.
135-
---@param code integer
135+
---@param code? boolean|integer
136136
---@param close? boolean
137-
---@return integer
138137
function os.exit(code, close) end
139138

140139
---@version 5.1
141140
---
142141
--- Calls the C function exit, with an optional `code`, to terminate the host
143142
--- program. The default value for `code` is the success code.
144-
---@param code integer
145-
---@return integer
143+
---@param code? integer
146144
function os.exit(code) end
147145

148146
---

‎crates/emmylua_code_analysis/resources/std/string.lua‎

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,13 @@ function string.format(fmt, ...) end
147147
---@return fun():string?...
148148
function string.gmatch(s, pattern) end
149149

150+
---@version > 5.4
151+
---@param s string
152+
---@param pattern string
153+
---@param init? integer
154+
---@return fun():string?...
155+
function string.gmatch(s, pattern, init) end
156+
150157
---
151158
--- Returns a copy of `s` in which all (or the first `n`, if given)
152159
--- occurrences of the `pattern` have been replaced by a replacement string
@@ -230,9 +237,9 @@ function string.match(s, pattern, init) end
230237
--- Returns a binary string containing the values `v1`, `v2`, etc. packed (that
231238
--- is, serialized in binary form) according to the format string `fmt`.
232239
---@param fmt string
233-
---@param v1 string
234-
---@param v2? string
235-
---@param ... string
240+
---@param v1 string|number|integer
241+
---@param v2? string|number|integer
242+
---@param ... string|number|integer
236243
---@return string
237244
function string.pack(fmt, v1, v2, ...) end
238245

‎crates/emmylua_code_analysis/resources/std/table.lua‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,10 @@ function table.concat(list, sep, i, j) end
3434
--- elements to `list[pos]`, `list[pos+1]`, `···`, `list[#list]`. The default
3535
--- value for `pos` is ``#list+1`, so that a call `table.insert(t,x)`` inserts
3636
--- `x` at the end of list `t`.
37-
---@overload fun(list:table, value:any):integer
37+
---@overload fun(list:table, value:any)
3838
---@param list table
3939
---@param pos integer
4040
---@param value any
41-
---@return integer
4241
function table.insert(list, pos, value) end
4342

4443
---@version > 5.3
@@ -100,7 +99,6 @@ function table.remove(list, pos) end
10099
---@generic V
101100
---@param list V[]
102101
---@param comp? fun(a:V, b:V):boolean
103-
---@return integer
104102
function table.sort(list, comp) end
105103

106104
---@version > 5.2, JIT

‎crates/emmylua_code_analysis/resources/std/utf8.lua‎

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,15 @@ utf8.charpattern = ""
4040
--- (in bytes) and `c` the code point of each character. It raises an error if
4141
--- it meets any invalid byte sequence.
4242
---@param s string
43-
---@return string
43+
---@return fun(s: string, i?: integer): integer, integer
4444
function utf8.codes(s) end
4545

46+
---@version > 5.4
47+
---@param s string
48+
---@param lax? boolean
49+
---@return fun(s: string, i?: integer): integer, integer
50+
function utf8.codes(s, lax) end
51+
4652
---
4753
--- Returns the codepoints (as integers) from all characters in `s` that start
4854
--- between byte position `i` and `j` (both included). The default for `i` is
@@ -55,6 +61,15 @@ function utf8.codes(s) end
5561
---@return integer
5662
function utf8.codepoint(s, i, j) end
5763

64+
---@version > 5.4
65+
---@overload fun(s:string):integer
66+
---@param s string
67+
---@param i? integer
68+
---@param j? integer
69+
---@param lax? boolean
70+
---@return integer
71+
function utf8.codepoint(s, i, j, lax) end
72+
5873
---
5974
--- Returns the number of UTF-8 characters in string `s` that start between
6075
--- positions `i` and `j` (both inclusive). The default for `i` is 1 and for
@@ -63,6 +78,15 @@ function utf8.codepoint(s, i, j) end
6378
---@param s string
6479
---@param i? integer
6580
---@param j? integer
81+
---@return integer?
82+
---@return integer? errpos
83+
---@nodiscard
84+
function utf8.len(s, i, j) end
85+
86+
---@version > 5.4
87+
---@param s string
88+
---@param i? integer
89+
---@param j? integer
6690
---@param lax? boolean
6791
---@return integer?
6892
---@return integer? errpos

0 commit comments

Comments
 (0)