├── .editorconfig ├── .travis.yml ├── bin ├── list-bin-paths ├── download ├── exec-env ├── list-all └── install ├── CHANGELOG.md ├── LICENSE ├── .github └── workflows │ └── workflow.yml ├── README.md └── lib └── utils.sh /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | indent_style = space 5 | indent_size = 2 6 | charset = utf-8 7 | trim_trailing_whitespace = true 8 | insert_final_newline = true 9 | 10 | [*.py] 11 | indent_size = 4 12 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: c 2 | script: asdf plugin-test lua https://github.com/Stratus3D/asdf-lua.git 3 | before_script: 4 | - git clone https://github.com/asdf-vm/asdf.git 5 | - . asdf/asdf.sh 6 | os: 7 | - linux 8 | - osx 9 | -------------------------------------------------------------------------------- /bin/list-bin-paths: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Unoffical Bash "strict mode" 4 | # http://redsymbol.net/articles/unofficial-bash-strict-mode/ 5 | set -euo pipefail 6 | #ORIGINAL_IFS=$IFS 7 | IFS=$'\t\n' # Stricter IFS settings 8 | 9 | echo "bin luarocks/bin" 10 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | ## 0.1.2 4 | * Correct the environment lua executables run in by creating custom exec-env (#2) 5 | 6 | ## 0.1.1 7 | * Add Lua versions 5.3.3, 5.3.2, and 5.3.1 8 | 9 | ## 0.1.0 10 | * Initial Release 11 | * Installs Lua versions 5.2 or greater 12 | -------------------------------------------------------------------------------- /bin/download: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Unoffical Bash "strict mode" 4 | # http://redsymbol.net/articles/unofficial-bash-strict-mode/ 5 | set -euo pipefail 6 | #ORIGINAL_IFS=$IFS 7 | IFS=$'\t\n' # Stricter IFS settings 8 | 9 | # shellcheck source=lib/utils.sh 10 | source "$(dirname "$0")/../lib/utils.sh" 11 | 12 | archive_file_path="$(get_download_file_path "$ASDF_INSTALL_TYPE" "$ASDF_INSTALL_VERSION" "$ASDF_DOWNLOAD_PATH")" 13 | download_source "$ASDF_INSTALL_TYPE" "$ASDF_INSTALL_VERSION" "$archive_file_path" 14 | -------------------------------------------------------------------------------- /bin/exec-env: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | full_version="$(echo "$ASDF_INSTALL_PATH" | rev | cut -d/ -f1 | rev)" 4 | 5 | short_lua_version="" 6 | 7 | if [ "$full_version" != "system" ]; then 8 | IFS='.' read -r -a splitted_version <<<"$full_version" 9 | short_lua_version="${splitted_version[0]}.${splitted_version[1]}" 10 | fi 11 | 12 | package_path_override="package.path = package.path .. '\ 13 | ;${ASDF_INSTALL_PATH}/share/lua/${short_lua_version}/?.lua\ 14 | ;${ASDF_INSTALL_PATH}/share/lua/${short_lua_version}/?/init.lua\ 15 | ;${ASDF_INSTALL_PATH}/luarocks/share/lua/${short_lua_version}/?.lua\ 16 | ;${ASDF_INSTALL_PATH}/luarocks/share/lua/${short_lua_version}/?/init.lua'" 17 | 18 | package_cpath_override="package.cpath = package.cpath .. '\ 19 | ;${ASDF_INSTALL_PATH}/lib/lua/${short_lua_version}/?.so\ 20 | ;${ASDF_INSTALL_PATH}/luarocks/lib/lua/${short_lua_version}/?.so'" 21 | 22 | export LUA_INIT="${package_path_override} 23 | ${package_cpath_override}" 24 | -------------------------------------------------------------------------------- /bin/list-all: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Unoffical Bash "strict mode" 4 | # http://redsymbol.net/articles/unofficial-bash-strict-mode/ 5 | set -euo pipefail 6 | #ORIGINAL_IFS=$IFS 7 | IFS=$'\t\n' # Stricter IFS settings 8 | 9 | # Each of these values can be used to build the url to the archive containing 10 | # the source code for each version 11 | # (e.g. http://www.lua.org/ftp/lua-.tar.gz) 12 | 13 | versions_list=( 14 | #1.1 15 | #2.2 16 | #2.4 17 | #2.5 18 | #3.0 19 | #3.1 20 | #3.2 21 | #4.0 22 | # TODO: Add support for earlier versions 23 | 5.1 24 | 5.1.1 25 | 5.1.2 26 | 5.1.3 27 | 5.1.4 28 | 5.1.5 29 | 5.2.0 30 | 5.2.1 31 | 5.2.2 32 | 5.2.3 33 | 5.2.4 34 | 5.3.0 35 | 5.3.1 36 | 5.3.2 37 | 5.3.3 38 | 5.3.4 39 | 5.3.5 40 | 5.3.6 41 | 5.4.0 42 | 5.4.2 43 | 5.4.3 44 | 5.4.4 45 | 5.4.5 46 | 5.4.6 47 | 5.4.7 48 | ) 49 | 50 | versions="" 51 | 52 | # Concatenate all the versions together separated by spaces 53 | for version in "${versions_list[@]}"; do 54 | versions="${versions} ${version}" 55 | done 56 | 57 | # Print out the versions 58 | echo "$versions" 59 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Trevor Brown 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /.github/workflows/workflow.yml: -------------------------------------------------------------------------------- 1 | name: Main workflow 2 | 3 | on: 4 | pull_request: 5 | types: 6 | - opened 7 | - synchronize 8 | - reopened 9 | paths-ignore: 10 | - "**.md" 11 | push: 12 | branches: 13 | - master 14 | paths-ignore: 15 | - "**.md" 16 | 17 | jobs: 18 | plugin_test: 19 | strategy: 20 | fail-fast: false 21 | matrix: 22 | version: 23 | - 5.1.5 24 | - 5.2.4 25 | - 5.3.6 26 | - 5.4.7 27 | os: 28 | - macos-latest 29 | - ubuntu-latest 30 | 31 | runs-on: ${{ matrix.os }} 32 | 33 | steps: 34 | - name: Checkout code 35 | uses: actions/checkout@v2 36 | 37 | - name: Install system packages on Ubuntu 38 | if: ${{ runner.os == 'Linux' }} 39 | run: sudo apt-get install curl 40 | 41 | - name: Install system packages on macOS 42 | if: ${{ runner.os == 'macOS' }} 43 | run: brew install coreutils 44 | 45 | - name: Test plugin 46 | uses: asdf-vm/actions/plugin-test@v1 47 | with: 48 | command: lua -v 49 | version: ${{ matrix.version }} 50 | 51 | lint: 52 | runs-on: ubuntu-latest 53 | 54 | steps: 55 | - name: Checkout code 56 | uses: actions/checkout@v3 57 | 58 | - name: Run ShellCheck 59 | run: shellcheck bin/* lib/* 60 | 61 | format: 62 | runs-on: macos-latest 63 | 64 | steps: 65 | - name: Checkout code 66 | uses: actions/checkout@v3 67 | 68 | - name: Install shfmt 69 | run: brew install shfmt 70 | 71 | - name: Run shfmt 72 | run: shfmt -d . 73 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # asdf-lua 2 | 3 | [![Build Status](https://travis-ci.org/Stratus3D/asdf-lua.svg?branch=master)](https://travis-ci.org/Stratus3D/asdf-lua) 4 | [![Github Workflow](https://github.com/Stratus3D/asdf-lua/actions/workflows/workflow.yml/badge.svg)](https://github.com/Stratus3D/asdf-lua/actions/workflows/workflow.yml) 5 | 6 | Lua plugin for [asdf version manager](https://github.com/HashNuke/asdf) based off of scripts in my [dotfiles repository](https://github.com/Stratus3D/dotfiles). 7 | 8 | ## Dependencies 9 | 10 | * ANSI C compiler (like gcc). 11 | * OSX 12 | * `xcode-select --install`. Then install the "Command Line Tools" component from the dialog that appears. 13 | * Debian 14 | * `sudo apt-get install linux-headers-$(uname -r) build-essential` 15 | * RedHat 16 | * `sudo yum install devtoolset-2` 17 | 18 | ## Install 19 | 20 | ``` 21 | asdf plugin add lua https://github.com/Stratus3D/asdf-lua.git 22 | ``` 23 | 24 | ## Use 25 | 26 | Check the [asdf](https://github.com/HashNuke/asdf) readme for instructions on how to install & manage versions of Lua. 27 | 28 | You can also read my [Lua Version Management with asdf-lua](http://stratus3d.com/blog/2016/12/30/lua-version-management-with-asdf-lua/) article which has complete instructions on installation and usage. 29 | 30 | ## Options 31 | 32 | ### Linux Readline 33 | 34 | If you are installing Lua 5.4.x or greater on linux by default Lua will be compiled without readline. You can override this behavior by setting `ASDF_LUA_LINUX_READLINE=1` before running `asdf install`. See this thread for the details - http://lua-users.org/lists/lua-l/2020-07/msg00363.html 35 | 36 | ## Development 37 | 38 | To modify this plugin into your `asdf` installation and see changes live, just create a symlink: 39 | 40 | ``` 41 | ln -s . ~/.asdf/plugins/lua 42 | ``` 43 | 44 | ## Contributing 45 | 46 | Feel free to create an issue or pull request if you find a bug. 47 | 48 | ## Issues 49 | 50 | * Lua versions 4.0 and earlier do not install 51 | * No way to specify specify custom configuration options 52 | 53 | ## License 54 | MIT License 55 | -------------------------------------------------------------------------------- /lib/utils.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | download_source() { 4 | local install_type="$1" 5 | local version="$2" 6 | local download_path="$3" 7 | local download_url 8 | 9 | install_type="$1" 10 | version="$2" 11 | download_path="$3" 12 | download_url="$(get_download_url "$install_type" "$version")" 13 | 14 | curl -Lo "$download_path" -C - "$download_url" 15 | } 16 | 17 | get_download_url() { 18 | local install_type="$1" 19 | local version="$2" 20 | local lua_type 21 | 22 | lua_type="$(get_lua_type "$version")" 23 | 24 | if [ "${lua_type}" = "Lua" ]; then 25 | echo "https://www.lua.org/ftp/lua-${version}.tar.gz" 26 | elif [ "${lua_type}" = "LuaJIT" ]; then 27 | echo "https://luajit.org/download/LuaJIT-${version}.tar.gz" 28 | fi 29 | } 30 | 31 | get_lua_type() { 32 | IFS='-' read -ra version_info <<<"$1" 33 | if [ "${version_info[0]}" = "LuaJIT" ]; then 34 | echo "LuaJIT" 35 | else 36 | echo "Lua" 37 | fi 38 | } 39 | 40 | get_lua_version() { 41 | IFS='-' read -ra version_info <<<"$1" 42 | 43 | if [ "${version_info[0]}" = "LuaJIT" ]; then 44 | # TODO LuaJIT 45 | echo "${version_info[1]}-${version_info[2]}" 46 | else 47 | # Lua 48 | if [ "${#version_info[@]}" -eq 1 ]; then 49 | echo "${version_info[0]}" 50 | else 51 | echo "${version_info[0]}-${version_info[1]}" 52 | fi 53 | fi 54 | } 55 | 56 | get_download_file_path() { 57 | local install_type="$1" 58 | local version="$2" 59 | local tmp_download_dir="$3" 60 | local lua_type 61 | local lua_version 62 | 63 | lua_type="$(get_lua_type "$version")" 64 | lua_version="$(get_lua_version "$version")" 65 | 66 | if [ "${lua_type}" = "Lua" ]; then 67 | local pkg_name="lua-${lua_version}.tar.gz" 68 | fi 69 | 70 | echo "$tmp_download_dir/$pkg_name" 71 | } 72 | 73 | get_latest_luarocks_version() { 74 | curl_opts=(-fsSL) 75 | if [ -n "${GITHUB_API_TOKEN:-}" ]; then 76 | curl_opts=("${curl_opts[@]}" -H "Authorization: token ${GITHUB_API_TOKEN}") 77 | fi 78 | curl "${curl_opts[@]}" "https://api.github.com/repos/luarocks/luarocks/tags?per_page=1&page=1" | 79 | grep '"name"' | cut -d\" -f4 | cut -c2- 80 | } 81 | -------------------------------------------------------------------------------- /bin/install: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Unoffical Bash "strict mode" 4 | # http://redsymbol.net/articles/unofficial-bash-strict-mode/ 5 | set -euo pipefail 6 | #ORIGINAL_IFS=$IFS 7 | IFS=$'\t\n' # Stricter IFS settings 8 | 9 | # shellcheck source=lib/utils.sh 10 | source "$(dirname "$0")/../lib/utils.sh" 11 | 12 | install_lua() { 13 | local install_type="$1" 14 | local version="$2" 15 | local install_path="$3" 16 | local download_path="$4" 17 | local source_path 18 | local tmp_download_dir 19 | 20 | # If download path is not set 21 | if [ -z "$download_path" ]; then 22 | if [ "${TMPDIR:-}" = "" ]; then 23 | tmp_download_dir="$(mktemp -d -t lua_build_XXXXXX)" 24 | else 25 | tmp_download_dir="${TMPDIR%/}" 26 | fi 27 | 28 | source_path="$(get_download_file_path "$install_type" "$version" "$tmp_download_dir")" 29 | 30 | download_source "$install_type" "$version" "$source_path" 31 | 32 | download_path="$source_path" 33 | else 34 | download_path="$(get_download_file_path "$install_type" "$version" "$download_path")" 35 | fi 36 | 37 | # Running this in a subshell because we don't to disturb the current 38 | # working directory. 39 | ( 40 | cd "$(dirname "$download_path")" 41 | tar zxvf "$download_path" 42 | download_dir="$(dirname "$download_path")" 43 | 44 | cd "$(untar_path "$install_type" "$version" "$download_dir")" || exit 1 45 | 46 | # Target is OS-specific 47 | target="$(get_target)" 48 | 49 | # Build Lua 50 | if version_5x_or_greater "$version"; then 51 | make "$target" || exit 1 52 | make test || exit 1 53 | make local || exit 1 54 | else 55 | make || exit 1 56 | make install INSTALL_ROOT=install || exit 1 57 | fi 58 | 59 | # `make local` target changed in version 5x 60 | if version_5_2x_or_greater "$version"; then 61 | cp -r install/* "$install_path" || exit 1 62 | elif version_5x_or_greater "$version"; then 63 | cp -r ./* "$install_path" || exit 1 64 | else 65 | # We install version 4 and lesser in install/ 66 | cp -r install/* "$install_path" || exit 1 67 | fi 68 | 69 | # If we are installing Lua 5.x or greater install LuaRocks as well 70 | if version_5x_or_greater "$version"; then 71 | local luarocks_version 72 | luarocks_version="${ASDF_LUA_LUAROCKS_VERSION:-$(get_latest_luarocks_version)}" 73 | local luarocks_name="luarocks-$luarocks_version" 74 | echo "Installing LuaRocks v${luarocks_version}..." 75 | curl -L "https://luarocks.org/releases/${luarocks_name}.tar.gz" --output luarocks.tar.gz || exit 1 76 | tar zxpf luarocks.tar.gz || exit 1 77 | cd "$luarocks_name" || exit 1 78 | ./configure --with-lua="$install_path" --with-lua-include="$install_path/include" --with-lua-lib="$install_path/lib" --prefix="$install_path/luarocks" || exit 1 79 | make bootstrap || exit 1 80 | fi 81 | ) 82 | } 83 | 84 | untar_path() { 85 | local install_type="$1" 86 | local version="$2" 87 | local tmp_download_dir="$3" 88 | local lua_type 89 | local lua_version 90 | 91 | lua_type="$(get_lua_type "$version")" 92 | lua_version="$(get_lua_version "$version")" 93 | 94 | if [ "${lua_type}" = "Lua" ]; then 95 | if version_5_1x_or_greater "$version"; then 96 | local dir_name="lua-${lua_version}" 97 | else 98 | local dir_name="lua" 99 | fi 100 | elif [ "${lua_type}" = "LuaJIT" ]; then 101 | local dir_name="luajit-${lua_version}" 102 | fi 103 | 104 | echo "$tmp_download_dir/$dir_name" 105 | } 106 | 107 | get_target() { 108 | os="$(uname -s)" 109 | 110 | # If on OSX (Darwin) then the target is macosx 111 | if [ "$os" = "Darwin" ]; then 112 | echo "macosx" 113 | elif [ "${ASDF_LUA_LINUX_READLINE-}" == "1" ]; then 114 | echo "linux-readline" 115 | else # Otherwise let the lua Makefile guess for us 116 | if less_than_version_5_4x "$version"; then 117 | echo "linux" 118 | else 119 | echo "guess" 120 | fi 121 | fi 122 | } 123 | 124 | version_5x_or_greater() { 125 | version="$1" 126 | IFS='.' read -ra version_array <<<"$version" 127 | major_version="${version_array[0]}" 128 | 129 | if (("$major_version" >= 5)); then 130 | return 0 131 | else 132 | return 1 133 | fi 134 | } 135 | 136 | version_5_1x_or_greater() { 137 | version="$1" 138 | IFS='.' read -ra version_array <<<"$version" 139 | major_minor_version="${version_array[0]}0${version_array[1]}" 140 | if (("$major_minor_version" >= 501)); then 141 | return 0 142 | else 143 | return 1 144 | fi 145 | } 146 | version_5_2x_or_greater() { 147 | version=$1 148 | IFS='.' read -ra version_array <<<"$version" 149 | major_minor_version="${version_array[0]}0${version_array[1]}" 150 | if (("$major_minor_version" >= 502)); then 151 | return 0 152 | else 153 | return 1 154 | fi 155 | } 156 | 157 | less_than_version_5_4x() { 158 | version=$1 159 | IFS='.' read -ra version_array <<<"$version" 160 | major_minor_version="${version_array[0]}0${version_array[1]}" 161 | if (("$major_minor_version" < 504)); then 162 | return 0 163 | else 164 | return 1 165 | fi 166 | } 167 | 168 | install_lua "$ASDF_INSTALL_TYPE" "$ASDF_INSTALL_VERSION" "$ASDF_INSTALL_PATH" "$ASDF_DOWNLOAD_PATH" 169 | --------------------------------------------------------------------------------