It is not possible to fully emulate the fnmatch() function LUA regular expressions.
I've been using a patched version of FLUA for some time, since I need it to match package names against COBFLICTS patterns in port Makefiles.
It is generally useful to match file names read from files against glob patterns, without these files necessarily existing on a file system.
Adding this function increases the binary size of flua by less than 1 KB on amd64.
Details
- Reviewers
kevans markj imp - Commits
- rGf35ccf46c7c6: flua: lposix: add fnmatch function
Apply the patch and rebuild flua.
Test that fnmatch can be used:
local fnmatch = require ("posix.fnmatch")
print ("no match result=", fnmatch.FNM_NOMATCH) -- expect 1
print (fnmatch.fnmatch("*.so.*", "bash")) -- expect 1
print (fnmatch.fnmatch("*.so.*", "libc.so.7")) -- expect 0
Diff Detail
- Repository
- rG FreeBSD src repository
- Lint
Lint Not Applicable - Unit
Tests Not Applicable
Event Timeline
Looks ok to me aside from a question.
libexec/flua/modules/lposix.c | ||
---|---|---|
179 | Should flags be a lua_Integer? Otherwise we are silently truncating here. |
libexec/flua/modules/lposix.c | ||
---|---|---|
179 | The types of the local variables are copied from the lua-posix module, where flags is also "int". |
libexec/flua/modules/lposix.c | ||
---|---|---|
179 | Right, but in lua one can pass an integer larger than INT_MAX, and it'll get silently truncated here. At least, I believe that can happen, or am I missing something? |
libexec/flua/modules/lposix.c | ||
---|---|---|
179 | Correct, but flags is only defined in the range 0..7, and the C function only ever accesses the lowest 3 bits of the value. All higher bits are ignored, truncation will not cause any issues, AFAIU. Please let me know whether I misunderstand the effect of truncation - I'll hold back the commit until there is agreement about this being an issue or not ... |