lua-users home
lua-l archive

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


On Thu, Jan 21, 2010 at 5:47 AM, Luiz Henrique de Figueiredo wrote:
> This reminded me of an experiment I did with using Lua for evaluating command
> lines, for which full Lua syntax is too heavy.
>
> A command line is of the form
>        word arg1 arg2 ... argn
> where the args can be a word or a quoted string. This is converted to
>        word(arg1,arg2,...,argn)
> where the args are converted to strings.

That reminds of one aspect of the make and CMake [1] syntaxes.  In
make, you set a variable to a list of source files like this:

  LIB_O=lauxlib.o lbaselib.o lbitlib.o ldblib.o liolib.o lmathlib.o loslib.o \
             ltablib.o lstrlib.o loadlib.o linit.o $(MORE_O)

In CMake it is a more functional syntax, but there are similarities:

  SET (SRC_LIB src/lauxlib.c src/lbaselib.c src/lbitlib.c src/ldblib.c
          src/linit.c src/liolib.c src/lmathlib.c src/loadlib.c src/loslib.c
          src/lstrlib.c src/ltablib.c ${MORE_O})

If you were to express that in Lua (perhaps Premake [2]), it might be
something like this:

  files {"src/lauxlib.c", "src/lbaselib.c", "src/lbitlib.c",
           "src/ldblib.c", "src/linit.c", "src/liolib.c", "src/lmathlib.c",
           "src/loadlib.c", "src/loslib.c", "src/lstrlib.c",
"src/ltablib.c", unpack(MORE_O)}

There was some discussion about replacing CMake's scripting language
with Lua [3], as Lua-based build systems [4] often do.  I'm not sure
it would be a good idea requiring users to type all the quotes and
commas in the common case just for the added flexibility of Lua syntax
for the exceptional case.  However, one can always keep the VM, adjust
the parser, and maintain a 1-1 equivalence between the two syntaxes,
as Lhf demonstrates.

I would suggest the dollar ($) sign syntax in lcl.c so that you can
can refer to variables.

A similar case is Perl's special qw() operator that makes these two equivalent:

  @x = ('a', 'b', 'c');
  @x = qw(a b c);

In Lua, you can achieve a similar thing by appropriate definition of
`qw` as a function:

  x = qw[[a b c]]

Lua doesn't allow conveniently inserting variables ($) into that, well
at least not lexicals.  Some syntax extension or macro system would
best address that [5].

[1] http://www.itk.org/Wiki/CMake/Language_Syntax
[2] http://industriousone.com/premake
[3] http://lua-users.org/lists/lua-l/2008-02/msg00403.html
[4] http://lua-users.org/wiki/LuaBuildSystems
[5] http://lua-users.org/wiki/StringInterpolation