diff options
Diffstat (limited to 'win32/LuaRocks.reg.lua')
| -rw-r--r-- | win32/LuaRocks.reg.lua | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/win32/LuaRocks.reg.lua b/win32/LuaRocks.reg.lua new file mode 100644 index 00000000..2eb7583a --- /dev/null +++ b/win32/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 | ||
| 12 | local f = (arg or {})[1] | ||
| 13 | if not f then | ||
| 14 | print("must provide template file on command line") | ||
| 15 | os.exit(1) | ||
| 16 | end | ||
| 17 | |||
| 18 | -- cleanup filepath, remove all double backslashes | ||
| 19 | while f:match("\\\\") do | ||
| 20 | f = f:gsub("\\\\", "\\") | ||
| 21 | end | ||
| 22 | |||
| 23 | -- extract path and name from argument | ||
| 24 | local p = "" | ||
| 25 | local ni = f | ||
| 26 | for 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 | ||
| 32 | end | ||
| 33 | |||
| 34 | -- create output name | ||
| 35 | local no = ni:gsub("%.template","") | ||
| 36 | |||
| 37 | -- create path substitute; escape backslash by doubles | ||
| 38 | local ps = p:gsub("\\", "\\\\") | ||
| 39 | |||
| 40 | -- read template | ||
| 41 | local fh = io.open(f) | ||
| 42 | local content = fh:read("*a") | ||
| 43 | fh:close() | ||
| 44 | |||
| 45 | -- fill template | ||
| 46 | content = content:gsub("%<LUAROCKSPATH%>", ps) | ||
| 47 | |||
| 48 | -- write destination file | ||
| 49 | fh = io.open(p..no, "w+") | ||
| 50 | fh:write(content) | ||
| 51 | fh:close() | ||
