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

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! 😃

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.

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

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

Related

Uninstalling Lua

How in the world do I get rid of Lua on my Macbook Air?
I installed the programming language just to test it out and now I am not sure how to get rid of it.
I used the official Lua website <lua.org> to install it and followed the instructions on the download page using 'curl' or whatever it is.
I am a programming beginner. Other languages, like Java and Python, don't have this issue. Can someone please help me get rid of the annoying thing? I don't need it clogging up my computer.
Lua's Makefile has an uninstall target which should allow you to remove it from your system. cd to the Lua source directory (lua-5.4.3 for the current version) and type this command:
sudo make uninstall
The sudo is required if you need administrative privileges to remove software.
(I'm not familiar with MacOS, but from the comments, it seems to work the same way as it does on GNU systems.)

Is it possible to run sdl2-config on Windows?

It seems there are several times when running the sdl2-config script bundled with SDL2 would be useful (such as checking which libraries need to be linked to). But it doesn't seem possible to run this script natively on Windows.
I'm using I've been using mingw for all my C compiling needs so far, if that helps. Is there any way I can run this script on Windows?
Yes, sure!
However, that script is just a Bash script, so you need to install Cygwin which has Bash built in. It is not recommended to use the native (Win10) port of the Bash shell, since it is not behaving as expected.
If you don't already have it installed, then the tricky part is how to install SDL2 using Cygwin. IMHO, that should probably be avoided, as it tend to cause a lot of weird problems (for other packages).
However, there is already a Cygwin package if you want to try it.
apt-cyg install mingw64-x86_64-SDL2 libSDL2-devel libSDL2_2.0_0 # etc

Trouble opening Ncurses Examples in OS X

I recently downloaded ncurses from here and have compiled it using ./configure and make
As it is recommended in the README, I compiled the example programs that come bundled with the package. The programs compiled without any issue, but every time I run the programs I get the following errors:
Terminal type "xterm-256color"
terminals database is inaccessible
Changing the terminal's type using TERM=xterm and export TERM don't seem to solve this issue, and I'm just stuck. Will ncurses work if I included them in my C/C++ programs, or should I make sure the examples work?
Thanks in advance
Probably you did not install the terminal database, or did not tell the programs where to find it.
OSX comes with ncurses 5.7 (old, but not the problem here), with the terminal database in /usr/share/terminfo. However by default the configure script assumes you want to install in /usr/local. You can tell the programs where there's a terminal database by setting the TERMINFO environment variable, or (better), setting TERMINFO_DIRS to list both locations (with the newer one first of course).
For a start, something like
export TERMINFO=/usr/share/terminfo
should be enough to make the examples run.
Further reading:
TERMINFO
TERMINFO_DIRS

Running Lua scripts - Windows 64 bit

Recently I've started learning Lua programming language but I don't know how to run the scripts I'm writing(.lua files). Basically I'm practicing in eclipse with Eclipse LDT, but I want to run my scripts more freely, like in cmd. What do I need to do?
You can download the Lua source here or the binaries here. After that, simply install the Lua interpreter and open your command line.
There are two ways to use Lua with the shell:
directly:
lua
running a Lua script:
lua script.lua
In this post you can find various Lua editors or development environments.
Please use google or other search engines first.

How to develop in Linux-Like Shell (bash) on Windows?

I'm Windows user. But according to my project requirements, I need to write Linux Shell Script(Bash shell). How to develop Linux Shell on Windows?
Is there any IDE for writing Linux Shell Scripting? Please share me some ideas and resource links.
You have quite a number of options:
cygwin
Install cygwin. It will give you a bash.
mingw
The minimal GNU for windows. Comes with set of commands, compilers. This came with my Git on Windows and now the default shell for small scripts
VM, such as VirtualBox
There are tons on VMs, VirtualBox being easy to use(it powers the Boot2Docker). You can do development and test on real Linux distros.
Ubuntu on Windows 10
There is new kid on the block. This allows you to run User Space Ubuntu using Windows Subsystem for Linux (WSL). see more on it at Microsoft blog
Other notes/IDE support
Shell scripts should be small, requires less IDE etc. I use VIM with syntax highligthing. But it seems ShellED may be useful in your case. I got the link from answer for this question - Bash script plugin for Eclipse?
IntelliJ has couple of plugins too for Bash..
I prefer Gow (Gnu on Windows) over Cygwin. Both will give you bash on Windows, but Cygwin has unnatural conventions for filesystem access (/cygdive/c/some/path instead of c:\some\path).
The native windows command terminal is pretty lame, take a look at Conemu.
I'm not aware of any bash IDE, but there are a plethora of windows text editors with decent syntax highlight for bash scripts. I like Notepad++ and Sublime text (the multiple cursor feature from Sublime rocks!). I don't recommend bash for anything with more than 30 lines, if you ever feel the need for an IDE, perhaps the task is more suited for Python, Ruby or Perl (IMHO Python is more maintainable).
The Bash shell is coming to Windows 10 in the upcoming Anniversary Update (Redstone).
The Bash shell is coming to Windows. Yes, the real Bash is coming to Windows, said Microsoft's Kevin Gallo at Build 2016 keynote. This is not a VM [Virtual Machine]. This is not cross-compiled tools. This is native."
Here's the steps to run Bash on Windows 10 OS:
Open the Windows Start menu
Type "bash" [hit enter]
Which opens a console running Ubuntu's /bin/bash with full access to all of Ubuntu user space
Yes, you are right, that means apt, set, ssh, rsync, find, ls, grep, awk, sed, sort, xargs, md5sum, gpg, curl, wget, apache, mysql, python, perl, ruby, ruby gem, php, gcc, tar, vim, emacs, diff, patch, nano...and most of the tens of thousands binary packages available in the Ubuntu archives!
Reference
Step-vise Guide to Enable Windows 10’s Ubuntu Bash Shell (Windows Subsystem for Linux)
The Bash shell is coming to Windows 10 in the upcoming Anniversary Update (Redstone).
Run native Bash on Ubuntu on Windows
Since you need to write linux shell scripts, you are learning Linux. So you should install Linux on your machine (preferably on its own partition and boot from it, otherwise in a VM).
Using cygwin or whatever imitation of Linux shell is not using Linux. You'll learn a lot more by installing and using Linux (and by developing on it with an editor like emacs or gedit or gvim ....). Also, take advantage that Linux is almost entirely free software, so you can study its source code and improve it.
Not installing Linux is not doing yourself a favor.
I believe cygwin is for those who love Linux but have to use Windows. It cannot give you the entire Linux feeling (e.g. you won't be able to write shell scripts looking into /proc which does not exist in Windows, even with cygwin).
If you want to use a simple environment emulating all Linux environment as alternative to cygwin (more lightweight) you can try mingw and you can use notepad++ or emacs or vim to provide some syntax highlight on sh scripts.
Everyone has said to go full Linux or use various mocks.
Cloud9.io is a good option if you don't need that much.
You can set up a "workspace" which can be accessed online, lets you write in literally any language similar to np++, but the best part is, it's an online Linux, so you have a terminal, with all your shell commands - no mock up, no dual boot.
The downside to this is that the free users aren't given that much power, so if you wanted to execute some high-level maths or output a large image, it will crash as you will be using too much memory. But it is still really worth getting into, it's only ever crashed once on me, and I do some pretty memory-intensive things.
There is cygwin , that's a linux console for windows.. so you can execute all the linux command with it.
Install Cygwin to execute the commands. However you can use NotePad++ as editor which has native windows binaries.
http://www.cygwin.com/
http://notepad-plus-plus.org/
For Eclipse Luna Should use this one old version fails on UI error
Help > Install New Software… > Add…
Name: ShellEd
Location: http://sourceforge.net/projects/shelled/files/shelled/update/
I had a similar problem.
I like both Linux and Windows, and I am working on both systems, but for programming (and generally, for text editing) I use Windows, for different reasons. For example, I write C/C++ code on Windows, using the Windows DevC++ IDE, then I can compile this project on Linux, by sharing the files on LAN. Now I have to write long scripts, and I would like to do it in a similar way. Ok, maybe its a special request, but maybe I am not the only one who works in such a mixed environment.
First, I tried notepad++ (it is suggested by others as well), but does it support syntax highlight for Linux scripts? I didn't found this feature...
Then I tried gedit compiled for Windows. It requires the GTK library installed (actually it was already on my Windows). Gedit has syntax highlight for scripts!
So I suggest using gedit for Windows for this case. The edited script can not directly be started/tested with it, but for editing, it is fine!

Resources