Skip to content

Commit 5831c86

Browse files
committed
fix documents of collectgarbage
1 parent 524581f commit 5831c86

File tree

2 files changed

+162
-84
lines changed

2 files changed

+162
-84
lines changed

locale/en-us/meta.lua

Lines changed: 97 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -6,66 +6,103 @@ arg =
66
assert =
77
'Raises an error if the value of its argument v is false (i.e., `nil` or `false`); otherwise, returns all its arguments. In case of error, `message` is the error object; when absent, it defaults to `"assertion failed!"`'
88

9-
cgopt.collect =
10-
'Performs a full garbage-collection cycle.'
11-
cgopt.stop =
12-
'Stops automatic execution.'
13-
cgopt.restart =
14-
'Restarts automatic execution.'
15-
cgopt.count =
16-
'Returns the total memory in Kbytes.'
17-
cgopt.step =
18-
[[
19-
Performs a garbage-collection step. This option may be followed by an integer `size`.
20-
If `size` is a positive n, the collector acts as if n new bytes have been allocated; if `size` is zero, the collector performs a basic step.
21-
In incremental mode, a basic step corresponds to the current step size; in generational mode, a basic step performs a full minor collection,
22-
or an incremental step if the collector has scheduled one.
23-
In incremental mode, the function returns `true` if the step finished a collection cycle; in generational mode, it returns `true` if the step finished a major collection.
24-
]]
25-
cgopt.setpause =
26-
'Set `pause`.'
27-
cgopt.setstepmul =
28-
'Set `step multiplier`.'
29-
cgopt.incremental =
30-
'Changes the collector mode to incremental and returns the previous mode (either `"generational"` or `"incremental"`).'
31-
cgopt.generational =
32-
'Changes the collector mode to generational and returns the previous mode (either `"generational"` or `"incremental"`).'
33-
cgopt.param =
34-
[[
35-
Changes and/or retrieves the values of a collector parameter. This option must be followed by one or two extra arguments:
36-
the parameter name (a string) and an optional new value (an integer in the range [0,100000]).
37-
The call always returns the previous value of the parameter; if no new value is given, the value is left unchanged.
38-
Lua stores these values in a compressed format, so the value returned as the previous value may not be exactly the last value set.
39-
]]
40-
41-
gcparam.minormul =
42-
'The minor multiplier.'
43-
gcparam.majorminor =
44-
'The major-minor multiplier.'
45-
gcparam.minormajor =
46-
'The minor-major multiplier.'
47-
gcparam.pause =
48-
'The garbage-collector pause.'
49-
gcparam.stepmul =
50-
'The step multiplier.'
51-
gcparam.stepsize =
52-
'The step size.'
53-
54-
cgopt.isrunning =
55-
'Returns whether the collector is running.'
56-
57-
collectgarbage =
58-
[[
59-
Generic interface to the garbage collector. According to the first argument `opt`, it performs:
60-
• `"collect"`: Performs a full garbage-collection cycle (default option).
61-
• `"stop"`: Stops automatic execution of the collector; it runs only when explicitly invoked, until `"restart"`.
62-
• `"restart"`: Restarts automatic execution of the collector.
63-
• `"count"`: Returns the total memory in use by Lua in Kbytes (fractional; multiply by 1024 for bytes).
64-
• `"step"`: Performs a garbage-collection step; optional integer `size` controls behavior and return value (see `cgopt.step`).
65-
• `"isrunning"`: Returns whether the collector is running (i.e., not stopped).
66-
• `"incremental"`: Changes the mode to incremental and returns the previous mode.
67-
• `"generational"`: Changes the mode to generational and returns the previous mode.
68-
• `"param"`: Changes/reads collector parameters (see `gcparam.*`), always returns the previous value.
9+
collectgarbage51 =
10+
[[
11+
This function is a generic interface to the garbage collector. It performs different functions according to its first argument, opt:
12+
13+
* `"collect"`: performs a full garbage-collection cycle. This is the default option.
14+
* `"stop"`: stops the garbage collector.
15+
* `"restart"`: restarts the garbage collector.
16+
* `"count"`: returns the total memory in use by Lua (in Kbytes).
17+
* `"step"`: performs a garbage-collection step. The step "size" is controlled by arg (larger values mean more steps) in a non-specified way. If you want to control the step size you must experimentally tune the value of arg. Returns true if the step finished a collection cycle.
18+
* `"setpause"`: sets arg as the new value for the pause of the collector (see §2.10). Returns the previous value for pause.
19+
* `"setstepmul"`: sets arg as the new value for the step multiplier of the collector (see §2.10). Returns the previous value for step.
20+
]]
21+
22+
collectgarbage52 =
23+
[[
24+
This function is a generic interface to the garbage collector. It performs different functions according to its first argument, opt:
25+
26+
* `"collect"`: performs a full garbage-collection cycle. This is the default option.
27+
* `"stop"`: stops automatic execution of the garbage collector. The collector will run only when explicitly invoked, until a call to restart it.
28+
* `"restart"`: restarts automatic execution of the garbage collector.
29+
* `"count"`: returns the total memory in use by Lua (in Kbytes) and a second value with the total memory in bytes modulo 1024. The first value has a fractional part, so the following equality is always true:
30+
```lua
31+
k, b = collectgarbage("count")
32+
assert(k*1024 == math.floor(k)*1024 + b)
33+
```
34+
(The second result is useful when Lua is compiled with a non floating-point type for numbers.)
35+
* `"step"`: performs a garbage-collection step. The step "size" is controlled by arg (larger values mean more steps) in a non-specified way. If you want to control the step size you must experimentally tune the value of arg. Returns true if the step finished a collection cycle.
36+
* `"setpause"`: sets arg as the new value for the pause of the collector (see §2.5). Returns the previous value for pause.
37+
* `"setstepmul"`: sets arg as the new value for the step multiplier of the collector (see §2.5). Returns the previous value for step.
38+
* `"isrunning"`: returns a boolean that tells whether the collector is running (i.e., not stopped).
39+
* `"generational"`: changes the collector to generational mode. This is an experimental feature (see §2.5).
40+
* `"incremental"`: changes the collector to incremental mode. This is the default mode.
41+
]]
42+
43+
collectgarbage53 =
44+
[[
45+
This function is a generic interface to the garbage collector. It performs different functions according to its first argument, opt:
46+
47+
* `"collect"`: performs a full garbage-collection cycle. This is the default option.
48+
* `"stop"`: stops automatic execution of the garbage collector. The collector will run only when explicitly invoked, until a call to restart it.
49+
* `"restart"`: restarts automatic execution of the garbage collector.
50+
* `"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).
51+
* `"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 that amount of memory (in KBytes) had been allocated by Lua. Returns true if the step finished a collection cycle.
52+
* `"setpause"`: sets arg as the new value for the pause of the collector (see §2.5). Returns the previous value for pause.
53+
* `"setstepmul"`: sets arg as the new value for the step multiplier of the collector (see §2.5). Returns the previous value for step.
54+
* "isrunning"`: returns a boolean that tells whether the collector is running (i.e., not stopped).
55+
]]
56+
57+
collectgarbage54 =
58+
[[
59+
This function is a generic interface to the garbage collector. It performs different functions according to its first argument, opt:
60+
61+
* `"collect"`: Performs a full garbage-collection cycle. This is the default option.
62+
* `"stop"`: Stops automatic execution of the garbage collector. The collector will run only when explicitly invoked, until a call to restart it.
63+
* `"restart"`: Restarts automatic execution of the garbage collector.
64+
* `"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.
65+
* `"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 that amount of memory (in Kbytes) had been allocated by Lua. Returns true if the step finished a collection cycle.
66+
* `"isrunning"`: Returns a boolean that tells whether the collector is running (i.e., not stopped).
67+
* `"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 (see §2.5.1). A zero means to not change that value.
68+
* `"generational"`: Change the collector mode to generational. This option can be followed by two numbers: the garbage-collector minor multiplier and the major multiplier (see §2.5.2). A zero means to not change that value.
69+
See §2.5 for more details about garbage collection and some of these options.
70+
71+
This function should not be called by a finalizer.
72+
]]
73+
74+
collectgarbage55 =
75+
[[
76+
This function is a generic interface to the garbage collector. It performs different functions according to its first argument, opt:
77+
78+
* `"collect"`: Performs a full garbage-collection cycle. This is the default option.
79+
* `"stop"`: Stops automatic execution of the garbage collector. The collector will run only when explicitly invoked, until a call to restart it.
80+
* `"restart"`: Restarts automatic execution of the garbage collector.
81+
* `"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.
82+
* `"step"`: Performs a garbage-collection step. This option may be followed by an extra argument, an integer with the step size.
83+
84+
If the size is a positive n, the collector acts as if n new bytes have been allocated. If the size is zero, the collector performs a basic step. In incremental mode, a basic step corresponds to the current step size. In generational mode, a basic step performs a full minor collection or an incremental step, if the collector has scheduled one.
85+
86+
In incremental mode, the function returns true if the step finished a collection cycle. In generational mode, the function returns true if the step finished a major collection.
87+
88+
* `"isrunning"`: Returns a boolean that tells whether the collector is running (i.e., not stopped).
89+
* `"incremental"`: Changes the collector mode to incremental and returns the previous mode.
90+
* `"generational"`: Changes the collector mode to generational and returns the previous mode.
91+
* `"param"`: Changes and/or retrieves the values of a parameter of the collector. This option must be followed by one or two extra arguments: The name of the parameter being changed or retrieved (a string) and an optional new value for that parameter, an integer in the range [0,100000]. The first argument must have one of the following values:
92+
* `"minormul"`: The minor multiplier.
93+
* `"majorminor"`: The major-minor multiplier.
94+
* `"minormajor"`: The minor-major multiplier.
95+
* `"pause"`: The garbage-collector pause.
96+
* `"stepmul"`: The step multiplier.
97+
* `"stepsize"`: The step size.
98+
99+
The call always returns the previous value of the parameter. If the call does not give a new value, the value is left unchanged.
100+
101+
Lua stores these values in a compressed format, so, the value returned as the previous value may not be exactly the last value set.
102+
103+
See §2.5 for more details about garbage collection and some of these options.
104+
105+
This function should not be called by a finalizer.
69106
]]
70107

71108
dofile =

meta/template/basic.lua

Lines changed: 65 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -13,35 +13,76 @@ arg = {}
1313
---@return any ...
1414
function assert(v, message, ...) end
1515

16-
17-
---@alias gcoptions
18-
---|>"collect" # ---#DESTAIL 'cgopt.collect'
19-
---| "stop" # ---#DESTAIL 'cgopt.stop'
20-
---| "restart" # ---#DESTAIL 'cgopt.restart'
21-
---| "count" # ---#DESTAIL 'cgopt.count'
22-
---| "step" # ---#DESTAIL 'cgopt.step'
23-
---| "isrunning" # ---#DESTAIL 'cgopt.isrunning'
24-
---#if VERSION >= 5.4 then
25-
---| "incremental" # ---#DESTAIL 'cgopt.incremental'
26-
---| "generational" # ---#DESTAIL 'cgopt.generational'
16+
---#if VERSION == 5.1 then
17+
---#DES 'collectgarbage51'
18+
---@overload fun(opt?: "collect")
19+
---@overload fun(opt: "stop")
20+
---@overload fun(opt: "restart")
21+
---@overload fun(opt: "count"): number
22+
---@overload fun(opt: "step", arg: integer): true
23+
---@overload fun(opt: "setpause", arg: integer): integer
24+
---@overload fun(opt: "setstepmul", arg: integer): integer
25+
function collectgarbage(...) end
2726
---#end
28-
---#if VERSION >= 5.5 then
29-
---| "param" # ---#DESTAIL 'cgopt.param'
27+
28+
---#if VERSION == 5.2 then
29+
---#DES 'collectgarbage52'
30+
---@overload fun(opt?: "collect")
31+
---@overload fun(opt: "stop")
32+
---@overload fun(opt: "restart")
33+
---@overload fun(opt: "count"): number
34+
---@overload fun(opt: "step", arg: integer): true
35+
---@overload fun(opt: "setpause", arg: integer): integer
36+
---@overload fun(opt: "setstepmul", arg: integer): integer
37+
---@overload fun(opt: "isrunning"): boolean
38+
---@overload fun(opt: "generational")
39+
---@overload fun(opt: "incremental")
40+
function collectgarbage(...) end
3041
---#end
31-
---#if VERSION < 5.4 then
32-
---| "setpause" # ---#DESTAIL 'cgopt.setpause'
33-
---| "setstepmul" # ---#DESTAIL 'cgopt.setstepmul'
42+
43+
---#if VERSION == 5.3 then
44+
---#DES 'collectgarbage53'
45+
---@overload fun(opt?: "collect")
46+
---@overload fun(opt: "stop")
47+
---@overload fun(opt: "restart")
48+
---@overload fun(opt: "count"): number
49+
---@overload fun(opt: "step", arg: integer): true
50+
---@overload fun(opt: "setpause", arg: integer): integer
51+
---@overload fun(opt: "setstepmul", arg: integer): integer
52+
---@overload fun(opt: "isrunning"): boolean
53+
function collectgarbage(...) end
3454
---#end
3555

3656
---#if VERSION == 5.4 then
37-
---#DES 'collectgarbage'
38-
---@param opt? gcoptions
39-
---@param ... integer
40-
---@return any
41-
function collectgarbage(opt, ...) end
42-
---#else
43-
---#DES 'collectgarbage'
44-
function collectgarbage(opt, arg) end
57+
---#DES 'collectgarbage54'
58+
---@overload fun(opt?: "collect")
59+
---@overload fun(opt: "stop")
60+
---@overload fun(opt: "restart")
61+
---@overload fun(opt: "count"): number
62+
---@overload fun(opt: "step", arg: integer): true
63+
---@overload fun(opt: "isrunning"): boolean
64+
---@overload fun(opt: "incremental", pause?: integer, multiplier?: integer, stepsize?: integer)
65+
---@overload fun(opt: "generational", minor?: integer, major?: integer)
66+
function collectgarbage(...) end
67+
---#end
68+
69+
---#if VERSION == 5.5 then
70+
---#DES 'collectgarbage55'
71+
---@overload fun(opt?: "collect")
72+
---@overload fun(opt: "stop")
73+
---@overload fun(opt: "restart")
74+
---@overload fun(opt: "count"): number
75+
---@overload fun(opt: "step", arg: integer): true
76+
---@overload fun(opt: "isrunning"): boolean
77+
---@overload fun(opt: "incremental"): "generational" | "incremental"
78+
---@overload fun(opt: "generational"): "generational" | "incremental"
79+
---@overload fun(opt: "param", arg: "minormul", value?: integer): integer
80+
---@overload fun(opt: "param", arg: "majorminor", value?: integer): integer
81+
---@overload fun(opt: "param", arg: "minormajor", value?: integer): integer
82+
---@overload fun(opt: "param", arg: "pause", value?: integer): integer
83+
---@overload fun(opt: "param", arg: "stepmul", value?: integer): integer
84+
---@overload fun(opt: "param", arg: "stepsize", value?: integer): integer
85+
function collectgarbage(...) end
4586
---#end
4687

4788
---#DES 'dofile'

0 commit comments

Comments
 (0)