forked from edubart/nelua-lang
-
Notifications
You must be signed in to change notification settings - Fork 0
/
nelua.sh
executable file
·71 lines (63 loc) · 1.77 KB
/
nelua.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/bin/sh
# implement realpath case it's not present (Mac OS X for example)
if ! [ -x "$(command -v realpath)" ]; then
realpath() {
OURPWD=$PWD
cd "$(dirname "$1")"
LINK=$(readlink "$(basename "$1")")
while [ "$LINK" ]; do
cd "$(dirname "$LINK")"
LINK=$(readlink "$(basename "$1")")
done
REALPATH="$PWD/$(basename "$1")"
cd "$OURPWD"
echo "$REALPATH"
}
fi
# detect the current directory for this script
SCRIPT=$(realpath $0)
SCRIPT_DIR=$(dirname $SCRIPT)
SCRIPT_DIRNAME=$(basename $SCRIPT_DIR)
if [ "$SCRIPT_DIRNAME" = "bin" ]; then
# in a system install
if [ -z "$NELUA_LUA" ]; then
NELUA_LUA="$SCRIPT_DIR/nelua-lua"
fi
if [ -z "$NELUA_LUALIB" ]; then
USR_DIR=$(dirname $SCRIPT_DIR)
NELUA_LUALIB="$USR_DIR/lib/nelua/lualib"
fi
else
# in a repository clone
if [ -z "$NELUA_LUA" ]; then
NELUA_LUA="$SCRIPT_DIR/src/nelua-lua"
fi
if [ -z "$NELUA_LUALIB" ]; then
NELUA_LUALIB="$SCRIPT_DIR"
fi
fi
# fallback to system lua in case NELUA_LUA is not found
if [ ! -x "$NELUA_LUA" ]; then
NELUA_LUA=$(command -v lua)
fi
# check if a lua is present
if [ ! -x "$NELUA_LUA" ]; then
echo "Lua not found!"
exit 1
fi
# check if the compiler is present
if [ ! -f "$NELUA_LUALIB/nelua.lua" ]; then
echo "Nelua compiler not found!"
exit 1
fi
# determine nelua's lua package path
if [ "$OSTYPE" = "msys" ] || [ "$OSTYPE" = "cygwin" ]; then
NELUA_PACKAGE_PATH="$(cygpath -w $NELUA_LUALIB/)"
NELUA_PACKAGE_PATH="$(printf "%q\n" "$NELUA_PACKAGE_PATH")"
NELUA_NELUALUA="$(cygpath -w $NELUA_LUALIB/nelua.lua)"
else
NELUA_PACKAGE_PATH="$NELUA_LUALIB/"
NELUA_NELUALUA="$NELUA_LUALIB/nelua.lua"
fi
# execute nelua compiler
exec $NELUA_LUA -e "package.path='${NELUA_PACKAGE_PATH}?.lua;'..package.path" $NELUA_NELUALUA "$@"