aboutsummaryrefslogtreecommitdiff
path: root/win32/bin/LuaRocks.reg.lua
diff options
context:
space:
mode:
Diffstat (limited to 'win32/bin/LuaRocks.reg.lua')
-rw-r--r--win32/bin/LuaRocks.reg.lua51
1 files changed, 51 insertions, 0 deletions
diff --git a/win32/bin/LuaRocks.reg.lua b/win32/bin/LuaRocks.reg.lua
new file mode 100644
index 00000000..2eb7583a
--- /dev/null
+++ b/win32/bin/LuaRocks.reg.lua
@@ -0,0 +1,51 @@
1-- Call this file using its full path and the template file as a parameter;
2--
3-- C:\> lua.exe "create_reg_file.lua" "c:\luarocks\2.0\LuaRocks.reg.template"
4--
5-- it will strip the ".template" extension and write to that file the
6-- template contents, where "<LUAROCKSPATH>" will be replaced by the path
7-- to LuaRocks (including the trailing backslash)
8
9
10
11-- Check argument
12local f = (arg or {})[1]
13if not f then
14 print("must provide template file on command line")
15 os.exit(1)
16end
17
18-- cleanup filepath, remove all double backslashes
19while f:match("\\\\") do
20 f = f:gsub("\\\\", "\\")
21end
22
23-- extract path and name from argument
24local p = ""
25local ni = f
26for i = #f, 1, -1 do
27 if f:sub(i,i) == "\\" then
28 ni = f:sub(i+1)
29 p = f:sub(1, i)
30 break
31 end
32end
33
34-- create output name
35local no = ni:gsub("%.template","")
36
37-- create path substitute; escape backslash by doubles
38local ps = p:gsub("\\", "\\\\")
39
40-- read template
41local fh = io.open(f)
42local content = fh:read("*a")
43fh:close()
44
45-- fill template
46content = content:gsub("%<LUAROCKSPATH%>", ps)
47
48-- write destination file
49fh = io.open(p..no, "w+")
50fh:write(content)
51fh:close()