Lua Basics-01

Lua features introduction and design purpose


       lua is a lightweight and small scripting language that is designed to be embedded in applications to provide flexible extension and customization capabilities for applications.

  1. Lightweight: It is written in standard C language and open in the form of source code. After compiling, it is only more than 100K, which can be easily embedded in other programs.
  2. Extensible: Lua provides a very easy-to-use extension interface and mechanism: these functions are provided by the host language (usually C or C++), and Lua can use them as if they were built-in functions.
  3. Other features:
         1. Supports procedure-oriented programming and functional programming
           2. Automatic memory management; only provides a general type of table (table), which can be used to implement arrays, hash tables , collection, object;
           3. Language built-in pattern matching; closure; function can also be regarded as a value; provide multi-threading (cooperative process, not threads supported by the operating system) support;
           4. Through closure and table It can easily support some key mechanisms required by object-oriented programming, such as data abstraction, virtual functions, inheritance and overloading, etc.

lua application scenarios

      1. Game development.
      2. Independent application script.
    3. Web application script extensions and database plug-ins such as: MySQL Proxy and MySQL WorkBench.
      4. Security systems, such as intrusion detection systems.


Lua Basic Syntax

    Lua is very easy to learn, and we can now create our first Lua program. We can keep the Lua program code to a file ending in .lua and execute it. As for what platform to use to execute the code, you can search the Internet yourself. This is not difficult. I won't say more here. Let's start our first code.

print("Hello World!")

Notes

    1. Single-line comments
            Two minus signs are single-line comments

--注释语句

    2. Multi-line comments
            Multi-line comments

--[[
    多行注释
    code
--]]

identifier

    Lua identifiers are used to define a variable, and functions get other user-defined items.

    Identifiers start with a letter A to Z or a to z or an underscore _ followed by zero or more letters, underscores, numbers (0 to 9).

    It's best not to use underscore-plus-case identifiers, as Lua's reserved words are the same.

    Lua does not allow the use of special characters such as @, $, and % to define identifiers. Lua is a case-sensitive programming language.


keywords

    The keywords of lua, if you are interested, you can learn about them, and I will not repeat them here.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324871956&siteId=291194637