Tag:Lua tutorial

  • Lua tutorial (I): introduction to Lua scripting language


    LuaIs an extended programming language. It is designed to support general procedural programming and has facilities for related data description. Lua can also provide good support for object-oriented programming, functional programming and data-driven programming. It can be used as a powerful and lightweightscripting language For any required program. Lua is provided in the form of […]

  • Lua tutorial (II): syntax conventions


    The name (also known as identifier) used in Lua can be any string composed of letters, numbers and underscores that do not start with numbers. This fits almost allprograming languageDefinition of name in. (the definition of letters depends on the current environment: the letters in the alphabet defined in the system environment can be used […]

  • Lua tutorial (III): introduction to values and types


    Lua is a dynamictypeLanguage. This means that variables have no type, onlyvalueThere are types. Type definition does not exist in language. All values themselves carry their own type information. All values in Lua are first class. This means that all values can be placed in variables, passed as parameters to another function, and returned by […]

  • Lua tutorial (I): introduction, advantages and application scenarios


    1、 Introduction:   LuaAs the most popular free lightweight embedded scripting language, it is widely used in many industrial applications, such as Adobe’s Photoshop, and even in some famous game programs, such as interstellar. Moreover, Lua has many special advantages, such as simple syntax (based on process), high efficiency and stability (based on bytecode), handling complex […]

  • Lua tutorial (II): introduction to basic knowledge, types and values


    1、 Basic knowledge: 1. First program and function:At this learning stage, the best way to run Lua program is through Lua’s own interpreter program, such as:   Copy codeThe code is as follows:     /> lua     > print(“Hello World”)     Hello World In this way, we can enter Lua code interactively and get the […]

  • Lua tutorial (3): expressions and statements


    1、 Expression:     1. Arithmetic operator:Lua supports conventional arithmetic operators, including “+”, “-“, “*”, “/”, “^” (index), “%” (modulus), and “-” (minus sign) of binary. All of these operators can be used with real numbers. However, it should be noted that the modulus operator (%) is defined in Lua as:   Copy codeThe code is […]

  • Lua tutorial (IV): detailed explanation of functions


    1、 Function: In Lua, the calling method of functions is basically the same as that of C language, such as print (“Hello world”) and a = add (x, y). The only difference is that if the function has only one parameter and the type of the parameter is a string constant or a constructor of […]

  • Lua tutorial (5): iterator and generic for


    1. Iterator and closure: In Lua, iterators are usually functions that return the “next” element in the collection every time the function is called. Each iterator needs to maintain some state between each successful call in order to know its location and the location of the next iteration. From this point of view, the closure […]

  • Lua tutorial (VI): compilation, execution and errors


    1. Compilation:The dofile function is provided in Lua, which is a built-in operation for running Lua code blocks. But in fact, dofile is only an auxiliary function, and LoadFile is the real core function. Compared with dofile, LoadFile only loads Lua code block from the specified file, and then compiles this code block. If there […]

  • Lua tutorial (VII): detailed explanation of data structure


    Table in Lua is not a simple data structure. It can be used as the basis of other data structures. For example, arrays, records, linear tables, queues and sets can be represented by table in Lua. 1. Array: Using integers to index table can implement arrays in Lua. Therefore, the array in Lua has no […]

  • Lua tutorial (8): Data Persistence


    1. Data file: We can use the construction formula of table in Lua to define a file format, that is, the data in the file is the code constructed and initialized by table. This method is very convenient and clear for Lua program, such as:   Copy codeThe code is as follows:     Entry { […]

  • Lua tutorial (IX): detailed explanation of meta table and meta method


    The meta table provided in Lua is a personalized behavior used to help Lua data variables complete some non predefined functions, such as the addition of two tables. Assuming that both a and B are tables, you can define how to calculate the expression a + B through the meta table. When Lua tries to […]