[Dev-luatex] Assignments in Lua

Jonathan Sauer Jonathan.Sauer at silverstroke.com
Fri May 23 13:35:29 CEST 2008


Hello, 

> extending the syntax is not a priority; in principle one can write 
> another input language, map the parsed result onto primitives or lua 
> functions etc etc

That's what I'm doing right now: I have extended the use of "#" inside
the macro body by transforming the macro body to Lua code using lpeg,
compiling this Lua code into a function and calling the function using
a glue macro. Example:

\deflua\repeat#1#2{%
	#{for i = 1, tonumber(p1) do}%
		#(i): #2%
	#{end}%
}

This repeats #2 #1 times and prefixes it with the iteration's number.
It is transformed to (more or less) the following Lua function:

function repeat(p1, p2)
	for i = 1, tonumber(p1) do
		tex.sprint(tostring(i), tostring(p2))
	end
end

The macro \repeat then is:

\repeat#1#2{%
	\directlua0{repeat('\luaescapestring{\unexpanded{#1}}',%
	                   '\luaescapestring{\unexpanded{#2}}')}%
}

Of course, this is slower than a traditional TeX macro.


> Hans

Jonathan



More information about the dev-luatex mailing list