内容简介:Lua is a powerful, efficient, lightweight, embeddable scripting language developed by ateam atLua'sofficial web site provides complete information about Lua, including anexecutive summary and updateddocumentation, especially thereference manual, which may
About Lua
Lua is a powerful, efficient, lightweight, embeddable scripting language developed by ateam at PUC-Rio , the Pontifical Catholic University of Rio de Janeiro in Brazil. Lua isused in many products and projects around the world.
Lua'sofficial web site provides complete information about Lua, including anexecutive summary and updateddocumentation, especially thereference manual, which may differ slightly from thelocal copy distributed in this package.
Installing Lua
Lua is distributed insource form. You need to build it before using it. Building Lua should be straightforward because Lua is implemented in pure ANSI C and compiles unmodified in all known platforms that have an ANSI C compiler. Lua also compiles unmodified as C++. The instructions given below for building Lua are for Unix-like platforms, such as Linux and Mac OS X. See alsoinstructions for other systemsandcustomization options.
If you don't have the time or the inclination to compile Lua yourself, get a binary from LuaBinaries . Try also LuaDist , a multi-platform distribution of Lua that includes batteries.
Building Lua
In most common Unix-like platforms, simply do " make ". Here are the details.
- Open a terminal window and move to the top-level directory, which is named lua-5.4.0 . The Makefile there controls both the build process and the installation process.
- Do " make ". The Makefile will guess your platform and build Lua for it.
- If the guess failed, do " make help
" and see if your platform is listed. The platforms currently supported are:
guess aix bsd c89 freebsd generic linux linux-readline macosx mingw posix solaris
If your platform is listed, just do " make xxx ", where xxx is your platform name.
If your platform is not listed, try the closest one or posix, generic, c89, in this order.
- The compilation takes only a few moments and produces three files in the src directory: lua (the interpreter), luac (the compiler), and liblua.a (the library).
- To check that Lua has been built correctly, do " make test " after building Lua. This will run the interpreter and print its version.
If you're running Linux, try " make linux-readline " to build the interactive Lua interpreter with handy line-editing and history capabilities. If you get compilation errors, make sure you have installed the readline development package (which is probably named libreadline-dev or readline-devel ). If you get link errors after that, then try " make linux-readline MYLIBS=-ltermcap ".
Installing Lua
Once you have built Lua, you may want to install it in an official place in your system. In this case, do " make install ". The official place and the way to install files are defined in the Makefile . You'll probably need the right permissions to install files, and so may need to do " sudo make install ".
To build and install Lua in one step, do " make all install ", or " make xxx install ", where xxx is your platform name.
To install Lua locally after building it, do " make local ". This will create a directory install with subdirectories bin , include , lib , man , share , and install Lua as listed below. To install Lua locally, but in some other directory, do " make install INSTALL_TOP=xxx ", where xxx is your chosen directory. The installation starts in the src and doc directories, so take care if INSTALL_TOP is not an absolute path.
- bin:
- lua luac
- include:
- lua.h luaconf.h lualib.h lauxlib.h lua.hpp
- lib:
- liblua.a
- man/man1:
- lua.1 luac.1
These are the only directories you need for development. If you only want to run Lua programs, you only need the files in bin and man . The files in include and lib are needed for embedding Lua in C or C++ programs.
Customization
Three kinds of things can be customized by editing a file:
- Where and how to install Lua — edit Makefile .
- How to build Lua — edit src/Makefile .
- Lua features — edit src/luaconf.h .
You don't actually need to edit the Makefiles because you may set the relevant variables in the command line when invoking make. Nevertheless, it's probably best to edit and save the Makefiles to record the changes you've made.
On the other hand, if you need to customize some Lua features, you'll need to edit src/luaconf.h before building and installing Lua. The edited file will be the one installed, and it will be used by any Lua clients that you build, to ensure consistency. Further customization is available to experts by editing the Lua sources.
Building Lua on other systems
If you're not using the usual Unix tools, then the instructions for building Lua depend on the compiler you use. You'll need to create projects (or whatever your compiler uses) for building the library, the interpreter, and the compiler, as follows:
- library:
- lapi.c lcode.c lctype.c ldebug.c ldo.c ldump.c lfunc.c lgc.c llex.c lmem.c lobject.c lopcodes.c lparser.c lstate.c lstring.c ltable.c ltm.c lundump.c lvm.c lzio.c lauxlib.c lbaselib.c lcorolib.c ldblib.c liolib.c lmathlib.c loadlib.c loslib.c lstrlib.c ltablib.c lutf8lib.c linit.c
- interpreter:
- library, lua.c
- compiler:
- library, luac.c
To use Lua as a library in your own programs, you'll need to know how to create and use libraries with your compiler. Moreover, to dynamically load C libraries for Lua, you'll need to know how to create dynamic libraries and you'll need to make sure that the Lua API functions are accessible to those dynamic libraries — but don't link the Lua library into each dynamic library. For Unix, we recommend that the Lua library be linked statically into the host program and its symbols exported for dynamic linking; src/Makefile does this for the Lua interpreter. For Windows, we recommend that the Lua library be a DLL. In all cases, the compiler luac should be linked statically.
As mentioned above, you may edit src/luaconf.h to customize some features before building Lua.
Changes since Lua 5.3
Here are the main changes introduced in Lua 5.4. Thereference manual lists theincompatibilities that had to be introduced.
Main changes
- new generational mode for garbage collection
- to-be-closed variables
- const variables
- userdata can have multiple user values
- new implementation for math.random
- warning system
- debug information about function arguments and returns
- new semantics for the integer 'for' loop
- optional 'init' argument to 'string.gmatch'
- new functions 'lua_resetthread' and 'coroutine.close'
- string-to-number coercions moved to the string library
- allocation function allowed to fail when shrinking a memory block
- new format '%p' in 'string.format'
- utf8 library accepts codepoints up to 2^31
License
Lua is free software distributed under the terms of the MIT license reproduced below; it may be used for any purpose, including commercial purposes, at absolutely no cost without having to ask us. The only requirement is that if you do use Lua, then you should give us credit by including the appropriate copyright notice somewhere in your product or its documentation. For details, seethis.
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
以上所述就是小编给大家介绍的《Lua 5.4.0》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!
猜你喜欢:本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。