lua-users home
lua-l archive

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


On Mon, Oct 09, 2006 at 10:53:27AM +0100, Paul Hudson wrote:
> Or even
> 
> 	"Name $fname, Rank: $rankstr, Serial: $sernum" % {fname="Andy",
> rankstr="Captain", sernum=1234}
> 
> 
> which is closer to the original syntax suggestion. I've used this, with a
> function rather than an operator
> 
> -- replace $<whatever> foo in 's' with the value of the corresponding entry
> in 'l'.
> -- (leaving it alone if there is no such key in l so that more than one call
> to expand
> -- can be used to expand all the variables)
> 
> 
> function expand (s, l)
> 	return (string.gsub(s, "$([%w_]+)", 
> 	function (n) 
> 		return l[n] or ("$" .. n)
> 	end))
> end
add l = l or _G a/o array index matching a/o
function printex (s) print(expand(s,_G)) end
and you're done.

Certainly no need for new syntax.