[luatex] Getting the extra primitives?
Joseph Wright
joseph.wright at uea.ac.uk
Tue Feb 16 13:14:20 CET 2010
Hello all,
Thanks for the help thus far. I'm now stuck on the next step, I'm
afraid. With a file to build a format something like:
\catcode `\{ = 1 \relax
\catcode `\} = 2 \relax
\catcode `\# = 6 \relax
\catcode `\^ = 7 \relax
\catcode `\^^I = 10 \relax
\begingroup\expandafter\expandafter\expandafter\endgroup
\expandafter\ifx\csname directlua\endcsname\relax
\else
\long\def\pdfstrcmp#1#2{%
\directlua
{%
joseph.strcmp("\luaescapestring{#1}","\luaescapestring{#2}")%
}%
}
\directlua
{
tex.enableprimitives('',tex.extraprimitives ())
module("joseph",package.seeall)
function strcmp(A, B)
if A == B then
tex.write("0")
elseif A < B then
tex.write("-1")
else
tex.write("1")
end
end
}
\fi
\dump
If I then try building the format and using it, with something as simple as
\ifnum\pdfstrcmp{a}{b}=0\TRUE\else\FALSE\fi
I get:
! LuaTeX error <\directlua >:1: attempt to index global 'joseph' (a nil
value)
stack traceback:
<\directlua >:1: in main chunk.
\pdfstrcmp ...ring {#1}","\luaescapestring {#2}")}
<*> \ifnum\pdfstrcmp{a}{b}
=0 \TRUE\else\FALSE\fi
?
Obviously I'm still getting something wrong.
>> (Also, am I correct in thinking that there is no way to avoid needing
>> \unexpanded to get the string comparison "as is"?)
>
> That depends on the actual strings and the current catcode assignments
> of course, but \directlua expands its argument, so yes, if you want to
> compare control sequence names, you will need some way to make sure
> they don't expand automatically.
Just thought I should check: thanks.
--
Joseph Wright
More information about the luatex
mailing list