Skip to content

Commit adbeb94

Browse files
committed
std
1 parent 37f5088 commit adbeb94

File tree

11 files changed

+1310
-812
lines changed

11 files changed

+1310
-812
lines changed

res/std/builtin.lua

Lines changed: 93 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,103 @@
1-
--- builtin types
1+
-- Copyright (c) 2018. tangzx([email protected])
2+
--
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+
--
7+
-- http://www.apache.org/licenses/LICENSE-2.0
8+
--
9+
-- Unless required by applicable law or agreed to in writing, software
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.
214

3-
---@class _G
4-
_G = {}
15+
-- Built-in Types
516

17+
---
18+
--- The type *nil* has one single value, **nil**, whose main property is to be
19+
--- different from any other value; it usually represents the absence of a
20+
--- useful value.
21+
---@class nil
22+
23+
---
24+
--- The type *boolean* has two values, **false** and **true**. Both **nil** and
25+
--- **false** make a condition false; any other value makes it true.
626
---@class boolean
727

28+
---
29+
--- The type *number* uses two internal representations, or two subtypes, one
30+
--- called *integer* and the other called *float*. Lua has explicit rules about
31+
--- when each representation is used, but it also converts between them
32+
--- automatically as needed. Therefore, the programmer may choose to mostly
33+
--- ignore the difference between integers and floats or to assume complete
34+
--- control over the representation of each number. Standard Lua uses 64-bit
35+
--- integers and double-precision (64-bit) floats, but you can also compile
36+
--- Lua so that it uses 32-bit integers and/or single-precision (32-bit)
37+
--- floats. The option with 32 bits for both integers and floats is
38+
--- particularly attractive for small machines and embedded systems. (See
39+
--- macro LUA_32BITS in file luaconf.h.)
840
---@class number
941

10-
---@class void
42+
---
43+
--- Lua can call (and manipulate) functions written in Lua and functions
44+
--- written in C. Both are represented by the type *function*.
45+
---@class function
1146

12-
---@class any
47+
---
48+
--- The type *userdata* is provided to allow arbitrary C data to be stored in
49+
--- Lua variables. A userdata value represents a block of raw memory. There
50+
--- are two kinds of userdata: *full userdata*, which is an object with a block
51+
--- of memory managed by Lua, and *light userdata*, which is simply a C pointer
52+
--- value. Userdata has no predefined operations in Lua, except assignment
53+
--- and identity test. By using *metatables*, the programmer can define
54+
--- operations for full userdata values. Userdata values cannot be
55+
--- created or modified in Lua, only through the C API. This guarantees the
56+
--- integrity of data owned by the host program.
57+
---@class userdata
58+
59+
---
60+
--- The type *thread* represents independent threads of execution and it is
61+
--- used to implement coroutines. Lua threads are not related to
62+
--- operating-system threads. Lua supports coroutines on all systems, even those
63+
--- that do not support threads natively.
64+
---@class thread
1365

66+
---
67+
--- The type *table* implements associative arrays, that is, arrays that can
68+
--- have as indices not only numbers, but any Lua value except **nil** and NaN.
69+
--- (*Not a Number* is a special floating-point value used by the IEEE 754
70+
--- standard to represent undefined or unrepresentable numerical results, such
71+
--- as `0/0`.) Tables can be heterogeneous; that is, they can contain values of
72+
--- all types (except **nil**). Any key with value **nil** is not considered
73+
--- part oft he table. Conversely, any key that is not part of a table has an
74+
--- a ssociated value **nil**.
75+
---
76+
--- Tables are the sole data-structuring mechanism in Lua; they can be used to
77+
--- represent ordinary arrays, lists, symbol tables, sets, records, graphs,
78+
--- trees, etc. To represent records, Lua uses the field name as an index. The
79+
--- language supports this representation by providing `a.name` as syntactic
80+
--- sugar for `a["name"]`. There are several convenient ways to create tables
81+
--- in Lua.
82+
---
83+
--- Like indices, the values of table fields can be of any type. In particular,
84+
--- because functions are first-class values, table fields can contain functions.
85+
--- Thus tables can also carry *methods*.
86+
---
87+
--- The indexing of tables follows the definition of raw equality in the
88+
--- language. The expressions `a[i]` and `a[j]` denote the same table element
89+
--- if and only if `i` and `j` are raw equal (that is, equal without
90+
--- metamethods). In particular, floats with integral values are equal to
91+
--- their respective integers. To avoid ambiguities, any float with integral
92+
--- value used as a key is converted to its respective integer. For instance,
93+
--- if you write `a[2.0] = true`, the actual key inserted into the table will
94+
--- be the integer `2`. (On the other hand, 2 and "`2`" are different Lua
95+
--- values and therefore denote different table entries.)
1496
---@class table
1597

16-
---@class thread
98+
---
99+
--- Any of the above Built-in Types.
100+
---@class any
101+
102+
---
103+
---@class void

res/std/coroutine.lua

Lines changed: 51 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,80 @@
1-
-- Copyright (c) 2017. tangzx([email protected])
1+
-- Copyright (c) 2018. tangzx([email protected])
22
--
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
66
--
77
-- http://www.apache.org/licenses/LICENSE-2.0
88
--
99
-- 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.
1414

1515
coroutine = {}
1616

1717
---
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
2021
---@return thread
2122
function coroutine.create(f) end
2223

2324
---
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
3344
---@param co thread
34-
function coroutine.resume(co, ...) end
45+
---@param val1 string
46+
---@return thread|any
47+
function coroutine.resume(co, val1, ...) end
3548

3649
---
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
3953
function coroutine.running() end
4054

4155
---
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
4761
--- finished its body function, or if it has stopped with an error.
4862
---@param co thread
63+
---@return string
4964
function coroutine.status(co) end
5065

5166
---
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
5671
--- boolean. In case of error, propagates the error.
72+
---@param f fun():thread
73+
---@return fun():any
5774
function coroutine.wrap(f) end
5875

5976
---
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
6380
function coroutine.yield(...) end

0 commit comments

Comments
 (0)