lua-users home
lua-l archive

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


On 23 November 2013 02:08, Georgios Petsagourakis <petsagouris@gmail.com> wrote:
> Hello lua-l,
>
> I was studying the orbit source and I am having a hard time the lines found
> here:
>
> https://github.com/keplerproject/orbit/blob/master/src/orbit/routes.lua#L22-32
>
> Could anyone help me out understanding this?

The first part of line 22 is calling the `re.compile` function with a
single string argument (parentheses are optional when you call a
function with a single string/table literal as its only argument[1]),
which compiles a regular expression into a standard LPeg pattern. It
then uses LPeg's overloaded `/` (division) operator to turn the
pattern returned by `re.compile` into a function capture[2], which
calls the function defined on lines 23-32 with the captures made by
the pattern as arguments and uses the function's return values as the
results of the capture. It then assigns this function capture to the
new local variable `param`.

I don't know enough about LPeg to tell you exactly what that function
does, but hopefully the above explanation helps.

[1] http://www.lua.org/manual/5.2/manual.html#3.4.9
[2] http://www.inf.puc-rio.br/~roberto/lpeg/lpeg.html#cap-func