lua-mkiv.tex /size: 4680 b    last modification: 2023-12-21 09:43
1% language=us runpath=texruns:manuals/lua
2
3% author    : Hans Hagen
4% copyright : ConTeXt Development Team
5% license   : Creative Commons Attribution ShareAlike 4.0 International
6% reference : pragma-ade.nl | contextgarden.net | texlive (related) distributions
7% origin    : the ConTeXt distribution
8%
9% comment   : Because this manual is distributed with TeX distributions it comes with a rather
10%             liberal license. We try to adapt these documents to upgrades in the (sub)systems
11%             that they describe. Using parts of the content otherwise can therefore conflict
12%             with existing functionality and we cannot be held responsible for that. Many of
13%             the manuals contain characteristic graphics and personal notes or examples that
14%             make no sense when used out-of-context.
15%
16% comment   : Some chapters might have been published in TugBoat, the NTG Maps, the ConTeXt
17%             Group journal or otherwise. Thanks to the editors for corrections. Also thanks
18%             to users for testing, feedback and corrections.
19
20\usemodule[art-01,abr-02]
21
22\setupbodyfont
23  [10pt]
24
25\definecolor
26  [maincolor]
27  [b=.4]
28
29\usesymbols
30  [cc]
31
32\setuptype
33  [color=maincolor]
34
35\setuptyping
36  [color=maincolor]
37
38\definefont
39  [TitlePageFont]
40  [file:lmmonolt10-bold.otf]
41
42\setuphead
43  [color=maincolor]
44
45\setupinteraction
46  [hidden]
47
48\startdocument
49  [metadata:author=Hans Hagen,
50   metadata:title={Lua, the context libraries},
51   author=Hans Hagen,
52   affiliation=PRAGMA ADE,
53   location=Hasselt NL,
54   title=Lua,
55   subtitle=the context libraries,
56   support=www.contextgarden.net,
57   website=www.pragma-ade.nl]
58
59\startMPpage
60
61    StartPage ;
62
63    numeric w ; w := bbwidth(Page) ;
64    numeric h ; h := bbheight(Page) ;
65
66    fill Page withcolor \MPcolor{maincolor} ;
67
68    draw textext.urt("\TitlePageFont \documentvariable{title}")    xsized (0.8w) shifted (.1w,.2h) withcolor .80white ;
69    draw textext.top("\TitlePageFont \documentvariable{subtitle}") xsized (0.8w) shifted (.5w,.1h) withcolor .60white ;
70
71    StopPage ;
72
73\stopMPpage
74
75\startsubject[title=Contents]
76
77\placelist[section][alternative=a]
78
79\stopsubject
80
81\startsection[title=Introduction]
82
83Once we started the \LUATEX\ project it didn't take long for \CONTEXT\ to use
84the \LUA\ language extensively. And so, rather soon, a bunch of libraries
85evolved that provided all kind of helpers. Because \LUATEX\ can also act as
86a \LUA\ interpreter, and because we have \type {mtxrun} as script runner
87we can also use some of those libraries outside \CONTEXT. So, for me, a rather
88natural way to run a \LUA\ script is:
89
90\starttyping
91mtxrun --script myscript.lua <optional arguments>
92\stoptyping
93
94The advantage of this approach is that you operate in the same file domain as
95your \TEX\ runs as all file locators are preloaded as well. However, in some
96cases this is not possible, for instance when you run a stock \LUA\ or some
97embedded version. For this we provide an alternative mechanism.
98
99\stopsection
100
101\startsection[title=Making libraries]
102
103In the \CONTEXT\ distribution there is a script called \type {mtxlibs.lua} that
104can create a library for you that has the basic general purpose \CONTEXT\
105libraries on board, as well as whatever more you specify.
106
107\starttyping
108lua mtxlibs.lua --selfmerge  myproject-a-libs.lua
109lua mtxlibs.lua --selfmerge  myproject-b-libs.lua \
110    trac-lmx
111lua mtxlibs.lua --selfmerge  myproject-c-libs.lua \
112    util-sql util-sql-imp-client util-sql-imp-library
113\stoptyping
114
115Here we create three libs. The first one has only the core libraries. You can
116read more about what they provide in the \type {cld-mkiv.pdf} manual. The second
117library includes code for creating web pages. The third variant preloads \SQL\
118support.
119
120You can best run this file in its own directory, in the \CONTEXT\ tree, so that
121it knows where to find the libraries needed. Of course you can put the result
122everywhere you want, preferably alongside your normal scripts. As we merge code,
123this is a rather good way to prevent compatibility issues. After all, some of
124the code might get improved.
125
126You can \type {require("mtxlibs")} directly in which case it will load the core
127libraries runtime. Of course this means that \LUA\ should be able to figure out
128where it can find them.
129
130\stopsection
131
132\startsubject[title={Colofon}]
133
134\starttabulate[|B|p|]
135\NC author    \NC \documentvariable{author}, \documentvariable{affiliation}, \documentvariable{location} \NC \NR
136\NC version   \NC \currentdate \NC \NR
137\NC website   \NC \documentvariable{website} \endash\ \documentvariable{support} \NC \NR
138\NC copyright \NC \symbol[cc][cc-by-sa] \NC \NR
139\stoptabulate
140
141\stopsubject
142
143\stopdocument
144