How to install Lua on windows
Asked Answered
A

3

8

I'm new to Lua, and need to know how to install it on Windows?

I've tried and am unable to run the sample. When I try to compile it 100% success is shown, but when I click the run button it shows this error:

Can't find moai executable in any of the folders in PATH or MOAI_BIN:
C:\Program Files\moai, D:\Program Files\moai, C:\Program Files (x86)\moai, D:\Program Files (x86)\moai, C:\WINDOWS\system32, C:\WINDOWS, C:\WINDOWS\System32\Wbem, C:\moai-sdk\bin\win32\moai.exe, C:\moai-sdk/bin 

If anyone can help me on how to install Lua, thanks.

Appliance answered 22/5, 2013 at 11:55 Comment(5)
What does MOAI have to do with Lua? And what "sample" are you trying to run?Queenqueena
Probably, you should firstly build moai.exe with Visual Studio. Read "Developing on Windows" sectionCounterfeit
@EgorSkriptunoff i mentioned the moai.exe in environmental variable .So please can you give brief idea.Appliance
This question was recently asked before. Take a look at this question here.Rentroll
And this answer may be useful too.Stenophagous
D
5

The easiest way nowsday is using WinGet:

 winget install "Lua for Windows"

WinGet is default included in Windows 11. In previous Windows version, you could install it from Windows Store. It is very convenient.

Doralynn answered 14/4, 2023 at 16:9 Comment(1)
It seems it isn't maintained anymore.Bertrando
T
3

Lua does not have a certified IDE or compiler to come with it. You usually run lua code from a lua command line / lua file which will handle the tasks you are attempting to create.

Downloading

Lua has a website where you can download their tools which will allow you to write and execute lua code: https://www.lua.org/download.html

Using lua console

After you download the file, put it in a file location anywhere on your computer, in order execute lua code; the first method is to open the lua console and simply type out your command: https://prnt.sc/ibw97h

Another method you can use, is make a .txt or .lua file, write your code in that, then you can drag and drop the file onto the lua console to execute it: https://prnt.sc/ibwa2f

Installing lua system wide

Add lua in the environment variables by adding the path from where it's installed. After doing this you can open PowerShell and enter lua53.exe to open lua.

Additional details

Although these is what lua directly offers, there are other third party alternatives of compiling and executing lua code. Examples of these can be found if you search for them.

Thevenot answered 8/2, 2018 at 14:17 Comment(1)
Your screenshots seem to have expired?Knighterrant
P
0

Using Windows based package managers

If you do not wish to build and compile Lua yourself, you can use Windows based package managers like Winget, Scoop or Chocolatey. Keep in mind that Winget and Chocolatey install lua from the same source, so you will only get up to Lua 5.1, Scoop however can install the latest version of Lua.

  • Winget: winget install "Lua for Windows" as described in YoungForest's answer.
  • Chocolatey: choco install lua
  • Scoop: scoop install lua

If you installed Lua with one of these package managers and want to use LuaRocks, you will need to install it and GCC with the same package manager.

If you did not install LuaRocks with a package manager

My stupid ass did that so let me tell you how to fix it, I will be using Scoop as my example.

Specifying your version of Lua and GCC to LuaRocks when Lua was installed with Scoop
  1. Find out where LuaRock's config.lua file is on your system: run luarocks you should find it right at the end of the output in the "Configuration files" section
  2. Modify the config-x.y.lua file with the correct paths to your installations of Lua and GCC, mine looks like this:
variables = {
   LUA = "C:\\Users\\admin\\scoop\\apps\\lua\\current\\lua54.exe",
   CC = "C:\\Users\\admin\\scoop\\apps\\gcc\\current\\bin\\gcc.exe",
   CXX = "C:\\Users\\admin\\scoop\\apps\\gcc\\current\\bin\\g++.exe",
}
LuaRocks tries to invoke GCC with the wrong command

If the config file is set correctly it shouldn't happen, but it happened to me.

In this case you can create a symlink of gcc.exe with this command as its name. If you installed it without a package manager for example, instead of trying gcc it will try x86_64-w64-mingw32-gcc so get in the directory where gcc.exe is located and in PowerShell do:

New-Item -ItemType SymbolicLink -Path .\x86_64-w64-mingw32-gcc.exe -Target .\gcc.exe

You should be able to see what command LuaRocks is trying in the error message when you try to install a library with it.

Periphrastic answered 3/5, 2024 at 2:23 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.