summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/context/base/luat-cnf.lua
blob: e45aceb79f43d950b9cd9ae63deb2b1502b490b3 (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
if not modules then modules = { } end modules ['luat-cnf'] = {
    version   = 1.001,
    comment   = "companion to luat-lib.mkiv",
    author    = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
    copyright = "PRAGMA ADE / ConTeXt Development Team",
    license   = "see context related readme files"
}

local format, concat, find = string.format, table.concat, string.find

luatex = luatex or { }

luatex.variablenames = {
    'main_memory', 'extra_mem_bot', 'extra_mem_top',
    'buf_size','expand_depth',
    'font_max', 'font_mem_size',
    'hash_extra', 'max_strings', 'pool_free', 'pool_size', 'string_vacancies',
    'obj_tab_size', 'pdf_mem_size', 'dest_names_size',
    'nest_size', 'param_size', 'save_size', 'stack_size','expand_depth',
    'trie_size', 'hyph_size', 'max_in_open',
    'ocp_stack_size', 'ocp_list_size', 'ocp_buf_size',
    'max_print_line',
}

function luatex.variables()
    local t, x = { }, nil
    for _,v in next, luatex.variablenames do
        x = resolvers.var_value(v)
        if x and find(x,"^%d+$") then
            t[v] = tonumber(x)
        end
    end
    return t
end

if not luatex.variables_set then
    for k, v in next, luatex.variables() do
        texconfig[k] = v
    end
    luatex.variables_set = true
end

local stub = [[
-- checking

storage = storage or { }
luatex  = luatex  or { }

-- we provide our own file handling

texconfig.kpse_init = false
texconfig.shell_escape = 't'

-- as soon as possible

luatex.starttime = os.gettimeofday()

-- this will happen after the format is loaded

function texconfig.init()

    -- shortcut and helper

    local b = lua.bytecode

    local function init(start)
        local i = start
        while b[i] do
            b[i]() ; b[i] = nil ; i = i + 1
         -- collectgarbage('step')
        end
        return i - start
    end

    -- the stored tables and modules

    storage.noftables  = init(0)
    storage.nofmodules = init(%s)

end

-- we provide a qualified path

callback.register('find_format_file',function(name)
    texconfig.formatname = name
    return name
end)

-- done, from now on input and callbacks are internal
]]

function luatex.dumpstate(name,firsttable)
    if tex and tex.luatexversion < 38 then
        os.remove(name)
    elseif true then
        local t = {
            "-- this file is generated, don't change it\n",
            "-- configuration (can be overloaded later)\n"
        }
        for _,v in next, luatex.variablenames do
            local tv = texconfig[v]
            if tv then
                t[#t+1] = format("texconfig.%s=%s",v,tv)
            end
        end
        io.savedata(name,format("%s\n\n%s",concat(t,"\n"),format(stub,firsttable or 501)))
    else
        io.savedata(name,format(stub,firsttable or 501))
    end
end

texconfig.kpse_init = false
texconfig.max_print_line = 100000
texconfig.max_in_open    = 127
texconfig.shell_escape   = 't'