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

-- path relates stuff ... todo: use a stack (or numeric index to list)

local type = type

local aux            = mp.aux
local mpnumeric      = aux.numeric
local mppair         = aux.pair

local registerscript = metapost.registerscript

local scan           = mp.scan
local get            = mp.get
local scannumber     = scan.number
local scanstring     = scan.string
local scanpath       = scan.path
local scanproperty   = scan.property
local gethashentry   = get.hashentry

local p = nil
local n = 0

registerscript("pathreset", function()
    p = nil
    n = 0
end)

registerscript("pathlengthof", function()
    p = scanpath()
    n = p and #p or 1
    mpnumeric(n)
end)

registerscript("pathpointof", function()
    local i = scannumber()
    if i > 0 and i <= n then
        local pi = p[i]
        mppair(pi[1],pi[2])
    end
end)

registerscript("pathleftof", function()
    local i = scannumber()
    if i > 0 and i <= n then
        local pi = p[i]
        mppair(pi[5],pi[6])
    end
end)

registerscript("pathrightof", function()
    local i = scannumber()
    if i > 0 and i <= n then
        local pn
        if i == 1 then
            pn = p[2] or p[1]
        else
            pn = p[i+1] or p[1]
        end
        mppair(pn[3],pn[4])
    end
end)

local report   = logs.reporter("metapost", "log")
local codes    = metapost.codes
local types    = metapost.types
local procodes = mplib.propertycodes

registerscript("showproperty", function()
    local k, s, p, d = scanproperty()
    if k then
        report("name %a, property %a, command %a, detail %a",s,procodes[p] or "-",codes[k] or "-",types[d] or "-")
    end
end)

registerscript("showhashentry", function()
    local s = scanstring()
    if s then
        local k, p, d = gethashentry(s)
        if k then
            report("name %a, property %a, command %a, detail %a",s,procodes[p] or "-",codes[k] or "-",types[d] or "-")
        end
    end
end)

local getmacro      = tokens.getters.macro
local mpgnamespace  = getmacro("??graphicvariable")

local scanmpstring  = mp.scan.string

local injectnumeric = mp.inject.numeric
local injectstring  = mp.inject.string

-- registerscript("mpv_numeric",   function() injectnumeric  (getmacro(mpgnamespace .. getmacro("currentmpvariableclass") .. ":" .. scanmpstring())) end)
-- registerscript("mpv_dimension", function() return getmacro(mpgnamespace .. getmacro("currentmpvariableclass") .. ":" .. scanmpstring()) end)
-- registerscript("mpv_string",    function() injectstring   (getmacro(mpgnamespace .. getmacro("currentmpvariableclass") .. ":" .. scanmpstring())) end)

registerscript("mpvar", function() return getmacro(mpgnamespace .. getmacro("currentmpvariableclass") .. ":" .. scanmpstring(), true) end) -- Isn't it already edef'd?