[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: variable interpolation into literal strings?
- From: Bennett Todd <bet@...>
- Date: Fri, 5 Sep 2003 11:00:18 -0400
I'm just getting started doing my first real thing with Lua.
I'm creating a new software package management system; I think it's
time for something simpler than rpm.
Naturally, the first problem that has to be solved is the spec file
parser, and naturally I chose Lua for that:-).
Here's a sample spec file for my current prototype lashup:
name = "bash";
version = "2.05b";
nv = name .. version; -- name-version, helper for below
sf = nv .. ".tar.gz"; -- source filename, similarly
url = "http://mirrors.kernel.org/gnu/" .. name .. "/" .. sf;
build = "tar xzvf " .. sf .. " && cd " .. nv .. [[ &&
./configure --enable-static-link --prefix=/usr --with-curses &&
make && make prefix=$BPM_ROOT install
]];
The "nv" and "sv" variables aren't actually needed by the packaging
system, they're just there to make the url and build string building
less tedious.
This:
url = "http://mirrors.kernel.org/gnu/" .. name .. "/" .. name .. "-" ..
version .. ".tar.gz";
I call tedious. And the build string gets even worse.
Would that I could do something like
url = "http://mirrors.kernel.org/gnu/%{name}/%{name}-%{version}.tar.gz";
(rpm syntax), or anything vaguely comparable. I'd really prefer that
over having to stop the string, use the concatenation operator, and
restart the string each time.
Does anybody have any brilliant hack for arranging for nice
generalized variable interpolation into strings? I can of course
take other approaches, e.g.
name = "bash";
version = "2.05b";
nv = name .. version; -- name-version, helper for below
sf = nv .. ".tar.gz"; -- source filename, similarly
url = string.format("http://mirrors.kernel.org/gnu/%s/%s", name, sf);
build = string.format([[tar xzvf %s && cd %s &&
./configure --enable-static-link --prefix=/usr --with-curses &&
make && make prefix=$BPM_ROOT install
]], sf, nv);
or explicitly invoking string.gsub, but all of these alternatives,
at least to my tastes, make the resulting spec file a bit more
opaque --- especially to people who aren't fluent in Lua.
-Bennett
Attachment:
pgplUG9QT_3ZD.pgp
Description: PGP signature