stevedonovan / Lake

A Lua-based Build Tool
MIT License
134 stars 17 forks source link

path.join with quoted paths #15

Open moteus opened 12 years ago

moteus commented 12 years ago

path.join shold unquot each element and quot result

For example:

IPPARCH="ia32" IPPBASE=J([[e:\Program Files\Intel\IPP\6.0.2.074]], IPPARCH) -- here i have IPPBASE= [["e:\Program Files\Intel\IPP\6.0.2.074\ia32"]] .... incdir=J(IPPBASE, 'include') -- here i have incdir= [["e:\Program Files\Intel\IPP\6.0.2.074\ia32\include"]]

to support this i implement:

function trim(s) return(s:gsub('^%s+',''):gsub('%s+$','')) end

function path_unquoted(s)
  s = trim(s)
  if s:sub(1,1) == '"' and s:sub(-1,-1) == '"' then
    return (s:sub(2,-2))
  end
  return s
end

function path_quoted(s)
  if s:find("%s") then return '"' .. s .. '"' end
  return s
end

function J(...)
  local t,n = {...}, select('#', ...)
  local r = path_unquoted(t[1])
  for i = 2, #t do r = path.join(r,path_unquoted(t[i])) end
  return path_quoted(r)
end
stevedonovan commented 12 years ago

Thanks, that is necessary. Internally I am keeping paths-with-spaces quoted, even on Unix.