lua-users home
lua-l archive

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


On Thu, Mar 10, 2011 at 4:11 PM, Jayanth Acharya <jayachar88@gmail.com> wrote:
> local struct = require(_NAME:match("^[^%.]+"))
> local name = (...):gsub('%.[^%.]+$', '')
>
> [...] What does the _NAME:match() do ?
> What does "(...):gsub(pattern...)" do ?

Personally, I've also found quite late about it, but:
  http://www.lua.org/manual/5.1/manual.html#5.4
  "The string library [...] sets a metatable for strings where the
__index field points to the string table. Therefore, you can use the
string functions in object-oriented style. For instance,
string.byte(s, i) can be written as s:byte(i)."

Note however, that for string literals (and probably some other
constructs, like the ellipsis in your example - I don't know where's
that mentioned in the manual) to be used in such a way you have to
enclose them in additional parentheses - like that:
  print( ('i=%d'):format(i) )

Other thing is, that IIRC in a module the ellipsis expands to the full
list of arguments present in the require(...) call which included the
module (thus, the verbatim (...) evaluates to more or less the name of
the module).

For _NAME, you should probably see:
http://www.lua.org/manual/5.1/manual.html#pdf-module

Hope this helps.
/Mateusz Czapliński