meta-fun.lua /size: 1488 b    last modification: 2020-07-01 14:35
1
if
not
modules
then
modules
=
{
}
end
modules
[
'
meta-fun
'
]
=
{
2
version
=
1
.
001
,
3
comment
=
"
companion to meta-fun.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 9
-- very experimental, actually a joke ... see metafun manual for usage
10 11
local
format
,
load
,
type
=
string
.
format
,
load
,
type
12 13
local
context
=
context
14
local
metapost
=
metapost
15 16
metapost
.
metafun
=
metapost
.
metafun
or
{
}
17
local
metafun
=
metapost
.
metafun
18 19
function
metafun
.
topath
(
t
,
connector
)
20
context
(
"
(
"
)
21
if
#
t
>
0
then
22
for
i
=
1
,
#
t
do
23
if
i
>
1
then
24
context
(
connector
or
"
..
"
)
25
end
26
local
ti
=
t
[
i
]
27
if
type
(
ti
)
=
=
"
string
"
then
28
context
(
ti
)
29
else
30
context
(
"
(%F,%F)
"
,
ti
.
x
or
ti
[
1
]
or
0
,
ti
.
y
or
ti
[
2
]
or
0
)
31
end
32
end
33
else
34
context
(
"
origin
"
)
35
end
36
context
(
"
)
"
)
37
end
38 39
function
metafun
.
interpolate
(
f
,
b
,
e
,
s
,
c
)
40
local
done
=
false
41
context
(
"
(
"
)
42
for
i
=
b
,
e
,
(
e
-
b
)
/
s
do
43
local
d
=
load
(
format
(
"
return function(x) return %s end
"
,
f
)
)
44
if
d
then
45
d
=
d
(
)
46
if
done
then
47
context
(
c
or
"
...
"
)
48
else
49
done
=
true
50
end
51
context
(
"
(%F,%F)
"
,
i
,
d
(
i
)
)
52
end
53
end
54
if
not
done
then
55
context
(
"
origin
"
)
56
end
57
context
(
"
)
"
)
58
end
59