How to run Lua in Mac OS X (Running lua on Mac OS X)

Source: Internet
Author: User
Tags lua


Reference article:
1) http://www.oschina.net/question/12_76955
2) http://rudamoura.com/luaonmacosx.html

Recently in the development of the game for iOS, my development machine is iPhone5. The LUA language is required in the development of the game project, so I want to use it in myApple MacBook ProThe LUA language interpreter is installed for script debugging.
The version of my Mac OS x is 10.8.3. Lua is a lightweight scripting language that is used very much in game development. It's open-source. We can download its source code to compile.

Until the writing time of this document (May 2013 9), the latest version of Lua is LUA 5.2.2
Download URL for LUA source code:
Http://www.lua.org/download.html


I. Installation of make and GCC commands in Mac OS x
The preparation that needs to be done before compiling Lua.
I downloaded the lua-5.2.2.tar.gz to an Apple computer, and after extracting it, I found that my Mac OS X did not have a MAK command or GCC command.
To detect if there is a way to make commands in Mac OS X on Apple computers, type the command in the console: which
If this command is available, a prompt will be returned:/usr/bin/make
So I need to install the MAK command in Mac OS X and the GCC command. The installation kit needs to be downloaded from Apple's development website.
Download method:
Open Xcode, Menu Xcode--Open Developer Tool-->more Developer Tools
The Safari browser is then run, and the registration dialog pops up, asks for an Apple ID and password, fills in the registration information and then goes to the Apple developer download site, searches for "Unix", and lists the download list of the Command toolkit:
Command line Tools (OS X Mountain Lion) for Xcode-april 2013 (this version requires Xcode 4.6.2 and Mac OS X 10.8 or later)
Command line Tools (OS X Lion) for Xcode-april 2013 (this version requires Xcode 4.6.2 and Mac OS X 10.7.4 or later)
.....
There are other versions below that you can download with the version of Mac OS x that you use. Also say:
Mac OS X 10.4.x, codenamed: Lion
Mac OS X 10.8.x, codenamed: Mountain Lion

My Mac OS x is Mountain Lion, so the command line Tools (OS X Mountain Lion) for Xcode-april 2013 version is downloaded, and the file name is:
Xcode462_cltools_10_86938259a.dmg
Double-click the file when you are finished downloading. After a while, the installation package window will pop up, double-click the installation package. Follow the prompts to complete the installation. Then make and GCC have it.
You can use the which command to check.

Ii. compiling LUA software
Detailed instructions for compiling and installing the method in the Readme file: lua-5.2.2/doc/readme.html
It is best to compile the test before compiling, in the lua-5.2.2 directory, use theThecommand is as follows: Make test

My compile and install method is:
sudo make macosx install               (sudo means superuser rights in Mac OS x)

Note: The
Lua compilation and installation instructions document (readme.html) indicates that When compiling LUA, you need to select the operating system you want to run, compiling and installing the following format:
make xxx install     (if not superuser login, you need to precede thesudo command)
wherexxx represents the tag for the target operating system, and the tag list for the target operating system is as follows:
aix    ansi    bsd    freebsd    Generic    linux    macosx    mingw    posix     solaris 

Lua will install to   by default,/usr/local/,after the installation is complete, thethis directory will generate some important files.

/usr/local/Bin: (Can run program)Lua Luac (LUA is the LUA language interpreter, Luaclua language compiler)/usr/local/Include: (header file)Lua.h luaconf.h lualib.h lauxlib.h lua.hpp/usr/local/LIB: (library file)liblua.a/usr/local/Man/man1: (Command Manual)lua.1 luac.1


The full path to the Lua interpreter is /usr/local/bin/lua, and the interpreter can be called by running lua in the terminal.

Third, the Lua language interpreter test
Enter the lua command on the console:


Lua
Lua 5.2.1 Copyright (C) 1994-2012 Lua.org, PUC-Rio
> print ("Hello World!") (Enter the interactive command state, enter the test code under the prompt ">")
Hello World! (returned result)


Type Control+D to exit the interactive command

If you want to run a lua script file, you can use the following command: lua filename
Such as: lua hello.lua

The code for the hello.lua file:
Io.write("Hello world, from ",_VERSION,""!\n)

The result: Hello world, from Lua 5.2!

Note:
Lua is a small scripting language. It is a research group in the Pontifical Catholic University of Rio de Janeiro, developed by Roberto Ierusalimschy, Waldemar Celes and Luiz Henrique de Figueiredo and developed in 1993. It is designed to be embedded in the application to provide flexible extension and customization capabilities for the application.
Many applications use LUA as their own embedded scripting language for configurability and scalability. These include World of Warcraft, Baldur's Gate, Angry Birds, and more.



How to run Lua in Mac OS X (Running lua on Mac OS X)


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.