[luatex] Getting the extra primitives?
Manuel Pégourié-Gonnard
mpg at elzevir.fr
Wed Feb 17 13:58:06 CET 2010
Taco Hoekwater a écrit :
> Yes. A somewhat more generic solution is this:
>
> \directlua
> {
> tex.enableprimitives('',tex.extraprimitives ())
> lua.bytecode[1]=function ()
> function pdfstrcmp (A, B)
> if A == B then
> tex.write("0")
> elseif A < B then
> tex.write("-1")
> else
> tex.write("1")
> end
> end
> end
> lua.bytecode[1]()
> }
> \everyjob{\directlua{lua.bytecode[1]()}}
> \long\def\pdfstrcmp#1#2{%
> \directlua
> {%
> pdfstrcmp("\luaescapestring{#1}","\luaescapestring{#2}")%
> }%
> }
>
If one wants to use an external file for Lua code (which is probably preferable
when the amount of code is bigger than a few lines), a solution might be
\directlua{
lua.bytecode[1]=loadfile("latex3-format.lua")
lua.bytecode[1]()
}
\everyjob{\directlua{lua.bytecode[1]()}}
% TeX code goes here
using the fact that loadfile() returns a function whose body is the content of
the file.
Manuel.
More information about the luatex
mailing list