Skip to content

Commit e3cd3bd

Browse files
authored
Merge pull request #120 from xuhuanzy/hover
std文档添加简单翻译
2 parents 4f30a0f + 234243c commit e3cd3bd

File tree

24 files changed

+1326
-24
lines changed

24 files changed

+1326
-24
lines changed

crates/emmylua_code_analysis/resources/std/coroutine.lua

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
-- License for the specific language governing permissions and limitations under
1414
-- the License.
1515

16+
---@class coroutinelib
1617
coroutine = {}
1718

1819
---
@@ -74,10 +75,10 @@ function coroutine.running() end
7475
--- finished its body function, or if it has stopped with an error.
7576
---@param co thread
7677
---@return
77-
---| '"running"' # Is running.
78-
---| '"suspended"' # Is suspended or not started.
79-
---| '"normal"' # Is active but not running.
80-
---| '"dead"' # Has finished or stopped with an error.
78+
---| "running" # Is running.
79+
---| "suspended" # Is suspended or not started.
80+
---| "normal" # Is active but not running.
81+
---| "dead" # Has finished or stopped with an error.
8182
function coroutine.status(co) end
8283

8384
---

crates/emmylua_code_analysis/resources/std/debug.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
-- License for the specific language governing permissions and limitations under
1414
-- the License.
1515

16+
---@class debuglib
1617
debug = {}
1718

1819
---

crates/emmylua_code_analysis/resources/std/global.lua

Lines changed: 66 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,17 @@
2424
---@return std.NotNull<T>
2525
function assert(v, message) end
2626

27+
---@alias std.collectgarbage_opt
28+
---|>"collect" # performs a full garbage-collection cycle. This is the default option.
29+
---| "stop" # stops automatic execution of the garbage collector. The collector will run only when explicitly invoked, until a call to restart it.
30+
---| "restart" # restarts automatic execution of the garbage collector.
31+
---| "count" # returns the total memory in use by Lua in Kbytes. The value has a fractional part, so that it multiplied by 1024 gives the exact number of bytes in use by Lua (except for overflows).
32+
---| "step" # performs a garbage-collection step. The step "size" is controlled by `arg`. With a zero value, the collector will perform one basic (indivisible) step. For non-zero values, the collector will perform as if Lua had allocated that amount of memory (in KBytes). Returns true if the step finished a collection cycle.
33+
---| "setpause" # sets `arg` as the new value for the *pause* of the collector (see §2.5). Returns the previous value for *pause`.
34+
---| "incremental" # Change the collector mode to incremental. This option can be followed by three numbers: the garbage-collector pause, the step multiplier, and the step size.
35+
---| "generational" # Change the collector mode to generational. This option can be followed by two numbers: the garbage-collector minor multiplier and the major multiplier.
36+
---| "isrunning" # returns a boolean that tells whether the collector is running (i.e., not stopped).
37+
2738
---
2839
--- This function is a generic interface to the garbage collector. It performs
2940
--- different functions according to its first argument, `opt`:
@@ -51,11 +62,10 @@ function assert(v, message) end
5162
--- the major multiplier.
5263
--- **"isrunning"**: returns a boolean that tells whether the collector is
5364
--- running (i.e., not stopped).
54-
---@alias collectgarbage_opt "collect"|"stop"|"restart"|"count"|"step"|"setpause"|"incremental"|"generational"|"isrunning"
55-
---@param opt? collectgarbage_opt
56-
---@param arg? string
65+
---@param opt? std.collectgarbage_opt
66+
---@param ... any
5767
---@return any
58-
function collectgarbage(opt, arg) end
68+
function collectgarbage(opt, ...) end
5969

6070
---
6171
--- Opens the named file and executes its contents as a Lua chunk. When called
@@ -108,6 +118,11 @@ function getmetatable(object) end
108118
---@return fun(tbl: any):int, std.NotNull<V>
109119
function ipairs(t) end
110120

121+
---@alias std.loadmode
122+
---| "b" # only binary chunks
123+
---| "t" # only text chunks
124+
---| "bt" # both binary and text
125+
111126
---
112127
--- Loads a chunk.
113128
--- If `chunk` is a string, the chunk is this string. If `chunk` is a function,
@@ -139,9 +154,11 @@ function ipairs(t) end
139154
--- binary chunks can crash the interpreter.
140155
---@param chunk (fun():string) | string
141156
---@param chunkname? string
142-
---@param mode? string
143-
---@param env? any
157+
---@param mode? std.loadmode
158+
---@param env? table
144159
---@return fun():any
160+
---@return string? error_message
161+
---@nodiscard
145162
function load(chunk, chunkname, mode, env) end
146163

147164

@@ -315,6 +332,37 @@ function require(modname) end
315332
---@return std.Select<T..., Num>
316333
function select(index, ...) end
317334

335+
336+
---@class std.metatable
337+
---@field __mode 'v'|'k'|'kv'|nil
338+
---@field __metatable any|nil
339+
---@field __tostring (fun(t):string)|nil
340+
---@field __gc fun(t)|nil
341+
---@field __add (fun(t1,t2):any)|nil
342+
---@field __sub (fun(t1,t2):any)|nil
343+
---@field __mul (fun(t1,t2):any)|nil
344+
---@field __div (fun(t1,t2):any)|nil
345+
---@field __mod (fun(t1,t2):any)|nil
346+
---@field __pow (fun(t1,t2):any)|nil
347+
---@field __unm (fun(t):any)|nil
348+
---@field __idiv (fun(t1,t2):any)|nil
349+
---@field __band (fun(t1,t2):any)|nil
350+
---@field __bor (fun(t1,t2):any)|nil
351+
---@field __bxor (fun(t1,t2):any)|nil
352+
---@field __bnot (fun(t):any)|nil
353+
---@field __shl (fun(t1,t2):any)|nil
354+
---@field __shr (fun(t1,t2):any)|nil
355+
---@field __concat (fun(t1,t2):any)|nil
356+
---@field __len (fun(t):integer)|nil
357+
---@field __eq (fun(t1,t2):boolean)|nil
358+
---@field __lt (fun(t1,t2):boolean)|nil
359+
---@field __le (fun(t1,t2):boolean)|nil
360+
---@field __index table|(fun(t,k):any)|nil
361+
---@field __newindex table|fun(t,k,v)|nil
362+
---@field __call (fun(t,...):...)|nil
363+
---@field __pairs (fun(t):((fun(t,k,v):any,any),any,any))|nil
364+
---@field __close (fun(t,errobj):any)|nil
365+
318366
---
319367
--- Sets the metatable for the given table. (To change the metatable of other
320368
--- types from Lua code, you must use the debug library.) If `metatable`
@@ -324,7 +372,7 @@ function select(index, ...) end
324372
--- This function returns `table`.
325373
---@generic T
326374
---@param table T
327-
---@param metatable table
375+
---@param metatable std.metatable|table
328376
---@return T
329377
function setmetatable(table, metatable) end
330378

@@ -363,13 +411,23 @@ function tonumber(e, base) end
363411
---@return string
364412
function tostring(v) end
365413

414+
---@alias std.type
415+
---| "nil"
416+
---| "number"
417+
---| "string"
418+
---| "boolean"
419+
---| "table"
420+
---| "function"
421+
---| "thread"
422+
---| "userdata"
423+
366424
---
367425
--- Returns the type of its only argument, coded as a string. The possible
368426
--- results of this function are "`nil`" (a string, not the value **nil**),
369427
--- "`number`", "`string`", "`boolean`", "`table`", "`function`", "`thread`",
370428
--- and "`userdata`".
371429
---@param v any
372-
---@return string
430+
---@return std.type type
373431
function type(v) end
374432

375433
---

crates/emmylua_code_analysis/resources/std/io.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
-- License for the specific language governing permissions and limitations under
1414
-- the License.
1515

16+
---@class iolib
1617
io = {}
1718

1819
---

crates/emmylua_code_analysis/resources/std/math.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
-- License for the specific language governing permissions and limitations under
1414
-- the License.
1515

16+
---@class mathlib
1617
math = {}
1718

1819
---

crates/emmylua_code_analysis/resources/std/os.lua

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
-- License for the specific language governing permissions and limitations under
1414
-- the License.
1515

16+
---@class oslib
1617
os = {}
1718

1819
---
@@ -21,6 +22,17 @@ os = {}
2122
---@return number
2223
function os.clock() end
2324

25+
---@class std.osdate
26+
---@field year integer|string four digits
27+
---@field month integer|string 1-12
28+
---@field day integer|string 1-31
29+
---@field hour integer|string 0-23
30+
---@field min integer|string 0-59
31+
---@field sec integer|string 0-61, due to leap seconds
32+
---@field wday integer|string 1-7, Sunday is 1
33+
---@field yday integer|string 1-366
34+
---@field isdst boolean daylight saving flag, a boolean.
35+
2436
---
2537
--- Returns a string or a table containing date and time, formatted according
2638
--- to the given string `format`.
@@ -56,7 +68,7 @@ function os.clock() end
5668
---@overload fun(fmt:"*t", time: number):table
5769
---@param format string
5870
---@param time? number
59-
---@return string
71+
---@return string|std.osdate
6072
function os.date(format, time) end
6173

6274
---
@@ -147,6 +159,17 @@ function os.rename(oldname, newname) end
147159
---@return string|nil
148160
function os.setlocale(locale, category) end
149161

162+
---@class std.osdateparam
163+
---@field year integer|string four digits
164+
---@field month integer|string 1-12
165+
---@field day integer|string 1-31
166+
---@field hour (integer|string)? 0-23
167+
---@field min (integer|string)? 0-59
168+
---@field sec (integer|string)? 0-61, due to leap seconds
169+
---@field wday (integer|string)? 1-7, Sunday is 1
170+
---@field yday (integer|string)? 1-366
171+
---@field isdst boolean? daylight saving flag, a boolean.
172+
150173
---
151174
--- Returns the current time when called without arguments, or a time
152175
--- representing the date and time specified by the given table. This table
@@ -170,9 +193,9 @@ function os.setlocale(locale, category) end
170193
--- documented in the `os.date` function, so that they represent the same time
171194
--- as before the call but with values inside their valid ranges.
172195
---@overload fun():number
173-
---@param table? table
196+
---@param date? std.osdateparam
174197
---@return number
175-
function os.time(table) end
198+
function os.time(date) end
176199

177200
---
178201
--- Returns a string with a file name that can be used for a temporary

crates/emmylua_code_analysis/resources/std/package.lua

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
-- License for the specific language governing permissions and limitations under
1414
-- the License.
1515

16+
---@class packagelib
1617
package = {}
1718

1819
---
@@ -29,7 +30,12 @@ package = {}
2930
--- executable's directory. Default is '!'.
3031
--- The fifth line is a mark to ignore all text after it when building the
3132
--- luaopen_ function name. Default is '-'.
32-
package.config = ""
33+
package.config = [[
34+
/
35+
;
36+
?
37+
!
38+
-]]
3339

3440
---
3541
--- The path used by `require` to search for a C loader.

crates/emmylua_code_analysis/resources/std/table.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
-- License for the specific language governing permissions and limitations under
1414
-- the License.
1515

16+
---@class tablelib
1617
table = {}
1718

1819
---

crates/emmylua_code_analysis/resources/std/utf8.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
-- the License.
1717

1818
---@version >5.3
19+
---@class utf8lib
1920
utf8 = {}
2021

2122
---
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
std.bit32lib: |
2+
[查看文档](command:extension.lua.doc?["en-us/54/manual.html/pdf-bit32"])
3+
4+
std.bit32lib.arshift: |
5+
返回 `x` 向右位移 `disp` 位的结果。`disp` 为负时向左位移。这是算数位移操作,左侧的空位使用 `x` 的高位填充,右侧空位使用 `0` 填充。
6+
7+
[查看文档](command:extension.lua.doc?["en-us/54/manual.html/pdf-bit32.arshift"])
8+
9+
std.bit32lib.band: |
10+
返回参数按位与的结果。
11+
12+
[查看文档](command:extension.lua.doc?["en-us/54/manual.html/pdf-bit32.band"])
13+
14+
std.bit32lib.bnot: |
15+
返回 `x` 按位取反的结果。
16+
17+
```lua
18+
assert(bit32.bnot(x) ==
19+
(-1 - x) % 2^32)
20+
```
21+
22+
[查看文档](command:extension.lua.doc?["en-us/54/manual.html/pdf-bit32.bnot"])
23+
24+
std.bit32lib.bor: |
25+
返回参数按位或的结果。
26+
27+
[查看文档](command:extension.lua.doc?["en-us/54/manual.html/pdf-bit32.bor"])
28+
29+
std.bit32lib.btest: |
30+
参数按位与的结果不为0时,返回 `true` 。
31+
32+
[查看文档](command:extension.lua.doc?["en-us/54/manual.html/pdf-bit32.btest"])
33+
34+
std.bit32lib.bxor: |
35+
返回参数按位异或的结果。
36+
37+
[查看文档](command:extension.lua.doc?["en-us/54/manual.html/pdf-bit32.bxor"])
38+
39+
std.bit32lib.extract: |
40+
返回 `n` 中第 `field` 到第 `field + width - 1` 位组成的结果。
41+
42+
[查看文档](command:extension.lua.doc?["en-us/54/manual.html/pdf-bit32.extract"])
43+
44+
std.bit32lib.replace: |
45+
返回 `v` 的第 `field` 到第 `field + width - 1` 位替换 `n` 的对应位后的结果。
46+
47+
[查看文档](command:extension.lua.doc?["en-us/54/manual.html/pdf-bit32.replace"])
48+
49+
std.bit32lib.lrotate: |
50+
返回 `x` 向左旋转 `disp` 位的结果。`disp` 为负时向右旋转。
51+
52+
[查看文档](command:extension.lua.doc?["en-us/54/manual.html/pdf-bit32.lrotate"])
53+
54+
std.bit32lib.lshift: |
55+
返回 `x` 向左位移 `disp` 位的结果。`disp` 为负时向右位移。空位总是使用 `0` 填充。
56+
57+
```lua
58+
assert(bit32.lshift(b, disp) ==
59+
(b * 2^disp) % 2^32)
60+
```
61+
62+
[查看文档](command:extension.lua.doc?["en-us/54/manual.html/pdf-bit32.lshift"])
63+
64+
std.bit32lib.rrotate: |
65+
返回 `x` 向右旋转 `disp` 位的结果。`disp` 为负时向左旋转。
66+
67+
[查看文档](command:extension.lua.doc?["en-us/54/manual.html/pdf-bit32.rrotate"])
68+
69+
std.bit32lib.rshift: |
70+
返回 `x` 向右位移 `disp` 位的结果。`disp` 为负时向左位移。空位总是使用 `0` 填充。
71+
72+
```lua
73+
assert(bit32.lshift(b, disp) ==
74+
(b * 2^disp) % 2^32)
75+
```
76+
77+
[查看文档](command:extension.lua.doc?["en-us/54/manual.html/pdf-bit32.rshift"])

0 commit comments

Comments
 (0)