Lua common libraries and tools

Source: Internet
Author: User
Tags wxwidgets

Libraries and tools

Compared with Java, Python, and Perl, Lua may not have many open-source tools and libraries, but many of them are excellent. The following resources can be found in.

I. Kepler

Kepler is a simple and lightweight web development platform (but it does not mean that it can only be used to develop simple applications). It supports writing web programs with Lua, so it is easy to learn and use, and can be easily applied in some systems with limited resources. Because ansi c and Lua are used for development, it can be transplanted to any platform that supports ansi c.

Kepler consists of multiple Lua extension libraries, including cgilua, luasocket, luafilesystem, copas, luasql, lualdap, luaexpat, luaxmlrpc, luasoap, luazip, and Xavante, they can be roughly divided into two parts: core library and Function Support library. The core is cgilua and luasocket, and the latter is responsible for TCP/UDP sockets operations. The former allows you to create dynamic pages and process input data on web forms. Kepler uses the cgilua starter (launcher) to enable the Web server to execute and communicate with cgilua and web programs. The current version already includes cgilua starters suitable for CGI, FastCGI, Apache, IIS, tomcat, and Zope. Therefore, web programs developed with Lua can be freely migrated on these types of servers, you only need to install the corresponding cgilua starter at the same time.

Luafilesystem is a supplement to the file read/write function in the standard Lua library. It provides a portable method to access the directory structure and file attributes of the system. Copas is a coroutine-based service scheduler. Xavante is a web server developed with Lua that supports HTTP 1.1. It directly supports cgilua without a starter.

Other components provide functions such as SQL database access, XML parsing, LDAP, soap, XMLRPC, and zip file operations. If you only need some of these functions, you can extract related components (and the components on which they depend) for use.

Ii. wxlua

GUI is a field in which developers spend a lot of effort. Therefore, simplifying the compilation of GUI programs has always been the direction of the majority of programmers. With the rise of scripting languages, it is a very valuable attempt to introduce dynamic, flexible, and easy-to-use scripting languages into GUI development. The complex GUI layout requires a large amount of description information. Therefore, compared with other scripts, Lua language, which is suitable for programming and data description, has unique advantages in Gui construction.

WxWidgets is a well-known cross-platform C ++ GUI library. wxlua builds a bridge between Lua and wxWidgets and uses its Lua code to call almost all wxWidgets functions. Wxlua basically maps the wxWidgets class system to the Lua (prototype-based) object model, which enables programmers to develop wxlua programs in an object-based or object-oriented style. Writing, running, testing, and modifying a Lua script can be very fast, which undoubtedly greatly improves the development efficiency of GUI programs. Therefore, wxlua is very suitable for the construction of rapid prototypes. In addition, the good portability of Lua itself and wxWidgets makes the corresponding Lua
Gui programs run smoothly on many platforms.

Iii. Pluto

Although tables in Lua can be saved to files in the form of Lua code through the table constructor for persistence, when there is a complex reference relationship between data, in addition, this task becomes quite difficult and cumbersome in special situations such as cyclic reference and shared reference. Pluto persistence library can solve this problem for users. With its help, programmers can save any complex table data to a binary file in special format for future recovery, and the library will automatically process situations such as cyclic references.

In addition to tables, Pluto also supports persistence of functions (closure) and threads, which makes sense. We all know that a basic action in program debugging is to reproduce bugs. However, in many cases, the conditions for generating bugs are very complex and dependent on many factors, it is difficult for developers to accurately build a completely consistent runtime environment. With Pluto's persistence capabilities for functions and threads, we can save the complete runtime environment of the program when a bug occurs, so that we can easily reproduce the bug in the future. Another important application is the preservation of game progress. The running status of the Lua script that implements game logic can be written to the file at any time for future recovery, which makes it very easy to save the game at any time point.

Iv. luacom

Luacom is an extension library that supports interaction between Lua and component objects that comply with COM specifications (automation objects. The interaction involves two aspects: first, allow the Lua program to use COM objects. Luacom supports dynamic instantiation of COM objects registered in the system registry and dynamic access to running objects. With the help of luacom, calling the COM Object method is like calling a normal Lua function. The access attribute is similar to the field used to access the table, it is also responsible for automatic conversion between Automation Data Types and Lua data types. With these features, the Lua program becomes much easier to operate on COM objects. Coupled with the inherent dynamic nature of Lua, this undoubtedly makes it a very flexible component assembly language.

Another aspect of interaction is that Lua can be used to implement (automate) component objects and provide them to external customers. Luacom supports both in-process and out-of-process components. It provides auxiliary functions to handle registration and Object Instantiation tasks, thus simplifying related work. Because luacom actually constructs a COM Object Based on the Lua table, we can do something very interesting: In the userdata data type (representing the data structure that does not belong to the Lua world) with the support of the dynamic meta mechanism, Lua can access a variety of external data through tables, including C ++ objects, C structures, or CORBA objects; luacom can easily wrap the tables representing the data into a COM Object for external use, so that those old applications and libraries can enter the com world without too much effort.

V. tolua

It is common to directly use C to implement some functions and then import the corresponding functions into Lua. However, although Lua provides APIs for interaction with C language, you must manually perform tedious Lua stack (for data exchange with C) operations, you also need to note that the data types in the two languages are correctly converted. It is no wonder that the use of Lua's c API is just like the use of assembly languages. To reduce the burden on programmers, some C/C ++ wrapper came into being.

Tolua is not a wrapper, but it is an Automatic Generator of wrapper code. It uses a package file to describe the constants, variables, functions, classes, and methods to be imported into the Lua environment, this type of file is written in simplified C ++ header file format. First, let tolua parse the package file to generate the C/C ++ source file containing the corresponding glue code. Compile the generated source file and link it with the target modules that implement the specific functions.

Although tolua automatically generates the glue code, it is not convenient to write a description file. Some other Wrapper libraries use the C ++ template metaprogramming technology to automatically generate appropriate connection code, thus avoiding additional description files, such as the boost library luabind.

6. luajit

Lua is very efficient and runs faster than many other scripts (such as Perl, Python, and Ruby), which has been proven in a third-party independent evaluation. Even so, some people may not be satisfied. They always think "Well, it's not fast enough !". Luajit is an attempt to squeeze out a little more speed. It uses JIT compilation technology to compile Lua code to the local machine code and then directly execute it by the CPU. The luajit evaluation report shows that it has a significant acceleration effect in floating point operations, loops, and collaborative process switching. However, if the program relies heavily on functions compiled by C, the running speed will not be improved. Currently, luajit only supports x86 CPUs.

Luajit contains a library named Coco, which can be used independently. Coco provides real coroutine capabilities for Function C. You can suspend the coroutine at any point in Function C, and then return it to that point using the coroutine Restoration Operation in the future. In standard Lua, the suspension and restoration of coroutine cannot span the boundaries of C function calls. Coco uses features that depend on specific systems, so pay special attention when Porting Programs.

VII. chunkspy

Lua's Virtual Machine bytecode instruction set is not part of the language definition, so no documentation is provided officially. You can certainly obtain information by viewing the source code, but this is inconvenient after all.

Chunkspy is a Lua Virtual Machine bytecode reassembler that can output a binary Lua code block to a bytecode Assembly file in a variety of readable formats (detailed or simple, with or without source programs. It also supports interactive disassembly. You can view the corresponding bytecode command immediately after you have typed a line of code. The author of chunkspy wrote a detailed article about lua5 VM commands, called a no-frills introduction to Lua 5 VM instructions. You can find it on the project homepage. This article has now corrected the latest lua5.1. In addition, he is also the developer of the Yueliang project, which uses the Lua language itself to implement Lua. From the project name, the author should be a Chinese.

8. Others

Other libraries and tools include luaedit, luaeclipse, vs '05lualangpack (all of which are ide or IDE plug-ins), luawrapper, calua, ECC, cpplua (wrapper Library ), luaprofiler (performance measurement tool) and so on, readers can find them and other useful resources on lua-user.org and luaforge.net websites

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.