Commit 7f66f4ad authored by François Perrad's avatar François Perrad
Browse files

allow fnmatch from lunix

parent 1e20a1e7
Pipeline #433185 passed with stages
in 30 seconds
......@@ -2,6 +2,7 @@ Revision history for lua-Silva
0.1.7
- optimize some backtrack (early fail)
- allow fnmatch from lunix
0.1.6 Sat Oct 19 18:30:00 2019
- avoid string methods
......
......@@ -105,6 +105,7 @@ bed:
bed/bin/luarocks install lrexlib-pcre
bed/bin/luarocks install luafilesystem
bed/bin/luarocks install luaposix
bed/bin/luarocks install lunix
bed/bin/luarocks install luacov
hererocks bed --show
bed/bin/luarocks list
......
......@@ -14,7 +14,7 @@ its default value is `'template'`, the following values are handled :
- `'identity'` wraps the Lua string equality (`==`)
- `'lua'` wraps the Lua regex (`string.match`)
- `'pcre'` wraps the PCRE regex from [lrexlib-pcre](https://luarocks.org/modules/rrt/lrexlib-pcre)
- `'shell'` wraps the POSIX `fnmatch()` function (available via FFI or [LuaPosix](https://github.com/luaposix/luaposix) or implemented in plain Lua)
- `'shell'` wraps the POSIX `fnmatch()` function (available via FFI or [lunix](https://github.com/wahern/lunix) or [LuaPosix](https://github.com/luaposix/luaposix) or implemented in plain Lua)
- `'template'` wraps an URI Template ([RFC 6570](https://tools.ietf.org/html/rfc6570) - level 3) regex engine
Each kind of pattern is implemented as a plugin, so this list is easily extensible.
......
......@@ -6,6 +6,7 @@
local modname = string.gsub(..., '%.%w+$', '')
local matcher = require(modname).matcher
local assert = assert
local pcall = pcall
local require = require
local sub = string.sub
......@@ -24,6 +25,21 @@ if r then
end
end)
end
if not match then
local unix
r, unix = pcall(require, 'unix')
if r then
local fnmatch = unix.fnmatch
if fnmatch then
match = function (s, patt)
local _, m = assert(fnmatch(patt, s, -1))
if m then
return s
end
end
end
end
end
if not match then
local posix
r, posix = pcall(require, 'posix.fnmatch')
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment