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

-- limitation: input levels

-- context.stepwise (function()
--     ...
--     context.step(nil|...)
--     ...
--     context.step(nil|...)
--     ...
--     context.stepwise (function()
--         ...
--         context.step(nil|...)
--         ...
--     context.step(nil|...)
--     ...
--     end)
--     ...
--     context.step(nil|...)
--     ...
--     context.step(nil|...)
--     ...
-- end)

local create   = coroutine.create
local yield    = coroutine.yield
local resume   = coroutine.resume
local status   = coroutine.status

local stepper  = nil
local stack    = { } -- will never be deep so no gc needed
local depth    = 0

local nextstep = function()
    if status(stepper) == "dead" then
        stepper      = stack[depth]
        depth        = depth - 1
        stack[depth] = false
    end
    resume(stepper)
end

interfaces.implement {
    name    = "step",
    actions = nextstep,
}

local cldresume = context.constructcsonly("clf_step")

function context.step(first,...)
    if first ~= nil then
        context(first,...)
    end
    cldresume()
    yield()
end

function context.stepwise(f)
    depth = depth + 1
    stack[depth] = stepper
    stepper = create(f)
    resume(stepper)
end