lua-users home
lua-l archive

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



Passing the local variables as a kind-of identity matrix is not too bad:

local me= "asko"
local age= 36

print( "My name is $me and my age is $age." % { me=me, age=age } )

print( "My name is ${me} and my age is ${age}." % { me=me, age=age } )


Global values can be pointed to like such (unless the % operator wants to default fall-back to them):

print( "This is a global value: ${print}" % _G )





On Mon, 09 Oct 2006 06:52:27 -0400
 John Belmonte <john@neggie.net> wrote:
askok@dnainternet.net wrote:
Perl has a STRONG ease in the output of things, by allowing variables to be included in the string itself. This not only is shorter, but most of all much more readable than a lot of ..'s. Could be introduced in Lua as
syntax sugar, using """ and [[[ operations.

... or this can be solved without changing Lua. (By the way, I believe Perl also allows function calls and arbitrary expressions inside
strings, which you do not address.)

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

--John