From 1dd5293f0c725c1d5f290bbed51b3bec59748d16 Mon Sep 17 00:00:00 2001 From: Thijs Schreijer Date: Tue, 6 May 2014 22:43:00 +0200 Subject: Reorganized Windows specific files. Now installer can work directly from the repository --- win32/LuaRocks.reg.lua | 51 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 win32/LuaRocks.reg.lua (limited to 'win32/LuaRocks.reg.lua') 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 @@ +-- Call this file using its full path and the template file as a parameter; +-- +-- C:\> lua.exe "create_reg_file.lua" "c:\luarocks\2.0\LuaRocks.reg.template" +-- +-- it will strip the ".template" extension and write to that file the +-- template contents, where "" will be replaced by the path +-- to LuaRocks (including the trailing backslash) + + + +-- Check argument +local f = (arg or {})[1] +if not f then + print("must provide template file on command line") + os.exit(1) +end + +-- cleanup filepath, remove all double backslashes +while f:match("\\\\") do + f = f:gsub("\\\\", "\\") +end + +-- extract path and name from argument +local p = "" +local ni = f +for i = #f, 1, -1 do + if f:sub(i,i) == "\\" then + ni = f:sub(i+1) + p = f:sub(1, i) + break + end +end + +-- create output name +local no = ni:gsub("%.template","") + +-- create path substitute; escape backslash by doubles +local ps = p:gsub("\\", "\\\\") + +-- read template +local fh = io.open(f) +local content = fh:read("*a") +fh:close() + +-- fill template +content = content:gsub("%", ps) + +-- write destination file +fh = io.open(p..no, "w+") +fh:write(content) +fh:close() -- cgit v1.2.3-55-g6feb