#!/bin/sh
# Wrapper for Debian Torch Packages
# Copyright (C) 2016 Zhou Mo <cdluminate@gmail.com>
# BSD-3-Clause
set -e

# the real trepl script
TREPL=/usr/lib/torch-trepl/th

# probe lua interpreters, only luajit (recommend) and
# lua5.1 are supported. Here I don't use hardcoded lua
# interpreter path so user can override the default
# interpreter with `$PATH` instead of modifying this script.
if test -z "`which luajit 1>/dev/null`"; then
  LUA=$(which luajit)
else
  printf "I: luajit not found, falling back to lua5.1\n";
  if test -z "`which lua5.1 1>/dev/null`"; then
    LUA=$(which lua5.1)
  else
    printf "E: lua5.1 not found. No available lua interpreter.\n"
    false
  fi
fi

# run the real trepl script with possible arguments
exec $LUA $TREPL "$@"
