Windows How to install Lua on Windows? (1 Viewer)

D

Deleted member 2

Guest
I'm new to the Lua programming language. How to install Lua on Windows?
I've searched for videos but no luck.
 

stetre

Member
Rank: I
Joined
Jan 8, 2020
Messages
19
Reaction score
19
Location
Italy
Website
github.com
There are several ways to do it. I personally favour using the MSYS2 installer because it also allows me
to build a lot of useful other packages. The method goes as follows:

1) Download and install MSYS2 following the instructions at the link above. Then, assuming MSYS2 is installed
at the default location C:\msys32 (if not, change the paths below accordingly):

2) Open a MinGW shell using the launcher C:\msys32\mingw64.exe (or C:\msys32\mingw32.exe if you
have a 32-bit system), and install Lua using the following command (here the $ sign is the shell prompt):
Bash:
$ pacman -S ${MINGW_PACKAGE_PREFIX}-lua

Now you can use the Lua interpreter from any MinGW shell, by just typing the lua command in it:

Bash:
$ lua

If you want to use it also from the Windows command prompt, you have to append the path C:\msys32\mingw64\bin
to the Windows PATH environment variable (or C:\msys32\mingw32\bin, on a 32-bit system).

(If you don't know what PATH is ,or how to modify it, just google "windows PATH environment variable" and you'll
find plenty of instructions).
 

kinderalpha

Member
Rank: I
Joined
Jan 9, 2020
Messages
8
Reaction score
11
Age
23
Location
Chicago
Lua is often times uses as an embedded language, or an API for scripting within a game environment so Lua outside of either of those implementations isn't quite useful. Are you asking how to install Lua to use it for something specific?

If you're looking to use it for game development, I would suggest looking into Love2D as that's the most recent and to-date usage of Lua for a game development framework.
 
D

Deleted member 2

Guest
There are several ways to do it. I personally favour using the MSYS2 installer because it also allows me
to build a lot of useful other packages. The method goes as follows:

1) Download and install MSYS2 following the instructions at the link above. Then, assuming MSYS2 is installed
at the default location C:\msys32 (if not, change the paths below accordingly):

2) Open a MinGW shell using the launcher C:\msys32\mingw64.exe (or C:\msys32\mingw32.exe if you
have a 32-bit system), and install Lua using the following command (here the $ sign is the shell prompt):
Bash:
$ pacman -S ${MINGW_PACKAGE_PREFIX}-lua

Now you can use the Lua interpreter from any MinGW shell, by just typing the lua command in it:

Bash:
$ lua

If you want to use it also from the Windows command prompt, you have to append the path C:\msys32\mingw64\bin
to the Windows PATH environment variable (or C:\msys32\mingw32\bin, on a 32-bit system).

(If you don't know what PATH is ,or how to modify it, just google "windows PATH environment variable" and you'll
find plenty of instructions).
Is there any program with highlighting and error checking where I can just click build like Netbeans?
 

stetre

Member
Rank: I
Joined
Jan 8, 2020
Messages
19
Reaction score
19
Location
Italy
Website
github.com
Is there any program with highlighting and error checking where I can just click build like Netbeans?

I'm pretty sure that there are IDEs with support for Lua. I often read good things about Zerobrane, for example,
but honestly I'm not the right person to suggest one because I'm a vim addicted and I develop under Linux using
command line tools and window terminals (and less need for RAM...).

Hopefully some other user can give you more informed suggestion about the available IDEs.
 

kinderalpha

Member
Rank: I
Joined
Jan 9, 2020
Messages
8
Reaction score
11
Age
23
Location
Chicago
Zerobrane is the way to go for that in my opinion. It kinda varies based on what environment you're using Lua for. I use it for Love2D so zerobrane offers out of the box debug and highlighting support for Lua and syntax completion for Love. It has standard highlighting for Lua too. It also is configurable to setup a 'build' path depending on what you need. In my case, I can use it to build, debug, scratchpad, and Iog errors on completion. If you just want a text editor with highlighting then Atom, sublime, and notepad++ are good lightweight options.
 

Ray

Newcomer
Joined
Feb 4, 2020
Messages
3
Reaction score
2
Age
63
Location
USA
If you're running Cygwin (or MobaXterm, which has Cygwin built in) on your Windows PC, you can install Lua from inside Cygwin. Just use Cygwin's or Lua's package manager, search for "lua", select all of the packages that it offers you (well, that may be too many, but I can't tell you which ones NOT to select), and tell Cygwin to install them.

Then you can type "lua" at the command prompt to get the Lua shell, or "lua myfilename.lua" to execute a Lua file.

(What's "Cygwin"? It's a Linux-like environment, similar to Msys/MinGW.)
 

Maksumić

Administrator
Staff member
Joined
Jan 6, 2020
Messages
16
Reaction score
3

Full Lua Installation on Windows 10​

This tutorial shows you how to install Lua on Windows 10. The tutorial is meant for beginners.


  • Run the installer and click next with all the default settings (unless you know what you're doing.)
  • After the installation is complete, open SciTE from your desktop.

  • Write print "Hello, Lua!"
  • Click the disc icon (or CTRL+S) to save the Lua script

  • Name it hello_lua.lua (remember the .lua file extension.)

  • Click the play button (or F5) to run the Lua script


Success!
 

Maksumić

Administrator
Staff member
Joined
Jan 6, 2020
Messages
16
Reaction score
3

Install Lua on Windows 10 (build from sources)

This tutorial shows you how to build and install Lua on Windows 10 from sources.
The tutorial is not meant for complete beginners.

Download and install TDM-GCC​

  • Go to the downloads section or download TDM64-GCC-9.2.0.exe
  • Run the executable
  • Select "Create a new TDM-GCC installation"
  • Select "MinGW-w64/TDM64 (32-bit and 64-bit)"
  • Keep the default C:\TDM-GCC-64\ directory
  • Select "TDM-GCC Recommended, C/C++"

Download the Lua sources​

5.4.1 is the current Lua version as of this tutorial

Unpack the sources with 7-Zip​

You will also need 7-zip to unpack lua-5.4.1.tar.gz on Windows. The .tar.gz file format is very common on Linux, but not on Windows.

Download 7-Zip directly: 7-Zip 19.00 (2019-02-21) 64-bit (x64)

  1. Move lua-5.4.1.tar.gz to your C:/ directory
  2. Right click lua-5.4.1.tar.gz and click on "open with"
  3. Select always use this app to open .tar.gz
  4. Click on "more apps" and scroll down
  5. Click on "look for another app on this pc"
  6. Go to C:\Program Files\7-Zip and select 7zFM (7-Zip File Manager)
  7. Extract the source directory to your C:/ directory

Run the build script​

Before we can run the build script, we have to setup the correct directory (i.e. folder) structure.
  • Create the directory C:/gcc-lua-install/
  • Move lua-5.4.1 to C:/gcc-lua-install/
  • Move TDM-GCC-64 to C:/gcc-lua-install/
  • Save the script below as build.cmd inside C:/gcc-lua-install/


NOTE: If you downloaded a Lua version different from 5.4.1, update the version on the line set lua_version=5.4.1 in the script below.

Bash:
@echo off
        :: ========================
        :: file build.cmd
        :: ========================
        setlocal
        :: you may change the following variable's value
        :: to suit the downloaded version
        set lua_version=5.4.1

        set work_dir=%~dp0
        :: Removes trailing backslash
        :: to enhance readability in the following steps
        set work_dir=%work_dir:~0,-1%
        set lua_install_dir=%work_dir%\lua
        set compiler_bin_dir=%work_dir%\TDM-GCC-64\bin
        set lua_build_dir=%work_dir%\lua-%lua_version%
        set path=%compiler_bin_dir%;%path%

        cd /D %lua_build_dir%
        mingw32-make PLAT=mingw

        echo.
        echo **** COMPILATION TERMINATED ****
        echo.
        echo **** BUILDING BINARY DISTRIBUTION ****
        echo.

        :: create a clean "binary" installation
        mkdir %lua_install_dir%
        mkdir %lua_install_dir%\doc
        mkdir %lua_install_dir%\bin
        mkdir %lua_install_dir%\include

        copy %lua_build_dir%\doc\*.* %lua_install_dir%\doc\*.*
        copy %lua_build_dir%\src\*.exe %lua_install_dir%\bin\*.*
        copy %lua_build_dir%\src\*.dll %lua_install_dir%\bin\*.*
        copy %lua_build_dir%\src\luaconf.h %lua_install_dir%\include\*.*
        copy %lua_build_dir%\src\lua.h %lua_install_dir%\include\*.*
        copy %lua_build_dir%\src\lualib.h %lua_install_dir%\include\*.*
        copy %lua_build_dir%\src\lauxlib.h %lua_install_dir%\include\*.*
        copy %lua_build_dir%\src\lua.hpp %lua_install_dir%\include\*.*

        echo.
        echo **** BINARY DISTRIBUTION BUILT ****
        echo.

        %lua_install_dir%\bin\lua.exe -e"print [[Hello!]];print[[Simple Lua test successful!!!]]"

        echo.

        pause
  • Double-click on build.cmd


Running Lua​

Now that we have successfully built Lua from sources, let's try to run a script!
  • Create a new file hello.lua
  • Add the following code print "I built Lua on Windows from sources!" to hello.lua
  • Open the command line
  • Type cd C:\gcc-lua-install\lua\bin
  • Type lua the-path-to-your-script\hello.lua

  • Success!

Adding Lua to Windows 10 Environment Variables​

It is cumbersome to always have to execute Lua scripts from the C:\gcc-lua-install\lua\bin directory. Therefore, we add the Lua executable to the Windows 10 Environment Variables.
  • Open "Edit the system environment variables"
  • Click on "environment variables", "new", "browse file", find and select the Lua executable
  • Set the "variable name" to Lua
  • Click on ok
  • Restart your system
  • Open your command line (cmd), and type lua and hit enter
  • You should see something like Lua 5.4.1 Copyright (C) 1994-2020 Lua.org, PUC-Rio
  • Success! You can now run Lua scripts from anywhere on your Windows 10 computer!
 

Attachments

  • build.cmd
    1.8 KB · Views: 0
Top