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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
|
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 registerdirect = metapost.registerdirect
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("currentmpcategory") .. ":" .. scanmpstring())) end)
-- registerscript("mpv_dimension", function() return getmacro(mpgnamespace .. getmacro("currentmpcategory") .. ":" .. scanmpstring()) end)
-- registerscript("mpv_string", function() injectstring (getmacro(mpgnamespace .. getmacro("currentmpcategory") .. ":" .. scanmpstring())) end)
-- registerscript("mpvar", function() return getmacro(mpgnamespace .. getmacro("currentmpcategory") .. ":" .. scanmpstring(), true) end) -- Isn't it already edef'd?
-- registerscript("mpvar", function() return getmacro(metapost.namespace .. scanmpstring(), true) end) -- Isn't it already edef'd?
local scanstring = mp.scan.string
local expandtex = mp.expandtex
local injectnumeric = mp.inject.numeric
local injectstring = mp.inject.string
local injectboolean = mp.inject.boolean
local tokenvalues = tokens.values
local dimension_value = tokenvalues.dimension
local integer_value = tokenvalues.integer
local boolean_value = tokenvalues.boolean
local string_value = tokenvalues.string
local unknown_value = tokenvalues.none
registerdirect("mpvard", function()
if not expandtex(dimension_value,"mpcategoryparameter",true,scanstring()) then
injectnumeric(0)
end
end)
registerdirect("mpvarn", function()
if not expandtex(integer_value, "mpcategoryparameter",true,scanstring(),0) then
injectnumeric(0)
end
end)
registerdirect("mpvars", function()
if not expandtex(string_value, "mpcategoryparameter",true,scanstring(),"") then
injectstring("")
end
end)
registerdirect("mpvarb", function()
if not expandtex(boolean_value, "mpcategoryparameter",true,scanstring(),false) then
injectboolean(false)
end
end)
registerdirect("mpvar", function()
if not expandtex(unknown_value, "mpcategoryparameter",true,scanstring(),0) then
injectnumeric(0)
end
end)
|