1if 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
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31local context = context
32
33local create = coroutine.create
34local yield = coroutine.yield
35local resume = coroutine.resume
36local status = coroutine.status
37
38local stepper = nil
39local stack = { }
40local depth = 0
41
42local 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)
49end
50
51interfaces.implement {
52 name = "step",
53 actions = nextstep,
54}
55
56local ctx_resume = context.protected.cs.clf_step
57
58local closeinput = texio.closeinput
59local closeindeed = true
60local stepsindeed = true
61
62directives.register("context.steps.nosteps",function(v) stepsindeed = not v end)
63directives.register("context.steps.noclose",function(v) closeindeed = not v end)
64
65if closeinput then
66
67 function context.step(first,...)
68 if first ~= nil then
69 context(first,...)
70 end
71if stepper then
72 ctx_resume()
73 yield()
74 if closeindeed then
75 closeinput()
76 end
77end
78 end
79
80else
81
82 function context.step(first,...)
83 if first ~= nil then
84 context(first,...)
85 end
86if stepper then
87 ctx_resume()
88 yield()
89end
90 end
91
92end
93
94function context.stepwise(f)
95 if stepsindeed then
96 depth = depth + 1
97 stack[depth] = stepper
98 stepper = create(f)
99
100 ctx_resume()
101 else
102 f()
103 end
104end
105 |