This is a custom build of the LPeg library for LuaJIT on macOS, using FFI for loading.
- Copy
lpeg.luaandlpeg_ffi.soto your Lua package path (e.g.,/usr/local/lib/lua/5.1/or a local directory). - Ensure both files are in the same directory.
local lpeg = require("lpeg")
-- Use lpeg functions as usualThe module exposes the standard LPeg API. See the official documentation for details.
lpeg.match(pattern, subject [, init]): Matches a pattern against a string.lpeg.P(value): Converts a value into a pattern.lpeg.R(range): Matches a range of characters.lpeg.S(set): Matches any character in a set.lpeg.C(pattern): Captures the match.lpeg.Ct(pattern): Captures the match as a table.
To build the shared library from source:
gcc -O2 -bundle -undefined dynamic_lookup -I/opt/homebrew/include/luajit-2.1 -o lpeg_ffi.so lpeg-src/*.c- The build command assumes you have LuaJIT installed in
/opt/homebrew/include/luajit-2.1. Adjust the path if your LuaJIT installation is in a different location. - This build is specifically for macOS. For other platforms, you may need to adjust the build flags.