2019-01-30 14:13:15 +00:00
|
|
|
# set -e
|
|
|
|
|
|
|
|
nix_print() {
|
2019-08-21 14:03:11 +01:00
|
|
|
if [ ${NIX_DEBUG:-0} -ge $1 ]; then
|
|
|
|
echo "$2"
|
|
|
|
fi
|
2019-01-30 14:13:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
nix_debug() {
|
2019-08-21 14:03:11 +01:00
|
|
|
nix_print 3 "$1"
|
2019-01-30 14:13:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
addToLuaSearchPathWithCustomDelimiter() {
|
2019-08-21 14:03:11 +01:00
|
|
|
local varName="$1"
|
|
|
|
local absPattern="$2"
|
|
|
|
# delete longest match starting from the lua placeholder '?'
|
|
|
|
local topDir="${absPattern%%\?*}"
|
2019-01-30 14:13:15 +00:00
|
|
|
|
2019-08-21 14:03:11 +01:00
|
|
|
# export only if the folder exists else LUA_PATH/LUA_CPATH grow too large
|
|
|
|
if [[ ! -d "$topDir" ]]; then return; fi
|
2019-01-30 14:13:15 +00:00
|
|
|
|
2019-08-21 14:03:11 +01:00
|
|
|
# export only if we haven't already got this dir in the search path
|
2019-11-06 00:50:42 +00:00
|
|
|
if [[ ${!varName-} == *"$absPattern"* ]]; then return; fi
|
2019-08-21 14:03:11 +01:00
|
|
|
|
|
|
|
export "${varName}=${!varName:+${!varName};}${absPattern}"
|
2019-01-30 14:13:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
addToLuaPath() {
|
2019-08-21 14:03:11 +01:00
|
|
|
local dir="$1"
|
|
|
|
|
|
|
|
if [[ ! -d "$dir" ]]; then
|
|
|
|
nix_debug "$dir not a directory abort"
|
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
cd "$dir"
|
|
|
|
for pattern in @luapathsearchpaths@; do
|
|
|
|
addToLuaSearchPathWithCustomDelimiter LUA_PATH "$PWD/$pattern"
|
|
|
|
done
|
|
|
|
|
|
|
|
# LUA_CPATH
|
|
|
|
for pattern in @luacpathsearchpaths@; do
|
|
|
|
addToLuaSearchPathWithCustomDelimiter LUA_CPATH "$PWD/$pattern"
|
|
|
|
done
|
|
|
|
cd - >/dev/null
|
2019-01-30 14:13:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
addEnvHooks "$hostOffset" addToLuaPath
|