lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

2015-05-17 12:36 GMT+02:00 Daurnimator <>:
> Today I was working on an lpeg pattern, and ran into this oddity,
> which I believe to be a bug.
> I've condensed it down as far as I could, if I remove any more the bug
> seems to disappear.
> The following script throws in the assert.
> If you uncomment either of the alternate `path_abempty` definitions, it works.
> local lpeg = require "lpeg"
> local P = lpeg.P
> local HEXDIG = lpeg.R("09","af", "AF")
> local pct_encoded = P"%" * lpeg.C ( HEXDIG * HEXDIG ) / function (hex_num)
> return string.char(tonumber(hex_num, 16))
> end
> local pchar         = lpeg.R("az","AZ") + pct_encoded
> local path_abempty  = ( P"/" * pchar^0 )^0
> -- local path_abempty  = ( P"/" * pchar^0 )^0 * ( P"/" * pchar^0 )^0
> -- local path_abempty  = ( P"/" * pchar^0 )^0 * function() return true end
> local path_rootless = pchar^1 * path_abempty
> local path_absolute = P"/" * path_rootless^-1
> assert(lpeg.Cs ( path_absolute ):match "/var/log/messages" ==
> "/var/log/messages")

I don't even get this far. A freshly built LPEG does not load.
This is 64-bit Ubuntu 14.04 with Lua 5.3 installed under the
default directory /usr/local.

$ sudo luarocks install lpeg
[sudo] password for dirk:
Using switching
to 'build' mode
gcc -O2 -fPIC -I/home/dirk/include -c lpcap.c -o lpcap.o
gcc -O2 -fPIC -I/home/dirk/include -c lpcode.c -o lpcode.o
gcc -O2 -fPIC -I/home/dirk/include -c lpprint.c -o lpprint.o
gcc -O2 -fPIC -I/home/dirk/include -c lptree.c -o lptree.o
gcc -O2 -fPIC -I/home/dirk/include -c lpvm.c -o lpvm.o
gcc -shared -o -L/home/dirk/lib lpcap.o lpcode.o lpprint.o
lptree.o lpvm.o
Updating manifest for /usr/local/lib/luarocks/rocks
lpeg 0.12.2-1 is now built and installed in /usr/local (license: MIT/X11)

$ luarocks show lpeg

LPeg 0.12.2-1 - Parsing Expression Grammars For Lua

LPeg is a new pattern-matching library for Lua, based on Parsing Expression
Grammars (PEGs). The nice thing about PEGs is that it has a formal basis
(instead of being an ad-hoc set of features), allows an efficient and simple
implementation, and does most things we expect from a pattern-matching library
(and more, as we can define entire grammars).

License:     MIT/X11
Installed in:     /usr/local

    lpeg (/usr/local/lib/lua/5.3/
    re (/usr/local/share/lua/5.3/re.lua)

$ lua -v -l lpeg
Lua 5.3.0  Copyright (C) 1994-2015, PUC-Rio
lua: error loading module 'lpeg' from file '/usr/local/lib/lua/5.3/':
    /usr/local/lib/lua/5.3/ undefined symbol: lua_replace
stack traceback:
    [C]: in ?
    [C]: in function 'require'
    [C]: in ?