4.1. Lua tutorial

发布时间 : 2025-10-25 13:34:11 UTC      

Page Views: 9 views

Lua

Lua is a lightweight and compact scripting language written in the standard C language and open in source code. It is designed to be embedded in the application so as to provide flexible extension and customization for the application.

Lua was developed in 1993 by a research team at the Catholic University (Pontifical Catholic University of Rio de Janeiro) in Rio de Janeiro, Brazil. The team members are Roberto Ierusalimschy, Waldemar Celes and Luiz Henrique de Figueiredo.

4.1.1. Design purpose #

It is designed to be embedded in the application, so as to provide flexible extension and customization for the application.

4.1.2. Lua characteristics #

  • Lightweight: it is written in standard C language and open in source code. After compilation, it is only more than 100 K, and can be easily embedded inother programs.

  • Extensibility: Lua provides very easy-to-use extension interfaces and mechanisms: these functions are provided by the host language (usually C or C++) and can be used by Lua as if they were built-in functionality.

  • Other features:

    • Support for process oriented (procedure-oriented) programming and functionalprogramming (functional programming);

    • Automatic memory management; only one common type of table (table) is provided, which can be used to implement arrays, hash tables, collections, and objects:

    • Language built-in pattern matching; closure; function can also be seen as a value; provides multithreading (collaborative processes, not threads supported by the operating system)

    • Closures and table can easily support some of the key mechanisms needed for object-oriented programming, such as data abstraction, virtual functions, inheritance and overloading.

4.1.3. Lua application scenario #

  • Game development

  • Stand-alone application script

  • Web application script

  • Extensions and database plug-ins such as MySQL Proxy and MySQL WorkBench

  • Security systems, such as intrusion detection systems

4.1.4. The first Lua program #

Next, we use the Lua to output "Hello World!"

Instance (Lua 5.3) #

print("Hello World!") 

After running, it will be displayed on the screen Hello, world! .

《地理信息系统原理、技术与方法》  97

最近几年来,地理信息系统无论是在理论上还是应用上都处在一个飞速发展的阶段。 GIS被应用于多个领域的建模和决策支持,如城市管理、区划、环境整治等等,地理信息成为信息时代重要的组成部分之一; “数字地球”概念的提出,更进一步推动了作为其技术支撑的GIS的发展。 与此同时,一些学者致力于相关的理论研究,如空间感知、空间数据误差、空间关系的形式化等等。 这恰好说明了地理信息系统作为应用技术和学科的两个方面,并且这两个方面构成了相互促进的发展过程。