Skip to content

Instantly share code, notes, and snippets.

@Egor-Skriptunoff
Last active February 2, 2024 14:36
Show Gist options
  • Save Egor-Skriptunoff/22bf55c1abe44d7825605e132e48c084 to your computer and use it in GitHub Desktop.
Save Egor-Skriptunoff/22bf55c1abe44d7825605e132e48c084 to your computer and use it in GitHub Desktop.
How to build windowless LuaJIT for Windows

What is "windowless LuaJIT"?

Windowless LuaJIT does not create a console window.
It runs invisible for user.

Please note that "windowless" means "doesn't have stdin, stdout and stderr".
You will not be able to see error message.
io.read(), io.write() and print() in your Lua script will not work.
But in some situations invisible LuaJIT is just what you need very much.
For example, to avoid a GUI application (especially a game) to lose input focus when some background Lua script is started.


How to build 64-bit windowless LuaJIT 2.1 binaries for Windows

  1. Download the latest LuaJIT sources

    • Create temporary folder for LuaJIT sources.
      I assume you would use C:\Temp\ folder.

    • Download and install Portable "Git for Windows"

    • Run git-cmd.exe, a console window will open.

    • Execute the following commands in this console window:
      cd /d C:\Temp\
      git clone https://luajit.org/git/luajit.git
      cd luajit
      git checkout v2.1

    • Close the console window.
      Now you have LuaJIT 2.1 sources in the folder C:\Temp\luajit\

    • You can uninstall "Git for Windows" application now.
      It's portable, so just remove its folder.

  2. Modify LuaJIT sources

    • Open folder C:\Temp\luajit\src\

    • Find the file luajit.c, right-click it and select "Edit".
      Notepad will open.

    • Scroll down to the end of the file and add the following 2 lines after the last line:
      int __stdcall WinMain(void* hInstance, void* hPrevInstance, char* pCmdLine, int nShowCmd)
      { return main(__argc, __argv); }

    • Save the file and close Notepad.

  3. Build LuaJIT binaries using MinGW64

    • Download and install MSYS2.
      It is recommended to install MSYS2 in the default destination folder C:\msys64\,
      but you may choose another path consisting of English letters without spaces.

    • After installation is complete, a MSYS2 console window will open.
      Execute the following command in this MSYS2 console window:
      pacman -S mingw-w64-x86_64-gcc mingw-w64-x86_64-make
      When asked Proceed with installation? [Y/n], answer Y and press Enter.

    • Close this MSYS2 console window and open a new one by clicking the MSYS2 MinGW 64-bit menu item in Windows Start menu.
      Execute the following commands in the new MSYS2 window:
      cd /c/Temp/luajit/
      mingw32-make CFLAGS=-DLUAJIT_ENABLE_LUA52COMPAT TARGET_LDFLAGS=-mwindows

    • Close the MSYS2 console window.

    • You can uninstall MSYS2 application now at Control Panel -> Programs and Features.

  4. Take LuaJIT binaries

    • Open folder C:\Temp\luajit\src\
      Sort files by "Date Modified".

    • Find luajit.exe among the most recently modified.
      Rename it to wluajit.exe

    • Take 2 files: wluajit.exe and lua51.dll
      and put them to the folder where Lua binaries should be on your system.

    • You can remove LuaJIT sources now.
      Delete folder C:\Temp\luajit\

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment