tags:

views:

782

answers:

3

I was wondering, what can i use to program in Lua on the Mac? I'm looking for something that i can use to compile/interpret lua script on the mac.

+6  A: 

The Lua source easily compiles with no changes on the mac. It will build lua (the interpreter which can act on a source script, a pre-compiled script or interactively) and luac which can be used to pre-compile source scripts.

From the lua.org website: http://luabinaries.luaforge.net/download.html. The ones you want are the darwin binaries (they say Mac OS X in the description).

Jason Coco
I dont think i was clear, i'm looking for something that i can use to compile/interpret lua script on the mac. I'll edit my question.
RCIX
Yes, you were clear, exactly: the standard Lua source does this. Just download and build it or (I'm sure) you can find lua and luac prebuilt somewhere.
Jason Coco
Hm id rather not build something as i havent the first clue where to start, i guess ill whip out google...
RCIX
Here are some step-by-step directions for building the Lua source on Mac OS X, as Jason Coco suggested: http://luanova.org/2007/11/10/launch-getting-lua-installed/
las3rjock
Ok, let me clarify that; i'd like a precompiled version.
RCIX
I edited the answer with a link to the binaries that was found at lua.org under their downloads section.
Jason Coco
I found that separately but they're just a bunch of files that the mac doesn't know what to do with. do i need osmething in particular to run them?
RCIX
You need to untar them and put them somewhere they can be executed (like /usr/local/bin). The files you care about will be lua5.1 and luac5.1. You can rename these (or simlink these) to lua and luac respectively. Assuming this downloads to your Downloads folder, you can issue this in the terminal: cd foo; tar -xf ~/Downloads/lua5_1_4_Darwin94x86_bin.tar; sudo cp lua5.1 luac5.1 /usr/local/bin; sudo ln -s /usr/local/bin/lua5.1 /usr/local/bin/lua; sudo ln -s /usr/local/bin/luac5.1 /usr/local/bin/luac
Jason Coco
replace cd foo above with cd /tmp. after that, you can run lua or luac from the command line.
Jason Coco
@RCIX Honestly, I think it would have been faster and easier to compile and install Lua from source using the directions from the link that I posted. Since I already had Apple's Developer Tools installed, it took me less than 5 minutes from the time I opened http://www.lua.org in Safari to the time I had lua and luac installed in /usr/local/bin.
las3rjock
I honestly have to agree with las3rjock :)
Jason Coco
Ok i give, i'll go compile it...
RCIX
Looks like Xcode is too big for my hard disk (dont ask), so im going to try another route...
RCIX
Just follow my directions in the early comment... cut and paste them with the ; in place or replace the ; with a new line in the terminal
Jason Coco
i'm attempting to use macports right now. Thanks for all of your attempts to help though!
RCIX
+4  A: 

My favorite way (from the shell):

sudo port install lua

I LOVE macports!

micmoo
For this, of course, you'll need to install MacPorts. Fortunately, that's easy: http://www.macports.org/install.php
adrian
Gonna try this and hope it works...
RCIX
when i run it it does nothing, and i have xcode + macports installed.
RCIX
Nothing? Did you enter your sudo password correctly?When I installed it, it downloaded some thing, configured it, and I could then launch with the lua command. Make sure :/opt/local/bin:/opt/local/sbin is in your pathIt installs the executable in /opt/local/bin/
micmoo
+1  A: 

Here is my terminal session from compiling and installing Lua from source, basically following these directions. I already had Apple's Developer Tools installed, and /usr/local/bin was already in my PATH, so I was able to skip some of the more time-consuming and/or tedious steps in the directions.

$ cd ~/Downloads

$ tar -xf lua-5.1.4.tar

$ cd lua-5.1.4

$ make macosx    
cd src && make macosx
make all MYCFLAGS=-DLUA_USE_LINUX MYLIBS="-lreadline"
gcc -O2 -Wall -DLUA_USE_LINUX   -c -o lapi.o lapi.c
gcc -O2 -Wall -DLUA_USE_LINUX   -c -o lcode.o lcode.c
gcc -O2 -Wall -DLUA_USE_LINUX   -c -o ldebug.o ldebug.c
gcc -O2 -Wall -DLUA_USE_LINUX   -c -o ldo.o ldo.c
gcc -O2 -Wall -DLUA_USE_LINUX   -c -o ldump.o ldump.c
gcc -O2 -Wall -DLUA_USE_LINUX   -c -o lfunc.o lfunc.c
gcc -O2 -Wall -DLUA_USE_LINUX   -c -o lgc.o lgc.c
gcc -O2 -Wall -DLUA_USE_LINUX   -c -o llex.o llex.c
gcc -O2 -Wall -DLUA_USE_LINUX   -c -o lmem.o lmem.c
gcc -O2 -Wall -DLUA_USE_LINUX   -c -o lobject.o lobject.c
gcc -O2 -Wall -DLUA_USE_LINUX   -c -o lopcodes.o lopcodes.c
gcc -O2 -Wall -DLUA_USE_LINUX   -c -o lparser.o lparser.c
gcc -O2 -Wall -DLUA_USE_LINUX   -c -o lstate.o lstate.c
gcc -O2 -Wall -DLUA_USE_LINUX   -c -o lstring.o lstring.c
gcc -O2 -Wall -DLUA_USE_LINUX   -c -o ltable.o ltable.c
gcc -O2 -Wall -DLUA_USE_LINUX   -c -o ltm.o ltm.c
gcc -O2 -Wall -DLUA_USE_LINUX   -c -o lundump.o lundump.c
gcc -O2 -Wall -DLUA_USE_LINUX   -c -o lvm.o lvm.c
gcc -O2 -Wall -DLUA_USE_LINUX   -c -o lzio.o lzio.c
gcc -O2 -Wall -DLUA_USE_LINUX   -c -o lauxlib.o lauxlib.c
gcc -O2 -Wall -DLUA_USE_LINUX   -c -o lbaselib.o lbaselib.c
gcc -O2 -Wall -DLUA_USE_LINUX   -c -o ldblib.o ldblib.c
gcc -O2 -Wall -DLUA_USE_LINUX   -c -o liolib.o liolib.c
gcc -O2 -Wall -DLUA_USE_LINUX   -c -o lmathlib.o lmathlib.c
gcc -O2 -Wall -DLUA_USE_LINUX   -c -o loslib.o loslib.c
gcc -O2 -Wall -DLUA_USE_LINUX   -c -o ltablib.o ltablib.c
gcc -O2 -Wall -DLUA_USE_LINUX   -c -o lstrlib.o lstrlib.c
gcc -O2 -Wall -DLUA_USE_LINUX   -c -o loadlib.o loadlib.c
gcc -O2 -Wall -DLUA_USE_LINUX   -c -o linit.o linit.c
ar rcu liblua.a lapi.o lcode.o ldebug.o ldo.o ldump.o lfunc.o lgc.o llex.o lmem.o lobject.o lopcodes.o lparser.o lstate.o lstring.o ltable.o ltm.o lundump.o lvm.o lzio.o lauxlib.o lbaselib.o ldblib.o liolib.o lmathlib.o loslib.o ltablib.o lstrlib.o loadlib.o linit.o
ranlib liblua.a
gcc -O2 -Wall -DLUA_USE_LINUX   -c -o lua.o lua.c
gcc -o lua  lua.o liblua.a -lm -lreadline
gcc -O2 -Wall -DLUA_USE_LINUX   -c -o luac.o luac.c
gcc -O2 -Wall -DLUA_USE_LINUX   -c -o print.o print.c
gcc -o luac  luac.o print.o liblua.a -lm -lreadline

$ make test
src/lua test/hello.lua
Hello world, from Lua 5.1!

$ sudo make install INSTALL_TOP=/usr/local
Password:
cd src && mkdir -p /usr/local/bin /usr/local/include /usr/local/lib /usr/local/man/man1 /usr/local/share/lua/5.1 /usr/local/lib/lua/5.1
cd src && install -p -m 0755 lua luac /usr/local/bin
cd src && install -p -m 0644 lua.h luaconf.h lualib.h lauxlib.h ../etc/lua.hpp /usr/local/include
cd src && install -p -m 0644 liblua.a /usr/local/lib
cd doc && install -p -m 0644 lua.1 luac.1 /usr/local/man/man1

$ lua
Lua 5.1.4  Copyright (C) 1994-2008 Lua.org, PUC-Rio
> print "Hi"
Hi
> = 2 + 3
5
> ^c

$ cd test

$ lua factorial.lua 
0! = 1
1! = 1
2! = 2
3! = 6
4! = 24
5! = 120
6! = 720
7! = 5040
8! = 40320
9! = 362880
10! = 3628800
11! = 39916800
12! = 479001600
13! = 6227020800
14! = 87178291200
15! = 1307674368000
16! = 20922789888000
las3rjock