summaryrefslogtreecommitdiff
path: root/src/fontloader/misc/fontloader-basics.tex
blob: 1180c68e6c5e2f3157d795934b8d1960e5ba3897 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
%D \module
%D   [       file=luatex-basics,
%D        version=2009.12.01,
%D          title=\LUATEX\ Support Macros,
%D       subtitle=Attribute Allocation,
%D         author=Hans Hagen,
%D           date=\currentdate,
%D      copyright={PRAGMA ADE \& \CONTEXT\ Development Team}]

%D As soon as we feel the need this file will file will contain an extension
%D to the standard plain register allocation. For the moment we stick to a
%D rather dumb attribute allocator. We start at 256 because we don't want
%D any interference with the attributes used in the font handler.

\ifx\newattribute\undefined \else \endinput \fi

\newcount \lastallocatedattribute \lastallocatedattribute=255

\def\newattribute#1%
  {\global\advance\lastallocatedattribute 1
   \attributedef#1\lastallocatedattribute}

% maybe we will have luatex-basics.lua some day for instance when more
% (pdf) primitives have moved to macros)

\directlua {

    gadgets = gadgets or { } % reserved namespace

    gadgets.functions = { }
    local registered  = {}

    function gadgets.functions.reverve()
        local numb = newtoken.scan_int()
        local name = newtoken.scan_string()
        local okay = string.gsub(name,"[\string\\ ]","")
        registered[okay] = numb
        texio.write_nl("reserving lua function '"..okay.."' with number "..numb)
    end

    function gadgets.functions.register(name,f)
        local okay = string.gsub(name,"[\string\\ ]","")
        local numb = registered[okay]
        if numb then
            texio.write_nl("registering lua function '"..okay.."' with number "..numb)
            lua.get_functions_table()[numb] = f
        else
            texio.write_nl("lua function '"..okay.."' is not reserved")
        end
    end

}

\newcount\lastallocatedluafunction

\def\newluafunction#1%
  {\ifdefined#1\else
     \global\advance\lastallocatedluafunction 1
     \global\chardef#1\lastallocatedluafunction
     \directlua{gadgets.functions.reserve()}#1{\detokenize{#1}}%
   \fi}

% an example of usage (if we ever support it it will go to the plain gadgets module):
%
% \directlua {
%
%     local cct = nil
%     local chr = nil
%
%     gadgets.functions.register("UcharcatLuaOne",function()
%         chr = newtoken.scan_int()
%         cct = tex.getcatcode(chr)
%         tex.setcatcode(chr,newtoken.scan_int())
%         tex.sprint(unicode.utf8.char(chr))
%     end)
%
%     gadgets.functions.register("UcharcatLuaTwo",function()
%         tex.setcatcode(chr,cct)
%     end)
%
% }
%
% \def\Ucharcat
%   {\expandafter\expandafter\expandafter\luafunction
%    \expandafter\expandafter\expandafter\UcharcatLuaTwo
%    \luafunction\UcharcatLuaOne}
%
% A:\the\catcode65:\Ucharcat 65 11:A:\the\catcode65\par
% A:\the\catcode65:\Ucharcat 65  5:A:\the\catcode65\par
% A:\the\catcode65:\Ucharcat 65 11:A:\the\catcode65\par


\endinput