1# set -e
2
3nix_print() {
4 if [ ${NIX_DEBUG:-0} -ge $1 ]; then
5 echo "$2"
6 fi
7}
8
9nix_debug() {
10 nix_print 3 "$1"
11}
12
13addToLuaSearchPathWithCustomDelimiter() {
14 local varName="$1"
15 local absPattern="$2"
16 # delete longest match starting from the lua placeholder '?'
17 local topDir="${absPattern%%\?*}"
18
19 # export only if the folder exists else LUA_PATH/LUA_CPATH grow too large
20 if [[ ! -d "$topDir" ]]; then return; fi
21
22 # export only if we haven't already got this dir in the search path
23 if [[ ${!varName-} == *"$absPattern"* ]]; then return; fi
24
25 export "${varName}=${!varName:+${!varName};}${absPattern}"
26}
27
28addToLuaPath() {
29 local dir="$1"
30
31 if [[ ! -d "$dir" ]]; then
32 nix_debug "$dir not a directory abort"
33 return 0
34 fi
35 cd "$dir"
36 for pattern in @luapathsearchpaths@; do
37 addToLuaSearchPathWithCustomDelimiter LUA_PATH "$PWD/$pattern"
38 done
39
40 # LUA_CPATH
41 for pattern in @luacpathsearchpaths@; do
42 addToLuaSearchPathWithCustomDelimiter LUA_CPATH "$PWD/$pattern"
43 done
44 cd - >/dev/null
45}
46
47addEnvHooks "$hostOffset" addToLuaPath