|
1 | | --- Copyright (c) 2017. tangzx([email protected]) |
| 1 | +-- Copyright (c) 2018. tangzx([email protected]) |
2 | 2 | -- |
3 | | --- Licensed under the Apache License, Version 2.0 (the "License"); |
4 | | --- you may not use this file except in compliance with the License. |
5 | | --- You may obtain a copy of the License at |
| 3 | +-- Licensed under the Apache License, Version 2.0 (the "License"); you may not |
| 4 | +-- use this file except in compliance with the License. You may obtain a copy of |
| 5 | +-- the License at |
6 | 6 | -- |
7 | 7 | -- http://www.apache.org/licenses/LICENSE-2.0 |
8 | 8 | -- |
9 | 9 | -- Unless required by applicable law or agreed to in writing, software |
10 | | --- distributed under the License is distributed on an "AS IS" BASIS, |
11 | | --- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
12 | | --- See the License for the specific language governing permissions and |
13 | | --- limitations under the License. |
| 10 | +-- distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 11 | +-- WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 12 | +-- License for the specific language governing permissions and limitations under |
| 13 | +-- the License. |
14 | 14 |
|
15 | 15 | coroutine = {} |
16 | 16 |
|
17 | 17 | --- |
18 | | ---- Creates a new coroutine, with body `f`. `f` must be a Lua |
19 | | ---- function. Returns this new coroutine, an object with type `"thread"`. |
| 18 | +--- Creates a new coroutine, with body `f`. `f` must be a Lua function. Returns |
| 19 | +--- this new coroutine, an object with type `"thread"`. |
| 20 | +---@param f fun():thread |
20 | 21 | ---@return thread |
21 | 22 | function coroutine.create(f) end |
22 | 23 |
|
23 | 24 | --- |
24 | | ---- Starts or continues the execution of coroutine `co`. The first time |
25 | | ---- you resume a coroutine, it starts running its body. The values |
26 | | ---- ... are passed as the arguments to the body function. If the coroutine |
27 | | ---- has yielded, `resume` restarts it; the values ... are passed |
28 | | ---- as the results from the yield. |
29 | | ---- If the coroutine runs without any errors, `resume` returns true plus any |
30 | | ---- values passed to `yield` (if the coroutine yields) or any values returned |
31 | | ---- by the body function (if the coroutine terminates). If there is any error, |
32 | | ---- `resume` returns false plus the error message. |
| 25 | +--- Returns true when the running coroutine can yield. |
| 26 | +--- |
| 27 | +--- A running coroutine is yieldable if it is not the main thread and it is not |
| 28 | +--- inside a non-yieldable C function. |
| 29 | +---@return boolean |
| 30 | +function coroutine.isyieldable() end |
| 31 | + |
| 32 | +--- |
| 33 | +--- Starts or continues the execution of coroutine `co`. The first time you |
| 34 | +--- resume a coroutine, it starts running its body. The values `val1`, ... |
| 35 | +--- are passed as the arguments to the body function. If the coroutine has |
| 36 | +--- yielded, `resume` restarts it; the values `val1`, ... are passed as the |
| 37 | +--- results from the yield. |
| 38 | +--- |
| 39 | +--- If the coroutine runs without any errors, `resume` returns **true** plus any |
| 40 | +--- values passed to `yield` (when the coroutine yields) or any values returned |
| 41 | +--- by the body function (when the coroutine terminates). If there is any error, |
| 42 | +--- `resume` returns **false** plus the error message. |
| 43 | +---@overload fun(co:thread):boolean|any |
33 | 44 | ---@param co thread |
34 | | -function coroutine.resume(co, ...) end |
| 45 | +---@param val1 string |
| 46 | +---@return thread|any |
| 47 | +function coroutine.resume(co, val1, ...) end |
35 | 48 |
|
36 | 49 | --- |
37 | | ---- Returns the running coroutine. Or nil when called by the main thread. |
38 | | ----@return thread |
| 50 | +--- Returns the running coroutine plus a boolean, true when the running |
| 51 | +--- coroutine is the main one. |
| 52 | +---@return thread|boolean |
39 | 53 | function coroutine.running() end |
40 | 54 |
|
41 | 55 | --- |
42 | | ---- Returns the status of coroutine `co`. Result is a string: `"running"`, if |
43 | | ---- the coroutine is running (that is, it called `status`); `"suspended"`, if |
44 | | ---- the coroutine is suspended in a call to `yield`, or if it has not started |
45 | | ---- running yet; `"normal"` if the coroutine is active but not running (that |
46 | | ---- is, it has resumed another coroutine); and `"dead"` if the coroutine has |
| 56 | +--- Returns the status of coroutine `co`, as a string: "`running`", if the |
| 57 | +--- coroutine is running (that is, it called `status`); "`suspended`", if the |
| 58 | +--- coroutine is suspended in a call to `yield`, or if it has not started |
| 59 | +--- running yet; "`normal`" if the coroutine is active but not running (that |
| 60 | +--- is, it has resumed another coroutine); and "`dead`" if the coroutine has |
47 | 61 | --- finished its body function, or if it has stopped with an error. |
48 | 62 | ---@param co thread |
| 63 | +---@return string |
49 | 64 | function coroutine.status(co) end |
50 | 65 |
|
51 | 66 | --- |
52 | | ---- Creates a new coroutine, with body `f`. `f` must be a Lua |
53 | | ---- function. Returns a function that resumes the coroutine each time it is |
54 | | ---- called. Any arguments passed to the function behave as the extra arguments to |
55 | | ---- `resume`. Returns the same values returned by `resume`, except the first |
| 67 | +--- Creates a new coroutine, with body `f`. `f` must be a Lua function. Returns |
| 68 | +--- a function that resumes the coroutine each time it is called. Any arguments |
| 69 | +--- passed to the function behave as the extra arguments to `resume`. Returns |
| 70 | +--- the same values returned by `resume`, except the first |
56 | 71 | --- boolean. In case of error, propagates the error. |
| 72 | +---@param f fun():thread |
| 73 | +---@return fun():any |
57 | 74 | function coroutine.wrap(f) end |
58 | 75 |
|
59 | 76 | --- |
60 | | ---- Suspends the execution of the calling coroutine. The coroutine cannot |
61 | | ---- be running a C function, a metamethod, or an iterator. Any arguments to |
62 | | ---- `yield` are passed as extra results to `resume`. |
| 77 | +--- Suspends the execution of the calling coroutine. Any arguments to `yield` |
| 78 | +--- are passed as extra results to `resume`. |
| 79 | +---@return any |
63 | 80 | function coroutine.yield(...) end |
0 commit comments