diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2019-01-08 14:22:32 -0200 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2019-01-08 14:22:32 -0200 |
commit | 264659bd53e92969a1e17d65c0266597cde24b5d (patch) | |
tree | 6aba62d2b6ac2a46dc064ea7193c8134200a7d57 /manual | |
parent | 4ace93ca6502dd1da38d5c06fa099d229e791ba8 (diff) | |
download | lua-264659bd53e92969a1e17d65c0266597cde24b5d.tar.gz lua-264659bd53e92969a1e17d65c0266597cde24b5d.tar.bz2 lua-264659bd53e92969a1e17d65c0266597cde24b5d.zip |
Optional 'init' argument to 'string.gmatch'
The function 'string.gmatch' now has an optional 'init' argument,
similar to 'string.find' and 'string.match'. Moreover, there was
some reorganization in the manipulation of indices in the string
library.
This commit also includes small janitorial work in the manual
and in comments in the interpreter loop.
Diffstat (limited to 'manual')
-rw-r--r-- | manual/manual.of | 42 |
1 files changed, 23 insertions, 19 deletions
diff --git a/manual/manual.of b/manual/manual.of index b9ab1ebe..421d04de 100644 --- a/manual/manual.of +++ b/manual/manual.of | |||
@@ -83,25 +83,10 @@ it usually represents the absence of a useful value. | |||
83 | The type @emph{boolean} has two values, @false and @true. | 83 | The type @emph{boolean} has two values, @false and @true. |
84 | Both @nil and @false make a condition false; | 84 | Both @nil and @false make a condition false; |
85 | any other value makes it true. | 85 | any other value makes it true. |
86 | The type @emph{number} represents both | ||
87 | integer numbers and real (floating-point) numbers. | ||
88 | The type @emph{string} represents immutable sequences of bytes. | ||
89 | @index{eight-bit clean} | ||
90 | Lua is 8-bit clean: | ||
91 | strings can contain any 8-bit value, | ||
92 | including @x{embedded zeros} (@Char{\0}). | ||
93 | Lua is also encoding-agnostic; | ||
94 | it makes no assumptions about the contents of a string. | ||
95 | 86 | ||
96 | The type @emph{number} uses two internal representations, | 87 | The type @emph{number} represents both |
97 | or two @x{subtypes}, | 88 | integer numbers and real (floating-point) numbers, |
98 | one called @def{integer} and the other called @def{float}. | 89 | using two @x{subtypes}: @def{integer} and @def{float}. |
99 | Lua has explicit rules about when each representation is used, | ||
100 | but it also converts between them automatically as needed @see{coercion}. | ||
101 | Therefore, | ||
102 | the programmer may choose to mostly ignore the difference | ||
103 | between integers and floats | ||
104 | or to assume complete control over the representation of each number. | ||
105 | Standard Lua uses 64-bit integers and double-precision (64-bit) floats, | 90 | Standard Lua uses 64-bit integers and double-precision (64-bit) floats, |
106 | but you can also compile Lua so that it | 91 | but you can also compile Lua so that it |
107 | uses 32-bit integers and/or single-precision (32-bit) floats. | 92 | uses 32-bit integers and/or single-precision (32-bit) floats. |
@@ -110,6 +95,22 @@ is particularly attractive | |||
110 | for small machines and embedded systems. | 95 | for small machines and embedded systems. |
111 | (See macro @id{LUA_32BITS} in file @id{luaconf.h}.) | 96 | (See macro @id{LUA_32BITS} in file @id{luaconf.h}.) |
112 | 97 | ||
98 | Lua has explicit rules about when each subtype is used, | ||
99 | but it also converts between them automatically as needed @see{coercion}. | ||
100 | Therefore, | ||
101 | the programmer may choose to mostly ignore the difference | ||
102 | between integers and floats | ||
103 | or to assume complete control over the representation of each number. | ||
104 | |||
105 | The type @emph{string} represents immutable sequences of bytes. | ||
106 | @index{eight-bit clean} | ||
107 | Lua is 8-bit clean: | ||
108 | strings can contain any 8-bit value, | ||
109 | including @x{embedded zeros} (@Char{\0}). | ||
110 | Lua is also encoding-agnostic; | ||
111 | it makes no assumptions about the contents of a string. | ||
112 | The length of any string in Lua must fit in a Lua integer. | ||
113 | |||
113 | Lua can call (and manipulate) functions written in Lua and | 114 | Lua can call (and manipulate) functions written in Lua and |
114 | functions written in C @see{functioncall}. | 115 | functions written in C @see{functioncall}. |
115 | Both are represented by the type @emph{function}. | 116 | Both are represented by the type @emph{function}. |
@@ -6788,13 +6789,16 @@ the string argument should not contain @x{embedded zeros}. | |||
6788 | 6789 | ||
6789 | } | 6790 | } |
6790 | 6791 | ||
6791 | @LibEntry{string.gmatch (s, pattern)| | 6792 | @LibEntry{string.gmatch (s, pattern [, init])| |
6792 | Returns an iterator function that, | 6793 | Returns an iterator function that, |
6793 | each time it is called, | 6794 | each time it is called, |
6794 | returns the next captures from @id{pattern} @see{pm} | 6795 | returns the next captures from @id{pattern} @see{pm} |
6795 | over the string @id{s}. | 6796 | over the string @id{s}. |
6796 | If @id{pattern} specifies no captures, | 6797 | If @id{pattern} specifies no captures, |
6797 | then the whole match is produced in each call. | 6798 | then the whole match is produced in each call. |
6799 | A third, optional numeric argument @id{init} specifies | ||
6800 | where to start the search; | ||
6801 | its default value @N{is 1} and can be negative. | ||
6798 | 6802 | ||
6799 | As an example, the following loop | 6803 | As an example, the following loop |
6800 | will iterate over all the words from string @id{s}, | 6804 | will iterate over all the words from string @id{s}, |