1if not modules then modules = { } end modules ['luat-cnf'] = {
2 version = 1.001,
3 comment = "companion to luat-lib.mkxl",
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 = type
10local format, concat = string.format, table.concat
11
12local report = logs.reporter("system")
13
14luatex = luatex or { }
15local luatex = luatex
16
17texconfig.functionsize = 32768
18texconfig.propertiessize = 10000
19
20
21
22local stub = [[
23
24-- checking
25
26storage = storage or { }
27luatex = luatex or { }
28
29-- as soon as possible
30
31texconfig.functionsize = 32768
32texconfig.propertiessize = 10000
33
34luatex.starttime = os.gettimeofday()
35
36-- this will happen after the format is loaded
37
38function texconfig.init()
39
40 -- development
41
42 local builtin, globals = { }, { }
43
44 libraries = { -- we set it here as we want libraries also 'indexed'
45 basiclua = {
46 "string", "table", "coroutine", "debug", "file", "io", "lpeg", "math", "os", "package",
47 "utf8",
48 },
49 basictex = {
50 "callback", "font", "lua", "node", "status", "tex", "texconfig", "texio", "token",
51 "font", "language",
52 },
53 extralua = {
54 "library", "luac",
55 "xzip", "xmath", "xcomplex", "xdecimal", "basexx", "posit", "sparse",
56 "md5", "sha2", "aes", "fio", "sio",
57 "lfs","socket",
58 },
59 extratex = {
60 "pdfe", "mplib", "potrace",
61 "pdfdecode", "pngdecode",
62 },
63 optional = {
64 "cerf", "curl", "foreign", "ghostscript", "graphicsmagick", "hb", "imagemagick",
65 "kpse", "lzma", "lzo", "lz4", "mujs", "mysql", "optional", "postgress", "sqlite",
66 "zint", "zstd",
67 },
68 obsolete = {
69 },
70 functions = {
71 "assert", "pcall", "xpcall", "error", "collectgarbage",
72 "dofile", "load","loadfile", "require", "module",
73 "getmetatable", "setmetatable",
74 "ipairs", "pairs", "rawequal", "rawget", "rawset", "next",
75 "tonumber", "tostring",
76 "type", "unpack", "select", "print",
77 },
78 builtin = builtin, -- to be filled
79 globals = globals, -- to be filled
80 }
81
82 for k, v in next, _G do
83 globals[k] = tostring(v)
84 end
85
86 local function collect(t,fnc)
87 local lib = { }
88 for k, v in next, t do
89 if fnc then
90 lib[v] = _G[v]
91 else
92 local keys = { }
93 local gv = _G[v]
94 local tv = type(gv)
95 if tv == "table" then
96 for k, v in next, gv do
97 keys[k] = tostring(v) -- true -- by tostring we cannot call overloads functions (security)
98 end
99 end
100 lib[v] = keys
101 builtin[v] = keys
102 end
103 end
104 return lib
105 end
106
107 libraries.basiclua = collect(libraries.basiclua)
108 libraries.basictex = collect(libraries.basictex)
109 libraries.extralua = collect(libraries.extralua)
110 libraries.extratex = collect(libraries.extratex)
111 libraries.functions = collect(libraries.functions,true)
112 libraries.obsolete = collect(libraries.obsolete)
113 libraries.optional = collect(libraries.optional)
114
115 -- shortcut and helper
116
117 local setbytecode = lua.setbytecode
118 local getbytecode = lua.getbytecode
119 local callbytecode = lua.callbytecode or function(i)
120 local b = getbytecode(i)
121 if type(b) == "function" then
122 b()
123 return true
124 else
125 return false
126 end
127 end
128
129 local function init(start)
130 local i = start
131 local t = os.clock()
132 while true do
133 -- local b = callbytecode(i)
134 local e, b = pcall(callbytecode,i)
135 if not e then
136 print(string.format("fatal error : unable to load bytecode register %%i, maybe wipe the cache first\n",i))
137 os.exit()
138 end
139 if b then
140 setbytecode(i,nil) ;
141 i = i + 1
142 else
143 break
144 end
145 end
146 return i - start, os.clock() - t
147 end
148
149 -- the stored tables and modules
150
151 storage.noftables , storage.toftables = init(0)
152 storage.nofmodules, storage.tofmodules = init(%s)
153
154 if modules then
155 local loaded = package.loaded
156 for module, _ in next, modules do
157 loaded[module] = true
158 end
159 end
160
161 texconfig.init = function() end
162
163end
164
165CONTEXTLMTXMODE = 1
166
167-- we provide a qualified path
168
169callback.register('find_format_file',function(name)
170 texconfig.formatname = name
171 return name
172end)
173
174-- done, from now on input and callbacks are internal
175]]
176
177local keys = {
178 "buffersize", "expandsize", "filesize", "fontsize", "hashsize", "inputsize",
179 "languagesize", "marksize", "insertsize", "nestsize", "nodesize", "parametersize", "poolsize",
180 "savesize", "stringsize", "tokensize", "errorlinesize", "halferrorlinesize", "mvlsize",
181}
182
183local function makestub()
184 local name = environment.jobname .. ".lui"
185 report("creating stub file %a using directives:",name)
186 report()
187 firsttable = firsttable or lua.firstbytecode
188 local t = {
189 "-- This file is generated, don't change it!\n"
190 }
191 for i=1,#keys do
192 local target = keys[i]
193 local key = "luametatex." .. target
194 local val = directives.value(key)
195 if type(val) == "number" then
196 val = { size = val }
197 end
198 if type(val) == "table" then
199 local s = { }
200 local v = val.size if v then s[#s+1] = format("size = %10i",v) end
201 local v = val.plus if v then s[#s+1] = format("plus = %10i",v) end
202 local v = val.step if v then s[#s+1] = format("step = %10i",v) end
203 if #s > 0 then
204 s = format("%-17s = { %s }",target,concat(s,", "))
205 report(" %s",s)
206 t[#t+1] = "texconfig." .. s
207 end
208 end
209 end
210 t[#t+1] = ""
211 t[#t+1] = format(stub,firsttable)
212 io.savedata(name,concat(t,"\n"))
213 report()
214end
215
216lua.registerinitexfinalizer(makestub,"create stub file")
217 |