How to properly set up environment for Lua

2k views Asked by At

could you please help me set up environment for Lua in Windows. I have added following C:\lua\bin to the PATH system env. variables. But when I try to run file for example test.lua with print("hello world") interpreter probably sees the file but I get this message in git-bash:

$ test.lua
/c/lua/bin/test.lua: line 1: syntax error near unexpected token "hello world"
/c/lua/bin/test.lua: line 1: print("hello world")

And when I try to open test.lua in cmd there are no errors just the Notepad with code opens...but code in file isnt executed. Thank you

3

There are 3 answers

1
Tanner Swett On

bash and cmd don't know that you want to execute the file using the Lua interpreter.

I assume that the Lua interpreter is at C:\lua\bin\lua.exe? If so, you should be able to run your script using the command lua test.lua. In bash, you might need to do /c/lua/bin/lua test.lua instead.

2
Egor   Skriptunoff On

Example:

I have lua53.exe in the folder C:\Lua\
I did not add this path to system variable PATH.

This is my Lua file "a.lua" containing shebang:

$ cat a.lua
#!/c/Lua/lua53
print"Hello"

And this is how I run it:

$ ./a.lua
Hello

P.S.
You are allowed to terminate shebang line with Windows-style newline CR LF (such shebang will not work on *nix), so using Notepad to edit Lua files is Ok.

1
moteus On

You can associate path extension with Lua executable like

ftype LuaScriptx86=c:\lua\x86\5.1\lua5.1.exe "%1" %*
assoc .lua=LuaScriptx86

(do not forget quotes around first argument) And then add .LUA to PATHEXT env variable. So you will be able run just test instead of lua test.lua