From befb73a2627ba126b3daa7540afae25c9dd12516 Mon Sep 17 00:00:00 2001 From: Ronan Collobert Date: Fri, 14 Feb 2014 12:56:12 +0100 Subject: fix init.lua --- init.lua | 118 ++++++++++++++++++++++++++++++++++++++++++++++ init.lua.in | 153 ------------------------------------------------------------ 2 files changed, 118 insertions(+), 153 deletions(-) create mode 100644 init.lua delete mode 100644 init.lua.in diff --git a/init.lua b/init.lua new file mode 100644 index 0000000..af2be0b --- /dev/null +++ b/init.lua @@ -0,0 +1,118 @@ +require 'libpaths' + +local assert = assert +local debug = debug +local pcall = pcall +local type = type +local ipairs = ipairs +local os = os +local g = _G + +module('paths') + +function is_win() + return uname():match('Windows') +end + +function is_mac() + return uname():match('Darwin') +end + +if is_win() then + home = os.getenv('HOMEDRIVE') or 'C:' + home = home .. ( os.getenv('HOMEPATH') or '\\' ) +else + home = os.getenv('HOME') or '.' +end + +function files(s) + local d = dir(s) + local n = 0 + return function() + n = n + 1 + if (d and n <= #d) then + return d[n] + else + return nil + end + end +end + +function thisfile(arg, depth) + local s = debug.getinfo(depth or 2).source + if type(s) ~= "string" then + s = nil + elseif s:match("^@") then -- when called from a file + s = concat(s:sub(2)) + elseif s:match("^qt[.]") then -- when called from a qtide editor + local function z(s) return g.qt[s].fileName:tostring() end + local b, f = pcall(z, s:sub(4)); + if b and f and f ~= "" then s = f else s = nil end + end + if type(arg) == "string" then + if s then s = concat(dirname(s), arg) else s = arg end + end + return s +end + +function dofile(f, depth) + local s = thisfile(nil, 1 + (depth or 2)) + if s and s ~= "" then + f = concat(dirname(s),f) + end + return g.dofile(f) +end + +function rmall(d, more) + if more ~= 'yes' then + return nil, "missing second argument ('yes')" + elseif filep(d) then + return os.remove(d) + elseif dirp(d) then + for f in files(d) do + if f ~= '.' and f ~= '..' then + local ff = concat(d, f) + local r0,r1,r2 = rmall(ff, more) + if not r0 then + return r0,r1,ff + end + end + end + return rmdir(d) + else + return nil, "not a file or directory", d + end +end + +function findprogram(...) + for _,exe in ipairs{...} do + if is_win() then + if not exe:match('[.]exe$') then + exe = exe .. '.exe' + end + local path, k, x = os.getenv("PATH") or "." + for dir in path:gmatch('[^;]+') do + x = concat(dir, exe) + if filep(x) then return x end + end + local function clean(s) + if s:match('^"') then return s:match('[^"]+') else return s end + end + k = 'SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\App Paths\\' .. exe + x = getregistryvalue('HKEY_CURRENT_USER', k, '') + if type(x) == 'string' then return clean(x) end + x = getregistryvalue('HKEY_LOCAL_MACHINE', k, '') + if type(x) == 'string' then return clean(x) end + k = 'Applications\\' .. exe .. '\\shell\\open\\command' + x = getregistryvalue('HKEY_CLASSES_ROOT', k, '') + if type(x) == 'string' then return clean(x) end + else + local path = os.getenv("PATH") or "." + for dir in path:gmatch('[^:]+') do + local x = concat(dir, exe) + if filep(x) then return x end + end + end + end + return nil +end diff --git a/init.lua.in b/init.lua.in deleted file mode 100644 index 4a5bcd0..0000000 --- a/init.lua.in +++ /dev/null @@ -1,153 +0,0 @@ -# -*- lua -*- - -require 'libpaths' - -local assert = assert -local debug = debug -local pcall = pcall -local type = type -local ipairs = ipairs -local os = os -local g = _G - -module('paths') - -install_prefix = [[@Torch_INSTALL_PREFIX@]] -install_bin_subdir = [[@Torch_INSTALL_BIN_SUBDIR@]] -install_man_subdir = [[@Torch_INSTALL_MAN_SUBDIR@]] -install_lib_subdir = [[@Torch_INSTALL_LIB_SUBDIR@]] -install_share_subdir = [[@Torch_INSTALL_SHARE_SUBDIR@]] -install_include_subdir = [[@Torch_INSTALL_INCLUDE_SUBDIR@]] -install_hlp_subdir = [[@Torch_INSTALL_HLP_SUBDIR@]] -install_html_subdir = [[@Torch_INSTALL_HTML_SUBDIR@]] -install_cmake_subdir = [[@Torch_INSTALL_CMAKE_SUBDIR@]] -install_lua_path_subdir = [[@Torch_INSTALL_LUA_PATH_SUBDIR@]] -install_lua_cpath_subdir = [[@Torch_INSTALL_LUA_CPATH_SUBDIR@]] -install_bin_ridbus = [[@Torch_INSTALL_BIN_RIDBUS@]] -install_cmake_ridbus = [[@Torch_INSTALL_CMAKE_RIDBUS@]] - -local e = execdir() -if e ~= nil then - install_prefix = concat(e,install_bin_ridbus) -end - -install_bin = concat(install_prefix, install_bin_subdir) -install_man = concat(install_prefix, install_man_subdir) -install_lib = concat(install_prefix, install_lib_subdir) -install_share = concat(install_prefix, install_share_subdir) -install_include = concat(install_prefix, install_include_subdir) -install_hlp = concat(install_prefix, install_hlp_subdir) -install_html = concat(install_prefix, install_html_subdir) -install_cmake = concat(install_prefix, install_cmake_subdir) -install_lua_path = concat(install_prefix, install_lua_path_subdir) -install_lua_cpath = concat(install_prefix, install_lua_cpath_subdir) - -assert(concat(install_bin,install_bin_ridbus) == install_prefix:gsub('/$','')) -assert(concat(install_cmake,install_cmake_ridbus) == install_prefix:gsub('/$','')) - -function is_win() - return uname():match('Windows') -end - -function is_mac() - return uname():match('Darwin') -end - -if is_win() then - home = os.getenv('HOMEDRIVE') or 'C:' - home = home .. ( os.getenv('HOMEPATH') or '\\' ) -else - home = os.getenv('HOME') or '.' -end - -function files(s) - local d = dir(s) - local n = 0 - return function() - n = n + 1 - if (d and n <= #d) then - return d[n] - else - return nil - end - end -end - -function thisfile(arg, depth) - local s = debug.getinfo(depth or 2).source - if type(s) ~= "string" then - s = nil - elseif s:match("^@") then -- when called from a file - s = concat(s:sub(2)) - elseif s:match("^qt[.]") then -- when called from a qtide editor - local function z(s) return g.qt[s].fileName:tostring() end - local b, f = pcall(z, s:sub(4)); - if b and f and f ~= "" then s = f else s = nil end - end - if type(arg) == "string" then - if s then s = concat(dirname(s), arg) else s = arg end - end - return s -end - -function dofile(f, depth) - local s = thisfile(nil, 1 + (depth or 2)) - if s and s ~= "" then - f = concat(dirname(s),f) - end - return g.dofile(f) -end - -function rmall(d, more) - if more ~= 'yes' then - return nil, "missing second argument ('yes')" - elseif filep(d) then - return os.remove(d) - elseif dirp(d) then - for f in files(d) do - if f ~= '.' and f ~= '..' then - local ff = concat(d, f) - local r0,r1,r2 = rmall(ff, more) - if not r0 then - return r0,r1,ff - end - end - end - return rmdir(d) - else - return nil, "not a file or directory", d - end -end - -function findprogram(...) - for _,exe in ipairs{...} do - if is_win() then - if not exe:match('[.]exe$') then - exe = exe .. '.exe' - end - local path, k, x = os.getenv("PATH") or "." - for dir in path:gmatch('[^;]+') do - x = concat(dir, exe) - if filep(x) then return x end - end - local function clean(s) - if s:match('^"') then return s:match('[^"]+') else return s end - end - k = 'SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\App Paths\\' .. exe - x = getregistryvalue('HKEY_CURRENT_USER', k, '') - if type(x) == 'string' then return clean(x) end - x = getregistryvalue('HKEY_LOCAL_MACHINE', k, '') - if type(x) == 'string' then return clean(x) end - k = 'Applications\\' .. exe .. '\\shell\\open\\command' - x = getregistryvalue('HKEY_CLASSES_ROOT', k, '') - if type(x) == 'string' then return clean(x) end - else - local path = os.getenv("PATH") or "." - for dir in path:gmatch('[^:]+') do - local x = concat(dir, exe) - if filep(x) then return x end - end - end - end - return nil -end -- cgit v1.2.3