1if not modules then modules = { } end modules [ ' luat-cnf ' ] = {
2 version = 1 . 001 ,
3 comment = " companion to luat-lib.mkiv " ,
4 author = " Hans Hagen, PRAGMA-ADE, Hasselt NL " ,
5 copyright = " PRAGMA ADE / ConTeXt Development Team " ,
6 license = " see context related readme files "
7}
8
9local type , next , tostring , tonumber = type , next , tostring , tonumber
10local format , concat , find , lower , gsub = string . format , table . concat , string . find , string . lower , string . gsub
11
12local report = logs . reporter ( " system " )
13
14local allocate = utilities . storage . allocate
15
16texconfig . kpse_init = false
17texconfig . shell_escape = ' t '
18
19luatex = luatex or { }
20local luatex = luatex
21
22texconfig . error_line = 79
23texconfig . expand_depth = 10000
24texconfig . half_error_line = 50
25texconfig . hash_extra = 100000
26texconfig . max_in_open = 1000
27texconfig . max_print_line = 100000
28texconfig . max_strings = 500000
29texconfig . nest_size = 1000
30texconfig . param_size = 25000
31texconfig . save_size = 100000
32texconfig . stack_size = 10000
33texconfig . function_size = 32768
34texconfig . properties_size = 10000
35texconfig . fix_mem_init = 750000
36
37local stub = [[
38
39-- checking
40
41storage = storage or { }
42luatex = luatex or { }
43
44-- we provide our own file handling
45
46texconfig.kpse_init = false
47texconfig.shell_escape = 't'
48---------.start_time = tonumber(os.getenv("SOURCE_DATE_EPOCH")) -- not used in context
49
50-- as soon as possible
51
52luatex.starttime = os.gettimeofday()
53
54-- this will happen after the format is loaded
55
56function texconfig.init()
57
58 -- development
59
60 local builtin, globals = { }, { }
61
62 libraries = { -- we set it here as we want libraries also 'indexed'
63 basiclua = {
64 -- always
65 "string", "table", "coroutine", "debug", "file", "io", "lpeg", "math", "os", "package",
66 -- bonus
67 "bit32", "utf8",
68 },
69 basictex = {
70 -- always
71 "callback", "font", "lang", "lua", "node", "status", "tex", "texconfig", "texio", "token",
72 -- not in luametatex
73 "img", "pdf",
74 },
75 extralua = {
76 -- not in luametatex
77 "unicode", "utf", "gzip", "zip", "zlib",
78 -- in luametatex
79 "xzip", "xmath", "xcomplex", "basexx",
80 -- maybe some day in luametatex
81 "lz4", "lzo",
82 -- always (mime can go)
83 "lfs","socket", "mime", "md5", "sha2", "fio", "sio",
84 },
85 extratex = {
86 -- not in luametatex
87 "kpse",
88 -- always
89 "pdfe", "mplib",
90 -- in luametatex
91 "pdfdecode", "pngdecode",
92 },
93 obsolete = {
94 "epdf",
95 "fontloader", -- can be filled by luat-log
96 "kpse",
97 },
98 functions = {
99 "assert", "pcall", "xpcall", "error", "collectgarbage",
100 "dofile", "load","loadfile", "require", "module",
101 "getmetatable", "setmetatable",
102 "ipairs", "pairs", "rawequal", "rawget", "rawset", "next",
103 "tonumber", "tostring",
104 "type", "unpack", "select", "print",
105 },
106 builtin = builtin, -- to be filled
107 globals = globals, -- to be filled
108 }
109
110 for k, v in next, _G do
111 globals[k] = tostring(v)
112 end
113
114 local function collect(t,fnc)
115 local lib = { }
116 for k, v in next, t do
117 if fnc then
118 lib[v] = _G[v]
119 else
120 local keys = { }
121 local gv = _G[v]
122 local tv = type(gv)
123 if tv == "table" then
124 for k, v in next, gv do
125 keys[k] = tostring(v) -- true -- by tostring we cannot call overloads functions (security)
126 end
127 end
128 lib[v] = keys
129 builtin[v] = keys
130 end
131 end
132 return lib
133 end
134
135 libraries.basiclua = collect(libraries.basiclua)
136 libraries.basictex = collect(libraries.basictex)
137 libraries.extralua = collect(libraries.extralua)
138 libraries.extratex = collect(libraries.extratex)
139 libraries.functions = collect(libraries.functions,true)
140 libraries.obsolete = collect(libraries.obsolete)
141
142 -- shortcut and helper
143
144 local setbytecode = lua.setbytecode
145 local getbytecode = lua.getbytecode
146 local callbytecode = lua.callbytecode or function(i)
147 local b = getbytecode(i)
148 if type(b) == "function" then
149 b()
150 return true
151 else
152 return false
153 end
154 end
155
156 local function init(start)
157 local i = start
158 local t = os.clock()
159 while true do
160 -- local b = callbytecode(i)
161 local e, b = pcall(callbytecode,i)
162 if not e then
163 print(string.format("\nfatal error : unable to load bytecode register %%i, maybe wipe the cache first\n",i))
164 os.exit()
165 end
166 if b then
167 setbytecode(i,nil) ;
168 i = i + 1
169 else
170 break
171 end
172 end
173 return i - start, os.clock() - t
174 end
175
176 -- the stored tables and modules
177
178 storage.noftables , storage.toftables = init(0)
179 storage.nofmodules, storage.tofmodules = init(%s)
180
181 if modules then
182 local loaded = package.loaded
183 for module, _ in next, modules do
184 loaded[module] = true
185 end
186 end
187
188 texconfig.init = function() end
189
190end
191
192CONTEXTLMTXMODE = %s
193
194-- we provide a qualified path
195
196callback.register('find_format_file',function(name)
197 texconfig.formatname = name
198 return name
199end)
200
201-- done, from now on input and callbacks are internal
202 ]]
203
204local variablenames = {
205 error_line = false ,
206 half_error_line = false ,
207 max_print_line = false ,
208 max_in_open = false ,
209 expand_depth = true ,
210 hash_extra = true ,
211 nest_size = true ,
212 max_strings = true ,
213 param_size = true ,
214 save_size = true ,
215 stack_size = true ,
216 function_size = true ,
217 properties_size = true ,
218}
219
220local function makestub ( )
221 name = name or ( environment . jobname . . " .lui " )
222 report ( " creating stub file %a using directives: " , name )
223 report ( )
224 firsttable = firsttable or lua . firstbytecode
225 local t = {
226 " -- this file is generated, don't change it\n " ,
227 " -- configuration (can be overloaded later)\n "
228 }
229 for v , permitted in table . sortedhash ( variablenames ) do
230 local d = " luatex. " . . gsub ( lower ( v ) , " [^%a] " , " " )
231 local dv = directives . value ( d )
232 local tv = texconfig [ v ]
233 if dv then
234 if not tv then
235 report ( " %s = %s (%s) " , d , dv , " configured " )
236 tv = dv
237 elseif not permitted then
238 report ( " %s = %s (%s) " , d , tv , " frozen " )
239 elseif tonumber ( dv ) > = tonumber ( tv ) then
240 report ( " %s = %s (%s) " , d , dv , " overloaded " )
241 tv = dv
242 else
243 report ( " %s = %s (%s) " , d , tv , " preset kept " )
244 end
245 elseif tv then
246 report ( " %s = %s (%s) " , d , tv , permitted and " preset " or " frozen " )
247 else
248 report ( " %s = <unset> " , d )
249 end
250 if tv then
251 t [ # t + 1 ] = format ( " texconfig.%s=%s " , v , tv )
252 end
253 end
254 t [ # t + 1 ] = " "
255 t [ # t + 1 ] = format ( stub , firsttable , tostring ( CONTEXTLMTXMODE or 0 ) )
256 io . savedata ( name , concat ( t , " \n " ) )
257 logs . newline ( )
258end
259
260lua . registerfinalizer ( makestub , " create stub file " )
261 |