aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/luarocks/fs/unix.lua7
-rw-r--r--src/luarocks/fs/win32.lua7
-rw-r--r--src/luarocks/util.lua9
3 files changed, 14 insertions, 9 deletions
diff --git a/src/luarocks/fs/unix.lua b/src/luarocks/fs/unix.lua
index e154ef45..9dc3b6a6 100644
--- a/src/luarocks/fs/unix.lua
+++ b/src/luarocks/fs/unix.lua
@@ -54,14 +54,15 @@ function wrap_script(file, dest, name, version)
54 local base = dir.base_name(file) 54 local base = dir.base_name(file)
55 local wrapname = fs.is_dir(dest) and dest.."/"..base or dest 55 local wrapname = fs.is_dir(dest) and dest.."/"..base or dest
56 local lpath, lcpath = cfg.package_paths() 56 local lpath, lcpath = cfg.package_paths()
57 lpath = util.escape_doublebrackets(lpath)
58 lcpath = util.escape_doublebrackets(lcpath)
59 local wrapper = io.open(wrapname, "w") 57 local wrapper = io.open(wrapname, "w")
60 if not wrapper then 58 if not wrapper then
61 return nil, "Could not open "..wrapname.." for writing." 59 return nil, "Could not open "..wrapname.." for writing."
62 end 60 end
63 wrapper:write("#!/bin/sh\n\n") 61 wrapper:write("#!/bin/sh\n\n")
64 wrapper:write('exec "'..dir.path(cfg.variables["LUA_BINDIR"], cfg.lua_interpreter)..'" -e \'package.path=[['..lpath..';]]..package.path\' -e \'package.cpath=[['..lcpath..';]]..package.cpath\' -lluarocks.loader -e\'luarocks.loader.add_context([['..name..']],[['..version..']])\' "'..file..'" "$@"\n') 62 local lua = dir.path(cfg.variables["LUA_BINDIR"], cfg.lua_interpreter)
63 local ppaths = "package.path="..util.LQ(lpath..";").."..package.path; package.cpath="..util.LQ(lcpath..";").."..package.cpath"
64 local addctx = "luarocks.loader.add_context("..util.LQ(name)..","..util.LQ(version)..")"
65 wrapper:write('exec '..fs.Q(lua)..' -e '..fs.Q(ppaths)..' -lluarocks.loader -e '..fs.Q(addctx)..' '..fs.Q(file)..' "$@"\n')
65 wrapper:close() 66 wrapper:close()
66 if fs.chmod(wrapname, "0755") then 67 if fs.chmod(wrapname, "0755") then
67 return true 68 return true
diff --git a/src/luarocks/fs/win32.lua b/src/luarocks/fs/win32.lua
index ba3ba2b3..4a105e8d 100644
--- a/src/luarocks/fs/win32.lua
+++ b/src/luarocks/fs/win32.lua
@@ -65,14 +65,15 @@ function wrap_script(file, dest, name, version)
65 local wrapname = fs.is_dir(dest) and dest.."/"..base or dest 65 local wrapname = fs.is_dir(dest) and dest.."/"..base or dest
66 wrapname = wrapname..".bat" 66 wrapname = wrapname..".bat"
67 local lpath, lcpath = cfg.package_paths() 67 local lpath, lcpath = cfg.package_paths()
68 lpath = util.escape_doublebrackets(lpath)
69 lcpath = util.escape_doublebrackets(lcpath)
70 local wrapper = io.open(wrapname, "w") 68 local wrapper = io.open(wrapname, "w")
71 if not wrapper then 69 if not wrapper then
72 return nil, "Could not open "..wrapname.." for writing." 70 return nil, "Could not open "..wrapname.." for writing."
73 end 71 end
74 wrapper:write("@echo off\n") 72 wrapper:write("@echo off\n")
75 wrapper:write('"'..dir.path(cfg.variables["LUA_BINDIR"], cfg.lua_interpreter)..'" -e "package.path=[['..lpath..';]]..package.path" -e "package.cpath=[['..lcpath..';]]..package.cpath" -lluarocks.loader -e"luarocks.loader.add_context([['..name..']],[['..version..']])" "'..file..'" %*\n') 73 local lua = dir.path(cfg.variables["LUA_BINDIR"], cfg.lua_interpreter)
74 local ppaths = "package.path="..util.LQ(lpath..";").."..package.path; package.cpath="..util.LQ(lcpath..";").."..package.cpath"
75 local addctx = "luarocks.loader.add_context("..util.LQ(name)..","..util.LQ(version)..")"
76 wrapper:write(fs.Q(lua)..' -e '..fs.Q(ppaths)..' -lluarocks.loader -e '..fs.Q(addctx)..' '..fs.Q(file)..' %*\n')
76 wrapper:close() 77 wrapper:close()
77 return true 78 return true
78end 79end
diff --git a/src/luarocks/util.lua b/src/luarocks/util.lua
index cfcd2013..1a60fd9c 100644
--- a/src/luarocks/util.lua
+++ b/src/luarocks/util.lua
@@ -512,6 +512,9 @@ function array_contains(tbl, value)
512 return false 512 return false
513end 513end
514 514
515function escape_doublebrackets(s) 515-- Quote Lua string, analogous to fs.Q.
516 return s:gsub("(([%[%]])%2)","]]..'%1'..[[") 516-- @param s A string, such as "hello"
517end \ No newline at end of file 517-- @return string: A quoted string, such as '"hello"'
518function LQ(s)
519 return ("%q"):format(s)
520end