summaryrefslogtreecommitdiff
path: root/tex/context/base/scrp-ini.mkiv
blob: b3ef7778200680f4da317fe4850d53c187a647d0 (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
%D \module
%D   [       file=scrp-ini,
%D        version=2009.02.06,
%D          title=\CONTEXT\ Script Macros,
%D       subtitle=Initialization,
%D         author=Hans Hagen,
%D           date=\currentdate,
%D      copyright=PRAGMA / Hans Hagen]
%C
%C This module is part of the \CONTEXT\ macro||package and is
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
%C details.

% here we collect code from other places (was organized differently)

\registerctxluafile{scrp-ini}{1.001}
\registerctxluafile{scrp-cjk}{1.001}

\definesystemattribute[preproc][public]
\definesystemattribute[prestat][public]

%D Since scripts need specific \LUA\ code we use hard coded attribute
%D values, but we might have more tricks at some time, so we use a
%D proper define macro too.

\unprotect

\def\s!attribute{attribute}

\def\namedscriptparameter#1#2%
  {\csname\doscriptparameter{\??ls#1}#2\endcsname}

\def\scriptparameter#1%
  {\csname\doscriptparameter{\??ls\currentscript}#1\endcsname}

\def\doscriptparameter#1#2%
  {\ifcsname#1#2\endcsname#1#2\else\expandafter\doscriptparentparameter\csname#1\s!parent\endcsname#2\fi}

\def\doscriptparentparameter#1#2%
  {\ifx#1\relax\s!empty\else\doscriptparameter#1#2\fi}

% \def\scriptparameterhash#1%
%   {\doscriptparameterhash{\??ls\currentscript}#1}
%
% \def\doscriptparameterhash#1#2%
%   {\ifcsname#1#2\endcsname#1\else\expandafter\doscriptparentparameterhash\csname#1\s!parent\endcsname#2\fi}
%
% \def\doscriptparentparameterhash#1#2%
%   {\ifx#1\relax\else\doscriptparameterhash#1#2\fi}

% when #2 == string, then only synonym, no settings

\unexpanded\def\definescript
  {\dodoubleargument\dodefinescript}

\def\dodefinescript[#1][#2]%
  {\doifassignmentelse{#2}
     {\getparameters[\??ls#1][\c!method=,\s!parent=,#2]%
      \doifelsenothing{\namedscriptparameter{#1}\c!method}
        {\letvalue {\??ls#1\s!attribute}\attributeunsetvalue}%
        {\setevalue{\??ls#1\s!attribute}{\ctxlua{scripts.define("\namedscriptparameter{#1}\c!method")}}}}%
     {\getparameters[\??ls#1][\s!parent=#2]}%
   \setvalue{#1}{\dosetscript{#1}}}

\unexpanded\def\setupscript
  {\dodoubleargument\dosetupscript}

\def\dosetupscript[#1][#2]%
  {\getparameters[\??ls#1][#2]}

\def\dosetscript#1%
  {\def\currentscript{#1}%
   \edef\currentscriptattribute{\scriptparameter\s!attribute}%
   \ifx\currentscriptattribute\empty
     \let\currentscript\empty
     \attribute\preprocattribute\attributeunsetvalue
   \else
     \attribute\preprocattribute\currentscriptattribute\relax % we can speed this up by storing the attribute in ??ls:a:#1
   \fi}

           \def\setscript  [#1]{\dosetscript{#1}}
\unexpanded\def\startscript[#1]{\begingroup\dosetscript{#1}}
\unexpanded\def\stopscript     {\endgroup}

% \setscript[hangul] \hangul \startscript[hangul]

\definescript[latin] [\c!method=]        %  resets the attribute
\definescript[hangul][\c!method=hangul]
\definescript[hanzi] [\c!method=hanzi]

\protect \endinput