lua-users home
lua-l archive

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


On Sun, Jul 4, 2010 at 6:48 PM, Alexander Gladysh <agladysh@gmail.com> wrote:
> Here is a script that creates and configures a shared bare Git
> repository with hook to send commit notifications to mailing list:
>    http://github.com/agladysh/misc/blob/master/git/new-shared-git-repo
> ...
> However, I do not like that I've got as a result (not surprising,
> actually). The main problem: it too verbose to be readable.

This:

  os.execute("test -e '" .. PATH .. "'")
  io.stdout:write("--> Setting permissions...\n")

can be rewritten as

  exec "test -e $PATH"
  echo "--> Setting permissions...\n"

under suitable definition of `exec` and `echo` (with caveats on
StringInterpolation mentioned in my last post).

Maybe the ideal is a token filter to directly allow "backtick" things
like `test -e $PATH` : http://lua-users.org/wiki/MetaProgramming .
This also allows handling locals in StringInterpolation more cleanly.

> Do you have (or know) any "shell-script"-like utility code in Lua that
> you want to show?

The need for various utility functions to wrap shell operations is
fairly common, such quoting strings passed to the shell.  See also

  http://lua-users.org/lists/lua-l/2008-09/msg00361.html (e.g. LuaRocks code).
  http://lua-users.org/wiki/FileGlob