2

How do you add Lua into the path variable so that I can just type

lua filename.lua

in cmd to run it?

I'm using Windows 8.1 64 bit

Yu Hao
  • 119,891
  • 44
  • 235
  • 294
Fderal
  • 457
  • 1
  • 6
  • 11

2 Answers2

1

You can also do this directly from a cmd.exe shell. Open a "Command Prompt" and type in:

setx path "x:/your/lua/path/goes/here;%path%" /M

Restart the Command Prompt for it to take effect.

greatwolf
  • 20,287
  • 13
  • 71
  • 105
  • I tried this but it didn't work. When I type lua plus my file name, all it does is say lua: no such file or directory exists. Do I have to put my lua script in the same folder as the lua interpreter? – Fderal Nov 16 '13 at 14:11
  • @Kamiccolo That opens up the Run prompt. Typing "lua" on it works provided that lua's installed directory is in the environment `PATH`. – greatwolf Nov 16 '13 at 22:49
  • @Fderal Can you go over the steps you did exactly? What's the exact command you typed? Are you sure the added path is correct? You can check it by running lua with its full absolute path prefixed. Afterwards did you close all instances of `cmd.exe` before opening another command prompt? Best to add this problem to your question above. – greatwolf Nov 16 '13 at 22:51
  • I needed to remove the /M, but it worked (windows 7) – Ricardo A. Nov 05 '19 at 19:44
0

First you must ensure that lua.exe is on your PATH: from the console where you want to run it, just type "lua" and ENTER; if you end up in Lua interpreter, the answer is yes. If you get command not found, you must extend PATH, either in the console (then you will have to do it every time you open a new console), or via the operating system's environment variables (via control panel as described by Yu Hao, or via setx as descripbed by greatwolf).

Once lua.exe is in your PATH, the first command line parameter you provide to the lua.exe must be the path to the .lua file. So if the current working directory in console is C:\Foo\bar, and your script is in C:\Foo\bar, then all you need to type is "lua yourScript.lua". If your script is instead in C:\Foo\cla, then you would type "lua ..\cla\yourScript.lua". To verify what is th current working folder, type "cd" then ENTER, it is the path printed.

Oliver
  • 27,510
  • 9
  • 72
  • 103