[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: expand text using locals
- From: David Manura <dm.lua@...>
- Date: Wed, 13 May 2009 19:43:40 -0400
On Wed, May 13, 2009 at 6:32 PM, Luiz Henrique de Figueiredo wrote:
>> Is there a way to write an expand function that make use of the local variables (not global)?
>> function do_stuff (p1) print(expand'$(p1+1)') end
> You could use the debug library for that, though its use for ordinary
> programming is not recommended. If you have control over do_stuff, then
> you could created a table with the values of the locals before calling
> expand and pass it to expand.
Using debug to access lexicals is demonstrated under "Using debug to
Access Lexicals" in . It's indeed considered a hack. Both  and
 illustrate the approach of passing values as function arguments,
which is hackish.
A number of times I've felt that there should be some language support
for putting variables in strings. The basic problem occurs in a
number of places [1-5] . The way I think it should work is that
f [[a %(b) c %(d) e]]
would be equivalent to
f( [[a %(1) c %(2) e]], b, d)
It can be done in Metalua though, along the lines of the string
interpolation solution . This is also probably simple enough to do
with a lighter weight solution like token filtering.
 http://lua-users.org/wiki/TableScope (near ShortAnonymousFunctions )
 http://lua-users.org/wiki/VarExpand (templatizing)