lua-users home
lua-l archive

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


Steve's chained method calls that apply to all elements in a collection [2],

  S{'[one]','[two]','[three]'}:sub(2,-2):upper():printall() -->
output: ONE TWO THREE

reminded me of jQuery [3].  I think there may be other applications of
this design pattern.  As a test, [1] implements a basic string
pattern/substitution library along this idea.

  assert(
    sq('<p>this is a <a href="/">test</a> http://lua-users.org
http://lua.org </p>')
    :match("<[^>]*>")
    :invert()
    :match('http://[^ ]+')
    :filter('user')
    :replace(function(s) return '<a href="' .. s .. '">' .. s .. '</a>' end)
    == '<p>this is a <a href="/">test</a> <a href="http://lua-users.org";>' ..
       'http://lua-users.org</a> http://lua.org </p>'
  )

Another idea is perhaps to apply it to source code AST transformations
(not unlike XHTML used in jQuery).

[1] http://lua-users.org/wiki/StringQuery
[2] http://lua-users.org/wiki/SequenceAdapters
[3] http://en.wikipedia.org/wiki/JQuery