1 first glance at Lua

Source: Internet
Author: User

1. Why is Lua used?

Many of the predecessors have answered this question about its usefulness. Real game development can prove its widespread use. Zhihu's "Why is Lua widely used in the field of game programming" and the open-source community "why do I choose Lua?" And so on, fully affirmed the power of Lua and its prospects. It is free, small, fast, and easy to transplant. More importantly, its scalability makes Lua very suitable for game development, westward journey 2, World of Warcraft Wow plug-in, and swordsman sentiment 3 are all in Lua language. But don't worry. The powerful Lua is easier to learn and get started with. There are not many things to talk about in depth, and there are few Chinese books dedicated to Lua on the market. Program in Lua and Lua Game Development Practice Guide are all classic books.


2. Lua in game projects(This is taken from Lua Game Development Practice Guide.)

· Edit the game user interface

· Define, store, and manage basic game data

· Manage real-time game events

· Create and maintain a developer-friendly game storage and loading system

· Compile the AI system of the game

· Create a functional prototype and port it in a high-performance language.


3. Build a Lua Environment

Lua can be compiled and run on almost all operating systems and platforms. Lua does not provide a powerful library, which is determined by its positioning. Therefore, Lua is not suitable for developing independent applications. Lua has a simultaneous JIT project that provides real-time compilation on a specific platform. The Lua kernel is smaller than kb, which is very small when compiled and integrated into the game development system. The following briefly introduces the Lua Environment Construction: ① linux environment: first to Lua official website (http://www.lua.org/download.html download the latest Lua source code, the latest is lua-5.2.3, get a .tar.gz. Second, use the tar-xzvf/path-to-your-lua-tar-file-folder/lua-5.2.3.tar.gz command to decompress and a lua-5.2.3 folder will be obtained. Then, use cd/path-to-your-lua-tar-file-folder/lua-5.2.3 to switch the current working directory to the lua-5.2.3 folder. Run the make command and you will See the following prompt: Please do make PLATFORM where PLATFORM is one of these: aix ansi bsd freebsd generic linux macosx mingw posix solaris See INSTALL for complete instructions. if your system PLATFORM name is in the list that is supported or not, continue to run the make PLATFORM command if it exists. Otherwise, run the make linux Command. Generally, the compilation is successful. Finally, run the make install command. Now, the lua language environment has been successfully installed. Enter the lua command under the terminal to enter! Then you can download a Lua Editor (LuaEdit ). 2 Windows environment: Download LFW (Lua for Windows) version, address :( https://code.google.com/p/luaforwindows/), lua for windows is actually a complete set of Lua development environment, it includes: lua Interpreter (Lua Interpreter) Lua Reference Manual (Lua Reference Manual) Quick Lua Tour (Lua Quick Start) Examples (Lua example) Libraries with documentation (some Lua Libraries and documents) sciTE (a great multi-purpose editor that has made special settings for Lua) integrates everything you need to learn and develop Lua in windows and is perfect for beginners, with SciTE, you can easily compile, compile, run, and debug the Lua program after simple configuration. If you need to use it in combination with VC ++ 6.0, there are two methods: 1) This is more convenient, use the previously downloaded FLW, in the menu of VC6.0, find the [tools]-[Options]-[Directory] tab, and then set the corresponding. h file and. add the lib file to the file. The path is to download the include and lib folders in the installation path of FLW. You can use SciTE to create a lua file, open and load the file in VC ++, or call a function of the file. The following code:
# Include <stdio. h> # include <process. h> extern "C" {# include "lua. h "# include <lauxlib. h> # include <lualib. h >}# pragma comment (lib, "lua5.1.lib") int main (void) {// open Lua lua_State * L = lua_open (); // load. lib file luaL_openlibs (L); // load the script file, which must be placed in the program directory luaL_dofile (L, "test. lua "); lua_resume (L, 0); // call ends lua_close (L); system (" pause "); return 0 ;}
2) If you do not want to download LFW, You need to compile the Lua library and configure the development environment by yourself. Download the latest Lua source code, get to a .tar.gz, and use the compression software to unlock it. There is an src directory in the directory to be unlocked, and the entire Lua core code is here. Use VC ++ 6.0 to generate the lib file. Create a Win32 StaticLibrary static library project in VC6. For example, set the project name to mylua and the project path to the src directory of Lua, in the subsequent project setup wizard, you do not need to add any settings, that is, do not select the pre-compiled header file and the "MFC support" option. Next, add all. c (except lua. c) and. h files in src to the project and compile them to get the desired static library mylua. lib. When creating a new project, you only need to add mylua. lib and several header files to develop the project. We recommend that you sort out these files and place them in a proper position. First, create the include directory, then create the lua directory under the include directory, and copy the following files to the lua Directory: lauxlib. h lua. h luaconf. h lualib. h. Create the lib directory at the same level as the include directory and compile the liblua. put lib here. You can use notepad or Sublime Text to create a lua file, open and load the file in VC ++, or call a function of the file, as shown in the preceding figure. You can also use this method to write a Lua console. The sharing code is as follows: http://download.csdn.net/detail/hejiero/6900023

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.