├── .gitignore ├── LICENSE ├── LuaJIT-For-Windows.cmd └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | /* 2 | !/.gitignore 3 | !/LICENSE 4 | !/LuaJIT-For-Windows.cmd 5 | !/README.md 6 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2025 ScriptTiger 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 | -------------------------------------------------------------------------------- /LuaJIT-For-Windows.cmd: -------------------------------------------------------------------------------- 1 | @echo off 2 | 3 | rem ===== 4 | rem For more information on ScriptTiger and more ScriptTiger scripts visit the following URL: 5 | rem https://scripttiger.github.io/ 6 | rem Or visit the following URL for the latest information on this ScriptTiger script: 7 | rem https://github.com/ScriptTiger/LuaJIT-For-Windows 8 | rem ===== 9 | 10 | rem Write lj4w.config if does not exist 11 | if not exist "%APPDATA%\LJ4W" md "%APPDATA%\LJ4W" 12 | if not exist "%APPDATA%\LJ4W\lj4w.txt" ( 13 | ( 14 | echo default.all.interpreter=lj4w 15 | echo default.lua.interpreter=lua 16 | echo default.luajit.interpreter=lj4w 17 | echo lj4w.interpreter=^"%~0^" 18 | ) > "%APPDATA%\LJ4W\lj4w.txt" 19 | ) 20 | 21 | rem If the LJ4W_INTERPRETER_PATH environmental variable is already set, launch directly 22 | if not "%LJ4W_INTERPRETER_PATH%" =="" goto launch 23 | 24 | rem If the LJ4W_INTERPRETER environmental variable is already set, find interpreter path and launch 25 | if not "%LJ4W_INTERPRETER%" =="" goto launch_comment_header 26 | 27 | rem If no arguments/file given, open lj4w command prompt 28 | if "%1"=="" goto lj4w 29 | 30 | rem If argument given is not a file, pass to default interpreter 31 | if not exist "%~1" goto default.all.interpreter 32 | 33 | rem Read file header 34 | set /p LJ4W_INTERPRETER=<%1 35 | 36 | :bytecode_headers 37 | if not "%LJ4W_INTERPRETER:~,1%"=="" ( 38 | goto comment_headers 39 | ) 40 | if "%LJ4W_INTERPRETER:~,3%"=="LJ" ( 41 | goto default.luajit.interpreter 42 | ) 43 | if "%LJ4W_INTERPRETER:~,4%"=="Lua" ( 44 | goto default.lua.interpreter 45 | ) 46 | 47 | :comment_headers 48 | rem If header is not a comment, launch default interpreter 49 | if /i not "%LJ4W_INTERPRETER:~,2%"=="--" ( 50 | set LJ4W_INTERPRETER= 51 | goto default.all.interpreter 52 | ) 53 | rem If header comment is not interpreter parameter, launcher default interpreter 54 | if /i not "%LJ4W_INTERPRETER:~,15%"=="--interpreter: " ( 55 | set LJ4W_INTERPRETER= 56 | goto default.all.interpreter 57 | ) 58 | rem Clean up interpreter name 59 | set LJ4W_INTERPRETER=%LJ4W_INTERPRETER:~15% 60 | :launch_comment_header 61 | rem Check if the header is valid, report error and exit if not 62 | findstr /b /i %LJ4W_INTERPRETER%.interpreter "%APPDATA%\LJ4W\lj4w.txt" > nul || ( 63 | echo No "%LJ4W_INTERPRETER%" interpreter configured! 64 | exit /b 65 | ) 66 | rem Look up path for requested interpreter 67 | for /f "tokens=2 delims==" %%0 in ('findstr /b /i %LJ4W_INTERPRETER%.interpreter "%APPDATA%\LJ4W\lj4w.txt"') do ( 68 | set LJ4W_INTERPRETER_PATH=%%~0 69 | goto launch 70 | ) 71 | 72 | :default.all.interpreter 73 | rem Look up path for default interpreter and launch 74 | for /f "tokens=2 delims==" %%0 in ('findstr /b /i default.all.interpreter "%APPDATA%\LJ4W\lj4w.txt"') do ( 75 | findstr /b /i %%0.interpreter "%APPDATA%\LJ4W\lj4w.txt" > nul || ( 76 | echo The "default.all.interpreter" is misconfigured! 77 | exit /b 78 | ) 79 | for /f "tokens=2 delims==" %%a in ('findstr /b /i %%0.interpreter "%APPDATA%\LJ4W\lj4w.txt"') do ( 80 | set LJ4W_INTERPRETER=%%0 81 | set LJ4W_INTERPRETER_PATH=%%~a 82 | goto launch 83 | ) 84 | ) 85 | 86 | :default.luajit.interpreter 87 | rem Look up path for default LuaJIT interpreter and launch 88 | for /f "tokens=2 delims==" %%0 in ('findstr /b /i default.luajit.interpreter "%APPDATA%\LJ4W\lj4w.txt"') do ( 89 | findstr /b /i %%0.interpreter "%APPDATA%\LJ4W\lj4w.txt" > nul || ( 90 | echo The "default.luajit.interpreter" is misconfigured! 91 | exit /b 92 | ) 93 | for /f "tokens=2 delims==" %%a in ('findstr /b /i %%0.interpreter "%APPDATA%\LJ4W\lj4w.txt"') do ( 94 | set LJ4W_INTERPRETER=%%0 95 | set LJ4W_INTERPRETER_PATH=%%~a 96 | goto launch 97 | ) 98 | ) 99 | 100 | :default.lua.interpreter 101 | rem Look up path for default Lua interpreter and launch 102 | for /f "tokens=2 delims==" %%0 in ('findstr /b /i default.lua.interpreter "%APPDATA%\LJ4W\lj4w.txt"') do ( 103 | findstr /b /i %%0.interpreter "%APPDATA%\LJ4W\lj4w.txt" > nul || ( 104 | echo The "default.lua.interpreter" is misconfigured! 105 | exit /b 106 | ) 107 | for /f "tokens=2 delims==" %%a in ('findstr /b /i %%0.interpreter "%APPDATA%\LJ4W\lj4w.txt"') do ( 108 | set LJ4W_INTERPRETER=%%0 109 | set LJ4W_INTERPRETER_PATH=%%~a 110 | goto launch 111 | ) 112 | ) 113 | 114 | :launch 115 | rem Launch appropriate lua implementation 116 | if exist "%LJ4W_INTERPRETER_PATH%" ( 117 | if /i "%LJ4W_MIXED%"=="true" call :clean_mixed 118 | if /i "%LJ4W_INTERPRETER_PATH%"=="%~0" goto lj4w 119 | title %LJ4W_INTERPRETER_PATH% 120 | call "%LJ4W_INTERPRETER_PATH%" %* 121 | exit /b 122 | ) 123 | rem Report error if requested lua implementation is not configured properly 124 | echo "%LJ4W_INTERPRETER%" cannot be found at "%LJ4W_INTERPRETER_PATH%"! 125 | if /i "%LJ4W_MIXED%"=="true" call :clean_mixed 126 | exit /b 127 | 128 | :clean_mixed 129 | set LJ4W_INTERPRETER= 130 | set LJ4W_INTERPRETER_PATH= 131 | exit /b 132 | 133 | :lj4w 134 | rem Set window title 135 | title LuaJIT For Windows 136 | 137 | rem Set base LuaJIT directory (LUADIR) 138 | set LUADIR=%~dp0 139 | set LUADIR=%LUADIR:~,-1% 140 | 141 | rem Set paths 142 | set PATH=%LUADIR%\tools\cmd;%LUADIR%\tools\PortableGit\mingw64\bin;%LUADIR%\tools\PortableGit\usr\bin;%LUADIR%\tools\mingw\bin;%LUADIR%\lib;%LUADIR%\bin;%APPDATA%\LJ4W\LuaRocks\bin;%PATH% 143 | set LUA_PATH=%LUADIR%\lua\?.lua;%LUADIR%\lua\?\init.lua;%APPDATA%\LJ4W\LuaRocks\share\lua\5.1\?.lua;%APPDATA%\LJ4W\LuaRocks\share\lua\5.1\?\init.lua;%LUA_PATH% 144 | set LUA_CPATH=%APPDATA%\LJ4W\LuaRocks\lib\lua\5.1\?.dll;%LUA_CPATH% 145 | 146 | rem If arguments are being sent, pass to LuaJIT and exit 147 | if not "%1"=="" ( 148 | call "%LUADIR%\bin\luajit.exe" %* 149 | exit /b 150 | ) 151 | 152 | rem Prepare command prompt environment 153 | set APPDATA=%APPDATA%\LJ4W 154 | if not exist "%APPDATA%\LuaRocks" md "%APPDATA%\LuaRocks" 155 | if not exist "%APPDATA%\LuaRocks\default-lua-version.lua" echo return "5.1">"%APPDATA%\LuaRocks\default-lua-version.lua" 156 | if not exist "%APPDATA%\LuaRocks\config-5.1.lua" call luarocks config > "%APPDATA%\LuaRocks\config-5.1.lua" 157 | 158 | rem Command prompt 159 | echo ***** LuaJIT For Windows ***** 160 | for /f "tokens=*" %%0 in ('call luajit -v^&call luarocks --version ^| grep -v main^&call gcc --version ^| grep clang') do echo %%0 161 | echo. 162 | cmd /k -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![Say Thanks!](https://img.shields.io/badge/Say%20Thanks-!-1EAEDB.svg)](https://docs.google.com/forms/d/e/1FAIpQLSfBEe5B_zo69OBk19l3hzvBmz3cOV6ol1ufjh0ER1q3-xd2Rg/viewform) 2 | 3 | # LuaJIT For Windows 4 | LuaJIT For Windows packages LuaJIT, LuaRocks, a Mingw-w64 tool chain, and git for a modern and easy-to-use all-in-one Lua solution that can be distributed as a standard Lua environment for any Lua workflow running on a 64-bit Windows platform. 5 | 6 | **Download the full pre-bundled self-extracting package here:** 7 | https://github.com/ScriptTiger/LuaJIT-For-Windows/releases/latest 8 | 9 | **LuaJIT** 10 | OpenResty's implementation of LuaJIT has been chosen since it's well maintained by a larger active contributor base as an ongoing branch of the original LuaJIT and therefore compatible with LuaJIT scripts and bytecode, compatible with Lua 5.1 scripts, as well as features additionally curated add-ons for an added bonus to keep you on the bleeding edge of Lua development. 11 | https://github.com/openresty/luajit2 12 | 13 | **LuaRocks** 14 | LuaRocks is a well-known and well-established Lua package manager which makes it easy to search, install, update, and remove Lua packages which are available through Lua repositories. It should be noted that while not all packages are compatible with LuaJIT, most common packages are. So, please refer to the documentation provided by the respective package maintainers for more information about compatibility. 15 | https://luarocks.org 16 | https://github.com/luarocks/luarocks 17 | 18 | **Mingw-w64** 19 | For those familiar with cross-platform development, or for those who just love the tool, Mingw-w64 needs no introduction. LLVM MinGW brings the standard Mingw-w64 environment needed to compile various components that may come with LuaRocks packages, so having the MSVC suite installed is not necessary. 20 | https://github.com/mstorsjo/llvm-mingw 21 | 22 | **git** 23 | Another staple of open source, git provides the LuaJIT For Windows package the necessary functionality of interacting directly with git repositories using the git protocol. 24 | https://git-scm.com/download/win 25 | 26 | # How it Works 27 | LuaJIT for Windows is designed with portability and flexibility in mind. Once the self-extracting package extracts LuaJIT For Windows to the directory of your choosing, you can immediately run it without any installation via the `LuaJIT-For-Windows.cmd`. 28 | 29 | The `LuaJIT-For-Windows.cmd` acts as both a Lua script launcher and development environment all in one and allows you to seamlessly run different implementations of Lua all from the same script. In fact, you can even set `LuaJIT-For-Windows.cmd` as the default application to open any file with a `.lua`, `.luac`, or other Lua file extension and it will automatically launch it using your pre-configured settings. At the same time, because of the ability `LuaJIT-For-Windows.cmd` has to read file headers, there is also no longer any need to have multiple file extensions to maintain Lua scripts for specific Lua implementations, which can oftentimes just cause problems when sharing Lua scripts with others who have different file associations from you on their system. 30 | 31 | **`LuaJIT-For-Windows.cmd` as a Lua Script Launcher** 32 | When you first run `LuaJIT-For-Windows.cmd`, the `lj4w.txt` will be created with some default preferences in the `%APPDATA%\LJ4W` directory (i.e. `C:\Users\YourName\AppData\Roaming\LJ4W`). The three pre-configured keys defined are `default.all.interpreter`, `default.lua.interpreter`, and `default.luajit.interpreter`. 33 | 34 | While their values can be changed, and further custom key-value pairs entered, these three default keys must always be present. The `default.all.interpreter` is used to determine which Lua implementation to use by default for any script without a header designating which implementation to use. The `default.lua.interpreter` is used to determine which Lua implementation to use when executing Lua bytecode generated from Luac. And `default.luajit.interpreter` is used to determine which LuaJIT implementation to use when executing LuaJIT bytecode. While both the `default.all.interpreter` and `default.luajit.interpreter` start off with the `lj4w` value and associated `lj4w.interpreter` key defining the full path to the `LuaJIT-For-Windows.cmd`, `default.lua.interpreter` is pre-configured with the `lua` value but no associated `lua.interpreter` defining its path. Therefore, you must add the full path of your `lua.exe` to the `lua.interpreter` value, as an example, in order to use this feature. Otherwise, if `lua.interpreter` is left undefined, or whatever value you choose to associate with `default.lua.interpreter` (i.e. `foo` value and associated `foo.interpreter` key), you will encounter an error when attempting to execute Luac bytecode. 35 | 36 | Aside from the aforementioned default keys mentioned, any number of further custom key-value pairs can be defined for custom headers, designated by the `--interpreter` header on the first line of a script (i.e. `--interpreter: foo`). So, for example, if you want to use the `foo` implementation of Lua for certain scripts, you can put `--interpreter: foo` on the first line of the script and it will automatically launch that script using the associated `foo.interpreter` as defined in the `lj4w.txt`. So, there is no longer a need to have multiple file extensions, and instead a simple file header can be used. 37 | 38 | An important note here is that, by default, if you are running multiple Lua scripts consecutively within the same environment, `LuaJIT-For-Windows.cmd` will attempt to use the same Lua implementation determined for the first script for all subsequent scripts within the same environment session in order to speed up launching subsequent scripts. However, you can set the `LJ4W_MIXED` environmental variable to `true` in order to force `LuaJIT-For-Windows.cmd` to determine which interpreter to use for every script if you are using mixed scripts within the same environment session (i.e. mixing LuaJIT and/or Lua scripts and/or bytecode). Running mixed scripts within the same environment session is not that common, however, since most projects only bundle together scripts that are intended for the same target implementation. 39 | 40 | For maximum flexibility, the `LJ4W_INTERPRETER` and/or `LJ4W_INTERPRETER_PATH` environmental variables can also be set, which act in the same way as the key-value pairs in the `lj4w.txt`. This can be useful to further speed up launch times or to specify things that can't be specified otherwise, such as alternative Lua implementations to use for bytecode files other than the defaults listed in the `lj4w.txt`, since custom headers cannot be added to bytecode files. If only the `LJ4W_INTERPRETER` is given, `LuaJIT-For-Windows.cmd` will attempt to set the `LJ4W_INTERPRETER_PATH` automatically by looking up the associated key-value pair in the `lj4w.txt`. Specifying the `LJ4W_INTERPRETER_PATH` explicitly will, alternatively, skip all lookups and go straight to launch the script using the interpreter at the path specified. 41 | 42 | **`LuaJIT-For-Windows.cmd` as a Development Environment** 43 | When launching `LuaJIT-For-Windows.cmd` as a stand-alone script without any arguments, it will open a development environment where you will have access to all of the tools available within the LuaJIT For Windows package. So, whether you want to access LuaRocks to manage packages, access LuaJIT's REPL interface, access gcc or any of the other tools within the LLVM MinGW suite, you can do so immediately all from the same environment. 44 | 45 | An important note for the development environment is that the `APPDATA` environmental variable is changed to `%APPDATA%\LJ4W` during a session in order to ensure that LuaRocks and all of its components remain isolated from any pre-existing LuaRocks trees which may be present. This change is only in effect while using the development environment and does not affect scripts which are directly launched via the script launcher functionality. 46 | 47 | # More About ScriptTiger 48 | 49 | For more ScriptTiger scripts and goodies, check out ScriptTiger's GitHub Pages website: 50 | https://scripttiger.github.io/ 51 | --------------------------------------------------------------------------------