2019-01-30 15:13:15 +01:00
|
|
|
# set -e
|
|
|
|
|
|
|
|
nix_print() {
|
2019-02-04 12:30:58 +01:00
|
|
|
if [ ${NIX_DEBUG:-0} -ge $1 ]; then
|
2019-01-30 15:13:15 +01:00
|
|
|
echo "$2"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
nix_debug() {
|
|
|
|
nix_print 3 "$1"
|
|
|
|
}
|
|
|
|
|
|
|
|
addToLuaSearchPathWithCustomDelimiter() {
|
|
|
|
local varName="$1"
|
|
|
|
local absPattern="$2"
|
|
|
|
# delete longest match starting from the lua placeholder '?'
|
|
|
|
local topDir="${absPattern%%\?*}"
|
|
|
|
|
|
|
|
# export only if the folder exists else LUA_PATH grows too big
|
|
|
|
if [ ! -d "$topDir" ]; then return; fi
|
|
|
|
|
|
|
|
export "${varName}=${!varName:+${!varName};}${absPattern}"
|
|
|
|
}
|
|
|
|
|
|
|
|
addToLuaPath() {
|
|
|
|
local dir="$1"
|
|
|
|
|
|
|
|
if [[ ! -d "$dir" ]]; then
|
|
|
|
nix_debug "$dir not a directory abort"
|
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
cd "$dir"
|
|
|
|
for pattern in @luapathsearchpaths@;
|
|
|
|
do
|
2019-02-04 12:30:58 +01:00
|
|
|
addToLuaSearchPathWithCustomDelimiter NIX_LUA_PATH "$PWD/$pattern"
|
2019-01-30 15:13:15 +01:00
|
|
|
done
|
|
|
|
|
|
|
|
# LUA_CPATH
|
|
|
|
for pattern in @luacpathsearchpaths@;
|
|
|
|
do
|
2019-02-04 12:30:58 +01:00
|
|
|
addToLuaSearchPathWithCustomDelimiter NIX_LUA_CPATH "$PWD/$pattern"
|
2019-01-30 15:13:15 +01:00
|
|
|
done
|
2019-01-30 19:53:01 +01:00
|
|
|
cd - >/dev/null
|
2019-01-30 15:13:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
addEnvHooks "$hostOffset" addToLuaPath
|
|
|
|
|