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
70
71
72
73
74
75
76
77
78
79
80
81
|
if not modules then modules = { } end modules ['data-vir'] = {
version = 1.001,
comment = "companion to luat-lib.mkiv",
author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
copyright = "PRAGMA ADE / ConTeXt Development Team",
license = "see context related readme files"
}
local format = string.format
local trace_virtual = false
local report_resolvers = logs.new("resolvers")
trackers.register("resolvers.locating", function(v) trace_virtual = v end)
trackers.register("resolvers.virtual", function(v) trace_virtual = v end)
local resolvers = resolvers
local finders, openers, loaders, savers = resolvers.finders, resolvers.openers, resolvers.loaders, resolvers.savers
local data, n, template = { }, 0, "virtual://%s.%s" -- hm, number can be query
function savers.virtual(specification,content)
n = n + 1 -- one number for all namespaces
local path = specification.path
local filename = format(template,path ~= "" and path or "virtualfile",n)
if trace_virtual then
report_resolvers("virtual saver: file '%s' saved",filename)
end
data[filename] = content
return filename
end
function finders.virtual(specification)
local original = specification.original
local d = data[original]
if d then
if trace_virtual then
report_resolvers("virtual finder: file '%s' found",original)
end
return original
else
if trace_virtual then
report_resolvers("virtual finder: unknown file '%s'",original)
end
return finders.notfound()
end
end
function openers.virtual(specification)
local original = specification.original
local d = data[original]
if d then
if trace_virtual then
report_resolvers("virtual opener, file '%s' opened",original)
end
data[original] = nil
return openers.helpers.textopener("virtual",original,d)
else
if trace_virtual then
report_resolvers("virtual opener, file '%s' not found",original)
end
return openers.notfound()
end
end
function loaders.virtual(specification)
local original = specification.original
local d = data[original]
if d then
if trace_virtual then
report_resolvers("virtual loader, file '%s' loaded",original)
end
data[original] = nil
return true, d, #d
end
if trace_virtual then
report_resolvers("virtual loader, file '%s' not loaded",original)
end
return loaders.notfound()
end
|