user14439458
user14439458

Reputation: 51

How do you run a .lua file in Terminal (Mac)

I want to run a Lua file on Mac through the Terminal. Python and Java have their own respective commands, but how can I run a script file for Lua on a Mac OSx through a Terminal command? I'm fairly new to the Terminal but have some experience in Lua, and can anybody help me? It would be greatly appreciated, thanks! 😃

Upvotes: 5

Views: 9842

Answers (3)

Evert_B
Evert_B

Reputation: 273

From the terminal:

brew install lua (This installs the lua interpreter)
lua yourfile.lua (This runs yourfile.lua in the interpreter)

Disclaimers:

  • There are installation alternatives to brew. Google lua installation macos and use what feels most comfortable to your flow.
  • You could also use a shebang on the first line and make the file executable. There is more than 1 option available here. The one listed above is the best to get going fast and easy.

Upvotes: 8

Doyousketch2
Doyousketch2

Reputation: 2147

Once you have Lua installed, such as through the brew command mentioned before, you can make your script run in terminal with these few steps:

#! /usr/bin/env lua  --  add hashbang header to script

chmod +x *.lua  --  make your script executable

./scriptname.lua  --  run it

Upvotes: 2

Piglet
Piglet

Reputation: 28940

From https://www.lua.org/start.html

To run Lua programs on your computer, you'll need a standalone Lua interpreter and perhaps some additional Lua libraries. Use your favorite text editor to write your Lua programs. Make sure to save your programs as plain text. If you want an IDE, try ZeroBrane Studio.

If you use Linux or Mac OS X, Lua is either already installed on your system or there is a Lua package for it. Make sure you get the latest release of Lua (currently 5.4.1).

Lua is also quite easy to build from source, as explained below....

From the Lua FAQ

... Chapter 1 of the book Beginning Lua Programming contains detailed instructions for downloading, building, and installing Lua. Here are simple instructions for Linux and Mac OS X:

curl -R -O http://www.lua.org/ftp/lua-5.4.1.tar.gz
tar zxf lua-5.4.1.tar.gz
cd lua-5.4.1
make all test

I suggest you also read that Chapter 1 or ideally the entire book and of course the Lua reference manual.

Once you have the Lua standalone interpreter installed you simply run it like any other command line executable

Upvotes: 0

Related Questions