Skip to content

Commit 712a7b5

Browse files
committed
Generate new API reference pages for Lune 0.8.5
1 parent 1b768a5 commit 712a7b5

File tree

3 files changed

+244
-0
lines changed

3 files changed

+244
-0
lines changed

pages/api-reference/_meta.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"luau": "Luau",
55
"net": "Net",
66
"process": "Process",
7+
"regex": "Regex",
78
"roblox": "Roblox",
89
"serde": "Serde",
910
"stdio": "Stdio",

pages/api-reference/regex.md

Lines changed: 230 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,230 @@
1+
# Regex
2+
3+
Built-in library for regular expressions
4+
5+
#### Example usage
6+
7+
```lua
8+
local Regex = require("@lune/regex")
9+
10+
local re = Regex.new("hello")
11+
12+
if re:isMatch("hello, world!") then
13+
print("Matched!")
14+
end
15+
16+
local caps = re:captures("hello, world! hello, again!")
17+
18+
print(#caps) -- 2
19+
print(caps:get(1)) -- "hello"
20+
print(caps:get(2)) -- "hello"
21+
print(caps:get(3)) -- nil
22+
```
23+
24+
## Constructors
25+
26+
### new
27+
28+
Creates a new `Regex` from a given string pattern.
29+
30+
#### Errors
31+
32+
This constructor throws an error if the given pattern is invalid.
33+
34+
#### Parameters
35+
36+
- `pattern` `string` The string pattern to use
37+
38+
#### Returns
39+
40+
- `Regex` The new Regex object
41+
42+
---
43+
44+
## Methods
45+
46+
### isMatch
47+
48+
Check if the given text matches the regular expression.
49+
50+
This method may be slightly more efficient than calling `find` if you only need to know if the text
51+
matches the pattern.
52+
53+
#### Parameters
54+
55+
- `self` Regex
56+
57+
- `text` `string` The text to search
58+
59+
#### Returns
60+
61+
- `boolean` Whether the text matches the pattern
62+
63+
---
64+
65+
### find
66+
67+
Finds the first match in the given text.
68+
69+
Returns `nil` if no match was found.
70+
71+
#### Parameters
72+
73+
- `self` Regex
74+
75+
- `text` `string` The text to search
76+
77+
#### Returns
78+
79+
- `RegexMatch?` The match object
80+
81+
---
82+
83+
### captures
84+
85+
Finds all matches in the given text as a `RegexCaptures` object.
86+
87+
Returns `nil` if no matches are found.
88+
89+
#### Parameters
90+
91+
- `self` Regex
92+
93+
- `text` `string` The text to search
94+
95+
#### Returns
96+
97+
- `RegexCaptures?` The captures object
98+
99+
---
100+
101+
### split
102+
103+
Splits the given text using the regular expression.
104+
105+
#### Parameters
106+
107+
- `self` Regex
108+
109+
- `text` `string` The text to split
110+
111+
#### Returns
112+
113+
- `{ string }` The split text
114+
115+
---
116+
117+
### replace
118+
119+
Replaces the first match in the given text with the given replacer string.
120+
121+
#### Parameters
122+
123+
- `self` Regex
124+
125+
- `haystack` `string` The text to search
126+
127+
- `replacer` `string` The string to replace matches with
128+
129+
#### Returns
130+
131+
- `string` The text with the first match replaced
132+
133+
---
134+
135+
### replaceAll
136+
137+
Replaces all matches in the given text with the given replacer string.
138+
139+
#### Parameters
140+
141+
- `self` Regex
142+
143+
- `haystack` `string` The text to search
144+
145+
- `replacer` `string` The string to replace matches with
146+
147+
#### Returns
148+
149+
- `string` The text with all matches replaced
150+
151+
---
152+
153+
# RegexCaptures
154+
155+
Captures from a regular expression.
156+
157+
## Methods
158+
159+
### get
160+
161+
Returns the match at the given index, if one exists.
162+
163+
#### Parameters
164+
165+
- `self` RegexCaptures
166+
167+
- `index` `number` The index of the match to get
168+
169+
#### Returns
170+
171+
- `RegexMatch` The match, if one exists
172+
173+
---
174+
175+
### group
176+
177+
Returns the match for the given named match group, if one exists.
178+
179+
#### Parameters
180+
181+
- `self` RegexCaptures
182+
183+
- `group` `string` The name of the group to get
184+
185+
#### Returns
186+
187+
- `RegexMatch` The match, if one exists
188+
189+
---
190+
191+
### format
192+
193+
Formats the captures using the given format string.
194+
195+
#### Example usage
196+
197+
```lua
198+
local regex = require("@lune/regex")
199+
200+
local re = regex.new("(?<day>[0-9]{2})-(?<month>[0-9]{2})-(?<year>[0-9]{4})")
201+
202+
local caps = re:captures("On 14-03-2010, I became a Tenneessee lamb.");
203+
assert(caps ~= nil, "Example pattern should match example text")
204+
205+
local formatted = caps:format("year=$year, month=$month, day=$day")
206+
print(formatted) -- "year=2010, month=03, day=14"
207+
```
208+
209+
#### Parameters
210+
211+
- `self` RegexCaptures
212+
213+
- `format` `string` The format string to use
214+
215+
#### Returns
216+
217+
- `string` The formatted string
218+
219+
---
220+
221+
# RegexMatch
222+
223+
A match from a regular expression.
224+
225+
Contains the following values:
226+
227+
- `start` -- The start index of the match in the original string.
228+
- `finish` -- The end index of the match in the original string.
229+
- `text` -- The text that was matched.
230+
- `len` -- The length of the text that was matched.

pages/api-reference/stdio.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ stdio.write("Hello, ")
1616
stdio.write("World! ")
1717
stdio.write("All on the same line")
1818
stdio.ewrite("\nAnd some error text, too")
19+
20+
-- Reading the entire input from stdin
21+
local input = stdio.readToEnd()
1922
```
2023

2124
## Functions
@@ -124,3 +127,13 @@ Writes a string directly to stderr, without any newline.
124127
- `s` The string to write to stderr
125128

126129
---
130+
131+
### readToEnd
132+
133+
Reads the entire input from stdin.
134+
135+
#### Returns
136+
137+
- The input from stdin
138+
139+
---

0 commit comments

Comments
 (0)