cldf-stp.lua /size: 2210 b    last modification: 2020-07-01 14:35
1
if
not
modules
then
modules
=
{
}
end
modules
[
'
cldf-stp
'
]
=
{
2
version
=
1
.
001
,
3
comment
=
"
companion to cldf-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 9
-- limitation: input levels
10 11
-- context.stepwise (function()
12
-- ...
13
-- context.step(nil|...)
14
-- ...
15
-- context.step(nil|...)
16
-- ...
17
-- context.stepwise (function()
18
-- ...
19
-- context.step(nil|...)
20
-- ...
21
-- context.step(nil|...)
22
-- ...
23
-- end)
24
-- ...
25
-- context.step(nil|...)
26
-- ...
27
-- context.step(nil|...)
28
-- ...
29
-- end)
30 31
local
context
=
context
32 33
local
create
=
coroutine
.
create
34
local
yield
=
coroutine
.
yield
35
local
resume
=
coroutine
.
resume
36
local
status
=
coroutine
.
status
37 38
local
stepper
=
nil
39
local
stack
=
{
}
-- will never be deep so no gc needed
40
local
depth
=
0
41 42
local
function
nextstep
(
)
43
if
status
(
stepper
)
=
=
"
dead
"
then
44
stepper
=
stack
[
depth
]
45
depth
=
depth
-
1
46
stack
[
depth
]
=
false
47
end
48
resume
(
stepper
)
49
end
50 51
interfaces
.
implement
{
52
name
=
"
step
"
,
53
actions
=
nextstep
,
54
}
55 56
local
ctx_resume
=
context
.
protected
.
cs
.
clf_step
57 58
local
closeinput
=
texio
.
closeinput
-- experiment
59
local
closeindeed
=
true
60
local
stepsindeed
=
true
61 62
directives
.
register
(
"
context.steps.nosteps
"
,
function
(
v
)
stepsindeed
=
not
v
end
)
63
directives
.
register
(
"
context.steps.noclose
"
,
function
(
v
)
closeindeed
=
not
v
end
)
64 65
if
closeinput
then
66 67
function
context
.
step
(
first
,
...
)
68
if
first
~
=
nil
then
69
context
(
first
,
...
)
70
end
71
if
stepper
then
72
ctx_resume
(
)
73
yield
(
)
74
if
closeindeed
then
75
closeinput
(
)
76
end
77
end
78
end
79 80
else
81 82
function
context
.
step
(
first
,
...
)
83
if
first
~
=
nil
then
84
context
(
first
,
...
)
85
end
86
if
stepper
then
87
ctx_resume
(
)
88
yield
(
)
89
end
90
end
91 92
end
93 94
function
context
.
stepwise
(
f
)
95
if
stepsindeed
then
96
depth
=
depth
+
1
97
stack
[
depth
]
=
stepper
98
stepper
=
create
(
f
)
99
-- ctx_resume(stepper)
100
ctx_resume
(
)
101
else
102
f
(
)
103
end
104
end
105