aboutsummaryrefslogtreecommitdiff
path: root/Lua
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2021-09-25 19:05:15 -0700
committerBruce Hill <bruce@bruce-hill.com>2021-09-25 19:05:15 -0700
commit3fe77cbf3eae108a3963f16bf69cb8e06ddc4cbd (patch)
tree3a59be7062d2416d7337518aa38e0d73b5832be4 /Lua
parentfb1840e07a6643a92206abb8a64a33b003ec06a8 (diff)
:eachmatch() -> :matches()
Diffstat (limited to 'Lua')
-rw-r--r--Lua/README.md10
-rw-r--r--Lua/lbp.c10
-rw-r--r--Lua/test.lua4
3 files changed, 12 insertions, 12 deletions
diff --git a/Lua/README.md b/Lua/README.md
index 1288696..3b6124b 100644
--- a/Lua/README.md
+++ b/Lua/README.md
@@ -12,11 +12,11 @@ The Lua `bp` bindings provide the following methods:
bp.match(pattern, text, [start_index]) --> match / nil
bp.replace(pattern, replacement, text, [start_index]) --> text_with_replacements, num_replacements
bp.compile(pattern) --> pattern_object
-for m in bp.eachmatch(pattern, text, [start_index]) do ... end
+for m in bp.matches(pattern, text, [start_index]) do ... end
pattern_object:match(text, [start_index]) --> match / nil
pattern_object:replace(replacement, text, [start_index]) --> text_with_replacements, num_replacements
-for m in pattern_object:eachmatch(text, [start_index]) do ... end
+for m in pattern_object:matches(text, [start_index]) do ... end
```
Match objects returned by `bp.match()` are tables whose `__tostring` will
@@ -32,7 +32,7 @@ unambiguous.
Pattern objects returned by `bp.compile()` are pre-compiled patterns that are
slightly faster to reuse than just calling `bp.match()` repeatedly. They have a
`.source` attribute that holds the original text used to compile them and have
-`:match()`, `:replace()`, and `:eachmatch()` methods as described above.
+`:match()`, `:replace()`, and `:matches()` methods as described above.
All methods will raise an error with a descriptive message if the given pattern
has a syntax error.
@@ -47,13 +47,13 @@ local m = bp.match('"n" @Es=+`e "dle"', "like finding a needle in a haystack")
local replaced, nreplacements = bp.match('"n" +`e "dle"', "cat", "like finding a needle in a haystack")
--> "like finding a cat in a haystack", 1
-for word in bp.eachmatch("+`A-Z,a-z", "one, two three... four!") do
+for word in bp.matches("+`A-Z,a-z", "one, two three... four!") do
print(word) --> prints "one" "two" "three" "four"
end
local pat = bp.compile("word parens")
for _,s in ipairs(my_strings) do
- for fncall in pat:eachmatch(s) do
+ for fncall in pat:matches(s) do
print(fncall)
end
end
diff --git a/Lua/lbp.c b/Lua/lbp.c
index 050d0e8..51ba9d2 100644
--- a/Lua/lbp.c
+++ b/Lua/lbp.c
@@ -3,11 +3,11 @@
* API:
* bp.match(pat, str, [start_index]) -> nil or match_table
* bp.replace(pat, replacement, str, [start_index]) -> str with replacements, num_replacements
-* for match_table in bp.eachmatch(pat, str, [start_index]) do ... end
+* for match_table in bp.matches(pat, str, [start_index]) do ... end
* bp.compile(pat) -> pattern object
* pat:match(str, [start_index])
* pat:replace(replacement, str, [start_index])
-* for match in pat:eachmatch(str, [start_index]) do ... end
+* for match in pat:matches(str, [start_index]) do ... end
*/
#include <fcntl.h>
@@ -240,7 +240,7 @@ static int iter(lua_State *L)
return Lmatch(L);
}
-static int Leachmatch(lua_State *L)
+static int Lmatches(lua_State *L)
{
int nargs = lua_gettop(L);
lua_pushcfunction(L, iter); // iter
@@ -294,7 +294,7 @@ static const luaL_Reg match_metamethods[] = {
static const luaL_Reg pat_methods[] = {
{"match", Lmatch},
{"replace", Lreplace},
- {"eachmatch", Leachmatch},
+ {"matches", Lmatches},
{NULL, NULL}
};
@@ -309,7 +309,7 @@ static const luaL_Reg bp_methods[] = {
{"match", Lmatch},
{"replace", Lreplace},
{"compile", Lcompile},
- {"eachmatch", Leachmatch},
+ {"matches", Lmatches},
{NULL, NULL}
};
diff --git a/Lua/test.lua b/Lua/test.lua
index 3e13f55..792a534 100644
--- a/Lua/test.lua
+++ b/Lua/test.lua
@@ -13,7 +13,7 @@ local function repr(obj)
end
print("Matching:")
-for m in bp.eachmatch("(*`a-z) => '(@0)'", "one two three") do
+for m in bp.matches("(*`a-z) => '(@0)'", "one two three") do
print(repr(m))
end
@@ -45,6 +45,6 @@ print(pat:match("...foo..."))
print(pat:match("...baz..."))
print(pat:replace("{@0}", "...baz..."))
-for m in pat:eachmatch("hello world") do
+for m in pat:matches("hello world") do
print(m)
end