macos 在 OS X 上用 Lua 编程?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1236879/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Programming in Lua on OS X?
提问by RCIX
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.
我可以用什么来在 Mac OS X 上编写 Lua 脚本?我正在寻找可以用来在 OS X 上编译/解释 Lua 脚本的东西。
回答by Paul Lynch
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:
如果您需要知道如何安装 Homebrew,请参阅http://mxcl.github.com/homebrew/和:
/usr/bin/ruby -e "$(curl -fsSL https://raw.github.com/gist/323731)"
回答by Jason Coco
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.
Lua 源代码在 mac 上无需更改即可轻松编译。它将构建 lua(可以作用于源脚本、预编译脚本或交互的解释器)和可用于预编译源脚本的 luac。
From the lua.orgwebsite: http://luabinaries.luaforge.net/download.html. The ones you want are the darwin binaries (they say Mac OS X in the description).
来自lua.org网站:http: //luabinaries.luaforge.net/download.html。你想要的是 darwin 二进制文件(他们在描述中说的是 Mac OS X)。
回答by micmoo
My favorite way (from the shell):
我最喜欢的方式(从外壳):
sudo port install lua
I LOVE macports!
我爱 macports!
回答by las3rjock
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.
这是我从源代码编译和安装 Lua 的终端会话,基本上遵循这些指示。我已经安装了 Apple 的开发人员工具,并且 /usr/local/bin 已经在我的 PATH 中,所以我能够跳过一些更耗时和/或繁琐的步骤。
$ 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
回答by Paul Kulchenko
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.
如果您不想编译自己的 Lua 二进制文件,可以尝试ZeroBrane Studio Lua IDE,它打包为 OSX 的 .dmg 文件。它是一个 IDE,可让您编辑和调试 Lua 脚本。如果您刚开始使用 Lua,它还包括 50 多个示例和演示脚本,以及有关运行它们的集成说明,因此您不会面临不知道从哪里开始的空白屏幕。
回答by zachwill
I just recently found Rudix—a maintained collection of precompiled Unix software for Mac.
我最近才发现Rudix——一个为 Mac 维护的预编译 Unix 软件集合。
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.
虽然我确定您已经找到了安装 Lua 的方法,但我通过谷歌搜索同样的东西遇到了您的问题。对于任何感兴趣的人,这里是最近 Lua 5.1.4 dmg 的链接。