catc-ini.lua /size: 1248 b    last modification: 2021-10-28 13:50
1if not modules then modules = { } end modules ['catc-ini'] = {
2    version   = 1.001,
3    comment   = "companion to catc-ini.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
9catcodes         = catcodes         or { }
10catcodes.numbers = catcodes.numbers or { }
11catcodes.names   = catcodes.names   or { }
12
13storage.register("catcodes/numbers", catcodes.numbers, "catcodes.numbers")
14storage.register("catcodes/names",   catcodes.names,   "catcodes.names")
15
16local numbers = catcodes.numbers
17local names   = catcodes.names
18
19-- this only happens at initime
20
21function catcodes.register(name,number)
22    numbers[name] = number
23    local cnn = names[number]
24    if cnn then
25        cnn[#cnn+1] = name
26    else
27        names[number] = { name }
28    end
29    tex[name] = number -- downward compatible
30end
31
32-- this only happens at runtime
33
34for name, number in next, numbers do
35    tex[name] = number -- downward compatible
36end
37
38-- nasty
39
40table.setmetatableindex(numbers,function(t,k) if type(k) == "number" then t[k] = k return k end end)
41table.setmetatableindex(names,  function(t,k) if type(k) == "string" then t[k] = k return k end end)
42