summaryrefslogtreecommitdiff
path: root/doc/context/sources/general/manuals/lua/lua-mkiv.tex
blob: 25a3d178661e4789fbd55df72b22da55ee19f5b4 (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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
% language=uk

% author    : Hans Hagen
% copyright : PRAGMA ADE & ConTeXt Development Team
% license   : Creative Commons Attribution ShareAlike 4.0 International
% reference : pragma-ade.nl | contextgarden.net | texlive (related) distributions
% origin    : the ConTeXt distribution
%
% comment   : Because this manual is distributed with TeX distributions it comes with a rather
%             liberal license. We try to adapt these documents to upgrades in the (sub)systems
%             that they describe. Using parts of the content otherwise can therefore conflict
%             with existing functionality and we cannot be held responsible for that. Many of
%             the manuals contain characteristic graphics and personal notes or examples that
%             make no sense when used out-of-context.
%
% comment   : Some chapters might have been published in TugBoat, the NTG Maps, the ConTeXt
%             Group journal or otherwise. Thanks to the editors for corrections. Also thanks
%             to users for testing, feedback and corrections.

\usemodule[art-01,abr-02]

\setupbodyfont
  [10pt]

\definecolor
  [maincolor]
  [b=.4]

\usesymbols
  [cc]

\setuptype
  [color=maincolor]

\setuptyping
  [color=maincolor]

\definefont
  [TitlePageFont]
  [file:lmmonolt10-bold.otf]

\setuphead
  [color=maincolor]

\setupinteraction
  [hidden]

\startdocument
  [metadata:author=Hans Hagen,
   metadata:title={Lua, the context libraries},
   author=Hans Hagen,
   affiliation=PRAGMA ADE,
   location=Hasselt NL,
   title=Lua,
   subtitle=the context libraries,
   support=www.contextgarden.net,
   website=www.pragma-ade.nl]

\startMPpage

    StartPage ;

    numeric w ; w := bbwidth(Page) ;
    numeric h ; h := bbheight(Page) ;

    fill Page withcolor \MPcolor{maincolor} ;

    draw textext.urt("\TitlePageFont \getvariable{document}{title}")    xsized (0.8w) shifted (.1w,.2h) withcolor .80white ;
    draw textext.top("\TitlePageFont \getvariable{document}{subtitle}") xsized (0.8w) shifted (.5w,.1h) withcolor .60white ;

    StopPage ;

\stopMPpage

\startsubject[title=Contents]

\placelist[section][alternative=a]

\stopsubject

\startsection[title=Introduction]

Once we started the \LUATEX\ project it didn't take long for \CONTEXT\ to use
the \LUA\ language extensively. And so, rather soon, a bunch of libraries
evolved that provided all kind of helpers. Because \LUATEX\ can also act as
a \LUA\ interpreter, and because we have \type {mtxrun} as script runner
we can also use some of those libraries outside \CONTEXT. So, for me, a rather
natural way to run a \LUA\ script is:

\starttyping
mtxrun --script myscript.lua <optional arguments>
\stoptyping

The advantage of this approach is that you operate in the same file domain as
your \TEX\ runs as all file locators are preloaded as well. However, in some
cases this is not possible, for instance when you run a stock \LUA\ or some
embedded version. For this we provide an alternative mechanism.

\stopsection

\startsection[title=Making libraries]

In the \CONTEXT\ distribution there is a script called \type {mtxlibs.lua} that
can create a library for you that has the basic general purpose \CONTEXT\
libraries on board, as well as whatever more you specify.

\starttyping
lua mtxlibs.lua --selfmerge  myproject-a-libs.lua
lua mtxlibs.lua --selfmerge  myproject-b-libs.lua \
    trac-lmx
lua mtxlibs.lua --selfmerge  myproject-c-libs.lua \
    util-sql util-sql-imp-client util-sql-imp-library
\stoptyping

Here we create three libs. The first one has only the core libraries. You can
read more about what they provide in the \type {cld-mkiv.pdf} manual. The second
library includes code for creating web pages. The third variant preloads \SQL\
support.

You can best run this file in its own directory, in the \CONTEXT\ tree, so that
it knows where to find the libraries needed. Of course you can put the result
everywhere you want, preferably alongside your normal scripts. As we merge code,
this is a rather good way to prevent compatibility issues. After all, some of
the code might get improved.

You can \type {require("mtxlibs")} directly in which case it will load the core
libraries runtime. Of course this means that \LUA\ should be able to figure out
where it can find them.

\stopsection

\startsubject[title={Colofon}]

\starttabulate[|B|p|]
\NC author    \NC \getvariable{document}{author}, \getvariable{document}{affiliation}, \getvariable{document}{location} \NC \NR
\NC version   \NC \currentdate \NC \NR
\NC website   \NC \getvariable{document}{website} \endash\ \getvariable{document}{support} \NC \NR
\NC copyright \NC \symbol[cc][cc-by-sa-nc] \NC \NR
\stoptabulate

\stopsubject

\stopdocument