[luatex] Getting the extra primitives?
Taco Hoekwater
taco at elvenkind.com
Wed Feb 17 10:27:11 CET 2010
Joseph Wright wrote:
> On 16/02/2010 15:43, luigi scarso wrote:
>> On Tue, Feb 16, 2010 at 1:14 PM, Joseph
>> Wright<joseph.wright at uea.ac.uk> wrote:
>>> 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.
>>
>> joseph = joseph or { }
>>
>> Next you need to implement strcmp function
>>
>> function joseph.strcmp(A,B)
>> -- your implementation here
>
> Further testing suggests the issue may be slightly different to my
> original explanation. As far as I can tell, if I use \pdfstrcmp as
> defined above during the format-creation process then all is fine (for
> example if I just stick \pdfstrcmp{a}{a} just before \dump): no errors.
> However, if I try to use if after making a format then I get the error
> as described. The conclusion is that the lua part of the set up does not
> survive the format-creation process. This seems to be very odd: am I
> getting something wrong? After all, the whole point of a format is that
> it is a pre-compiled and self-contained entity.
Lua stuff is not saved in the format unless you put in a lua bytecode
register (wrapped in a function). This is inconvenient, I know, but
serializing a whole lua state is a lot of work and therefore not done
(yet?).
Best wishes,
Taco
More information about the luatex
mailing list