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
|
-- Run this explicitly through -*- Lua -*-
local lua_bin, inst_share_path, inst_bin_path, inst_mod_path, inst_plugin_path, input_name, output_name = ...
local input_fh = assert(io.open(input_name, "r"))
local output_fh = assert(io.open(output_name, "w"))
local line = input_fh:read "*l"
if not inst_mod_path:match("%?") then
inst_mod_path = inst_mod_path .. "/?.lua"
inst_mod_path = inst_mod_path:gsub("/+", "/")
end
local mod_path_present = false
for path_elem in package.path:gmatch("([^;]+)") do
if path_elem == inst_mod_path then
mod_path_present = true
break
end
end
do
-- transform the plugin path from colon separated to a table
-- for interpolation
local path = {}
for entry in string.gfind(inst_plugin_path, "([^:]+)") do
path[#path+1] = ("%q"):format(entry)
end
inst_plugin_path = ("{%s}"):format(table.concat(path, ", "))
end
while line do
local token = line:match("^%-%- @@(.+)$")
if token then
if token == "SHEBANG" then
output_fh:write(("#!%s\n"):format(lua_bin))
elseif token == "GITANO_LUA_PATH" then
if not mod_path_present then
output_fh:write(("package.path = ('%%s;%%s'):" ..
"format(%q, package.path)" ..
"\n"):format(inst_mod_path))
else
output_fh:write("-- Gitano modules installed into " ..
inst_mod_path .. "\n")
end
elseif token == "GITANO_BIN_PATH" then
output_fh:write(("gitano.config.lib_bin_path(%q)\n"):format(inst_bin_path))
elseif token == "GITANO_SHARE_PATH" then
output_fh:write(("gitano.config.share_path(%q)\n"):format(inst_share_path))
elseif token == "GITANO_PLUGIN_PATH" then
output_fh:write(("gitano.plugins.load_plugins %s\n"):format(inst_plugin_path))
else
output_fh:write("-- Unknown token: " .. token .. "\n")
end
else
output_fh:write(line .. "\n")
end
line = input_fh:read "*l"
end
|