lua-users home
lua-l archive

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


On Mon, Sep 20, 2010 at 11:53 PM, Jonathan Castello <twisolar@gmail.com> wrote:
> On Mon, Sep 20, 2010 at 8:29 PM, Nilson <nilson.brazil@gmail.com> wrote:
>> Proposition 1. Make the separator optional in table initialization
>> Proposition 2. Extending the function name syntactic sugar to tables.
>
> If they're doable, I like these two a lot.

There have been proposals for these before:

  http://lua-users.org/lists/lua-l/2003-02/msg00405.html
  http://lua-users.org/lists/lua-l/2010-01/msg01405.html

  http://lua-users.org/lists/lua-l/2008-02/msg00830.html
  http://lua-users.org/lists/lua-l/2010-08/msg00569.html

And personally, I've wanted something like Proposition 1.  Lisp and
CMake languages allow this simpler syntax.  The major problem it poses
in Lua is that Lua expressions without a commas between them can too
easily run together.  {a "" {}} is valid in Lua 5.1, for example.  The
problem also occurs with statements without semicolons between them
("ambiguous syntax" error) but with a much lower frequency.

You can simulate a Perl-like "qw" quote operator though:

  -- like http://perldoc.perl.org/perlop.html#Quote-Like-Operators
  local function qw(s)
    local t = {}
    for x in s:gmatch("%S+") do
      t[#t+1] = x
    end
    return t
  end

  t = qw[[ foo  bar  baz ]]

Unfortunately, you can't easily embed variables, particularly
lexicals, inside these strings.  That's a common problem, and more
ideally you'd want Lua to expand qw at the macro/lexical processing
stage rather than at run-time:

  http://lua-users.org/wiki/StringInterpolation

>> Proposition 3: Unquoted strings constants

See qw above.