s-inf-03.mkiv /size: 10 Kb    last modification: 2024-01-16 09:03
1% \nopdfcompression
2
3% \starttext
4%   There is a loop somewhere ... todo.
5% \stoptext
6
7\enablemode[tablet] % whatever that means
8
9\setupbodyfont[dejavu]
10
11\doifelsemode {tablet} {
12
13    \setuppapersize
14      [S6,landscape]
15      [S6,landscape]
16
17    \definefont
18      [TitlePageFont]
19      [MonoBold at 14pt]
20
21    \setupbodyfont
22      [tt,8pt]
23
24} {
25
26    \definefont
27      [TitlePageFont]
28      [MonoBold at 17pt]
29
30    \setupbodyfont
31      [tt]
32
33}
34
35\setuplayout
36  [header=0cm,
37   footer=1cm,
38   backspace=.5cm,
39   topspace=.5cm,
40   width=middle,
41   height=middle]
42
43\setuphead
44  [title]
45  [style=\ttc,
46   interaction=reference]
47
48\definehead
49  [xtitle]
50  [title]
51
52\setuphead
53  [xtitle]
54  [color=darkgreen]
55
56\setupfootertexts
57  [\llap{\goto{\hbox to 5cm{\hss previous}}[previouspage]}%
58   \quad\pagenumber\quad
59   \rlap{\goto{\hbox to 5cm{next\hss}}[nextpage]}]
60
61\ifcase\contextlmtxmode
62    \setupinteraction
63      [title={ConTeXt MkIV}]
64\else
65    \setupinteraction
66      [title={ConTeXt LMTX}]
67\fi
68
69\setupinteraction
70  [state=start,
71   style=,
72   color=,
73   subtitle={Lua modules and functions},
74   author={Hans Hagen - automatically generated},
75   contrastcolor=]
76
77\setupinteractionscreen
78  [option=bookmark]
79
80\placebookmarks
81  [title,xtitle]
82  [force=yes]
83
84\definecolor[darkyellow][r=.5,g=.5,b=0]
85\definecolor[darkgray]  [s=.15]
86
87\nonknuthmode
88
89\starttext
90
91\startbuffer
92\startluacode
93local basiclua = libraries.basiclua
94local basictex = libraries.basictex
95local extratex = libraries.extratex
96local extralua = libraries.extralua
97local obsolete = libraries.obsolete
98
99local find = string.find
100local color, gotolocation = context.color, context["goto"]
101
102for k, v in table.sortedpairs(_G) do
103    if obsolete[k] or find(k,"_") or k == "arg" or k == "utf" then
104        --
105    elseif basiclua[k] then
106        gotolocation(function() color( { "darkred" }, k) end, { k } )
107    elseif extralua[k] then
108        gotolocation(function() color( { "darkgreen" }, k) end, { k } )
109    elseif basictex[k] then
110        gotolocation(function() color( { "darkblue" }, k) end, { k } )
111    elseif extratex[k] then
112        gotolocation(function() color( { "darkyellow" }, k) end, { k } )
113    elseif type(v) == "table" then
114        gotolocation(function() color( { "white" }, k) end, { k } )
115    end
116    context(" ")
117end
118\stopluacode
119\stopbuffer
120
121\setupbackgrounds
122  [page]
123  [background=color,
124   backgroundcolor=darkgray,
125   backgroundoffset=2mm]
126
127\startpagemakeup
128    \vfill
129    \pagereference[global]
130    \startnarrower[10mm]
131        \setupalign[nothyhenated,middle,broad]
132        \TitlePageFont \setupinterlinespace
133        \getbuffer % luabuffer
134        \par
135    \stopnarrower
136    \vfill
137    \vfill
138    \hskip10mm\scale[width=\dimexpr\paperwidth-20mm\relax]{\ttbf\white\ConTeXt\ \ifcase\contextlmtxmode MkIV\else LMTX\fi}
139    \par
140  % \hskip10mm\scale[width=\dimexpr\paperwidth-20mm\relax]{\white \strut Lua infrastructure \emdash\ \currentdate}
141    \vfill
142\stoppagemakeup
143
144\setupbackgrounds
145  [page]
146  [background=]
147
148\startluacode
149local builtin  = libraries.builtin
150local globals  = libraries.globals
151local basiclua = libraries.basiclua
152local basictex = libraries.basictex
153local extratex = libraries.extratex
154local extralua = libraries.extralua
155local obsolete = libraries.obsolete
156
157local sortedkeys = table.sortedkeys
158local mark       = storage.mark
159local marked     = storage.marked
160local gsub       = string.gsub
161local sub        = string.sub
162local byte       = string.byte
163local upper      = string.upper
164
165local skipglobal = table.tohash {
166    "_G", "_M", "_ENV", "",
167    "context", "modules", "global", "arg", "utf", 1,
168    "kpse", "commands", "ffi",
169}
170
171local skipkeys = table.tohash {
172 -- "_cldf_", "_cldn_", "_cldo_",
173    "_clmb_", "_clme_", "_clmm_", "_clmn_", "_clma_", "_clmh_",
174    "_G", "_M", "_ENV", "",
175 -- "global",  "shortcuts",
176    "_VERSION", "_COPYRIGHT", "_DESCRIPTION", "_NAME", "_PACKAGE", "__unload",
177    "__index", "__newindex",
178}
179
180local sameglobal = {
181    ["global"]   = "_G",
182 -- ["commands"] = "cs", -- already gone
183}
184
185-- -- -- -- -- -- -- -- -- -- -- -- --
186-- this should be done internally
187-- -- -- -- -- -- -- -- -- -- -- -- --
188
189for k,v in next, modules do
190    mark(v)
191end
192
193mark(document.arguments)
194mark(environment.arguments)
195mark(environment.engineflags)
196mark(characters.data)
197
198-- -- -- -- -- -- -- -- -- -- -- -- --
199-- -- -- -- -- -- -- -- -- -- -- -- --
200
201local variant = 1 -- all parents
202local variant = 2 -- parent name too
203local variant = 3 -- no parents
204
205local done = { }
206
207local function childtables(key,tab,handler,depth)
208    depth = depth or 1
209    local keys = sortedkeys(tab) -- no sorted_pairs
210    for i=1,#keys do
211        local k = keys[i]
212--      if k ~= "_G" and k ~= "_M" and type(k) == "string" then
213        if not skipkeys[k] and type(k) == "string" then
214            local v = tab[k]
215            local t = type(v)
216            local s = k
217            if variant ~= 3 then
218                s = key and (key .. "." .. s) or s
219            end
220            if t == "table" then
221                if marked(v) then
222                    t = "data"
223                    handler(s,t,depth)
224                elseif done[v] then
225                    -- logs.report("inf-03","key %a in %a already done",k,v)
226                else
227                    done[v] = true
228                    handler(s,t,depth)
229                    if variant == 3 then
230                        childtables(false,v,handler,depth+1)
231                    elseif variant == 2 then
232                        childtables(k,v,handler,depth+1)
233                    else
234                        childtables(s,v,handler,depth+1)
235                    end
236                end
237            else
238                handler(s,t,depth)
239            end
240        end
241    end
242end
243
244local NC, NR = context.NC, context.NR
245local overstrike, rlap, bf = context.overstrike, context.rlap, context.bf
246local color, gotolocation = context.color, context["goto"]
247
248local function cleanup(s)
249    return "\\char" ..byte(s) .. " "
250end
251
252local function handler(k,t,depth)
253    k = gsub(k,"([~#$%%^&{}\\|])",cleanup)
254    NC() rlap("\\quad\\tx\\kern" .. (depth or 0).. "em" .. upper(sub(t,1,1)) .. " ".. k) NC() NC() NR()
255end
256
257local function show(title,subtitle,alias,builtin,t,lib,libcolor,glo,glocolor,mark,obsolete)
258    -- todo: table as argument
259 -- print(title,subtitle,alias,builtin,t,lib,libcolor,glo,glocolor,mark,obsolete)
260    local keys = sortedkeys(t) -- no sorted_pairs
261    if #keys > 0 then
262        local fulltitle = title
263        if subtitle and subtitle ~= "" then
264            fulltitle = fulltitle .. " (" .. subtitle .. ")"
265        end
266        if alias and alias ~= "" then
267            fulltitle = fulltitle .. " (alias: " .. alias .. ")"
268        end
269        if builtin then
270            context.startxtitle { reference = title, title = fulltitle, backreference = "global" }
271        else
272            context.starttitle  { reference = title, title = fulltitle, backreference = "global" }
273        end
274        context.startcolumns { n = 2 }
275        context.starttabulate { "|||" }
276        local t_obsolete = rawget(t,"obsolete") -- tricky a t.obsolete fails
277        if type(t_obsolete) ~= "table" then
278            t_obsolete = nil
279        end
280        for i=1,#keys do
281            local k = keys[i]
282            local v = t[k]
283            if k and k ~= "obsolete" and not skipkeys[k] and (not obsolete or not obsolete[k]) then
284                local inlib = lib and lib[k]
285                local inglo = glo and glo[k]
286                local t = type(v)
287                local kstr, tstr = k, t
288                local obs = t_obsolete and t_obsolete[k]
289                if obs then
290                    tstr = function() overstrike(t) end
291                    kstr = function() overstrike(k) end
292                end
293                local marked = marked(v)
294                if marked then
295                    tstr = "data table"
296                end
297                if t == "table" then
298                    local m = getmetatable(v)
299                    if m and m.__call then
300                        tstr = "function"
301                    end
302                end
303                if not mark then
304                    --
305                elseif inlib and tostring(inlib) ~= tostring(v) then
306                    tstr = "overloaded ".. tstr
307                elseif inglo and tostring(inglo) ~= tostring(v) then
308                    tstr = "overloaded ".. tstr
309                end
310                NC() bf()
311                if inlib then
312                    if not mark and t == "table" then
313                        gotolocation(function() color( { libcolor }, kstr) end, { k } )
314                    else
315                        color( { libcolor }, kstr)
316                    end
317                elseif inglo then
318                    if not mark and t == "table" then
319                        gotolocation(function() color( { glocolor }, kstr) end, { k } )
320                    else
321                        color( { glocolor }, kstr)
322                    end
323                else
324                    if not mark and t == "table" then
325                        gotolocation(k, { kstr } )
326                    else
327                        context(kstr)
328                    end
329                end
330                NC()
331                if inlib then
332                    color( { libcolor }, tstr)
333                elseif inglo then
334                    color( { glocolor }, tstr)
335                else
336                    context(tstr)
337                end
338                NC() NR()
339                if mark and t == "table" and title ~= "libraries" and title ~= "package" and not marked then
340                    childtables(false,v,handler) -- (k,v,handler)
341                end
342            end
343        end
344        context.stoptabulate()
345        context.stopcolumns()
346        if builtin then
347            context.stopxtitle()
348        else
349            context.stoptitle()
350        end
351    end
352end
353
354show("global","",sameglobal.global,false,_G,builtin,"darkgreen",globals,"darkblue",false,obsolete)
355
356-- inspect(table.sortedkeys(context))
357
358for k, v in table.sortedpairs(_G) do
359    if not skipglobal[k] and not obsolete[k] and type(v) == "table" and not marked(v) then
360
361 --     local mt = getmetatable(v)
362 --     print("!!!!!!!!!!",k,v,mt,mt and mt.__index)
363
364        if     basiclua[k] then show(k,"basic lua",sameglobal[k],basiclua[k],v,builtin[k],"darkred",   false,false,true)
365        elseif extralua[k] then show(k,"extra lua",sameglobal[k],extralua[k],v,builtin[k],"darkred",   false,false,true)
366        elseif basictex[k] then show(k,"basic tex",sameglobal[k],basictex[k],v,builtin[k],"darkred",   false,false,true)
367        elseif extratex[k] then show(k,"extra tex",sameglobal[k],extratex[k],v,builtin[k],"darkred",   false,false,true)
368        else
369            show(k,"context",  sameglobal[k],false,      v,builtin[k],"darkyellow",false,false,true)
370        end
371    end
372end
373
374\stopluacode
375
376\stoptext
377