Programming in Lua on OS X?

后端 未结 6 2179
梦谈多话
梦谈多话 2021-02-08 04:45

What can I use to program Lua script on Mac OS X? I\'m looking for something that I can use to compile/interpret Lua script on OS X.

相关标签:
6条回答
  • 2021-02-08 04:55

    If you don't want to compile your own Lua binaries, you can try ZeroBrane Studio Lua IDE, which comes packaged as a .dmg file for OSX. It's an IDE that allows you to edit and debug your Lua scripts. If you are just starting with Lua, it also includes 50+ examples and demo scripts, as well as integrated instructions on running them, so you won't be facing an empty screen not knowing where to start.

    0 讨论(0)
  • 2021-02-08 05:00

    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
    
    0 讨论(0)
  • 2021-02-08 05:01

    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).

    0 讨论(0)
  • 2021-02-08 05:09

    My preferred way:

    brew install lua
    

    Thanks, Max!

    And if you need to know how to install Homebrew, see http://mxcl.github.com/homebrew/ and:

    /usr/bin/ruby -e "$(curl -fsSL https://raw.github.com/gist/323731)"
    
    0 讨论(0)
  • 2021-02-08 05:12

    My favorite way (from the shell):

    sudo port install lua
    

    I LOVE macports!

    0 讨论(0)
  • 2021-02-08 05:13

    I just recently found Rudix—a maintained collection of precompiled Unix software for Mac.

    While I'm sure you've already figured out a way of installing Lua, I came across your question by Googling the same thing. For anyone that's interested, here's the link to a recent Lua 5.1.4 dmg.

    0 讨论(0)
提交回复
热议问题