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

moduledata.steps = moduledata.steps or { }
local steps      = moduledata.steps

local locations = {
    'lefttop',
    'middletop',
    'righttop',
    'middleleft',
    'middle',
    'middleright',
    'leftbottom',
    'middlebottom',
    'rightbottom',
}

local done, current, previous, n

function steps.reset_locations()
    done, current, previous, n = table.tohash(locations,false), 0, 0, 0
end

function steps.next_location(loc)
    previous = current
    n = n + 1
    loc = loc and loc ~= "" and tonumber(loc)
    while true do
        current = loc or math.random(1,#locations)
        if not done[current] then
            done[current] = true
            break
        end
    end
end

function steps.current_location()
    context(locations[current] or "")
end

function steps.previous_location()
    context(locations[previous] or "")
end

function steps.current_n()
    context(current)
end

function steps.previous_n()
    context(previous)
end

function steps.step()
    context(n)
end

steps.reset_locations()