• Lua string library learning notes


    LuaOne of its most powerful features is itscharacter stringProcessing capability. It supports character formatted output, has extensible pattern matching search function, and some practical character operations, such as query, intercept, replace, delete and other string operations. These string operation functions are encapsulated in astringIn the module of. The character index in Lua starts from 1, […]

  • Lua module and package learning notes


    Starting from Lua 5.1, Lua has added a standard module management mechanism, which can put some public codes in one file and call them in other places in the form of API interface, which is conducive to code reuse and reduce code coupling. Create module In fact, Lua’s module is a table composed of variables, […]

  • Example of interaction between Lua and C language


    Lua is a lightweight, flexible and highly extensible scripting language. It can be easily embedded in other languages (c/c++), mainly thanks to its powerful C API, which makes it easy to interoperate with c/c++. Lua calls C When Lua calls the C function, it actually registers the C function in Lua and passes the C […]

  • Lua data type introduction


    LuaIt is a powerful, fast and lightweight embeddable scripting language, which is implemented by the standard ANSI C. due to its compact and powerful features and easy-to-use C API, it can be easily embedded or extended to other languages, and has a non-governmental Chinese name – “Lua”. Installing Lua Lua installation is simple. After downloading […]

  • Lua object oriented programming learning notes


    In fact, table in Lua is an object, because it has its own operation methods like objects:   Copy codeThe codes are as follows: Role = { hp = 100 } function Role.addHp(hp)     Role.hp = Role.hp + hp end   Role.addHp(50) print(Role.hp)   The above code creates an object named role with an addhp […]

  • Closure learning notes in Lua


    Previous introductionData type of luaIt was also mentioned that Lua’s function is a “first class value”. It can: Stored in a variable or table (for examplemodularandobject-orientedImplementation of)   Copy codeThe codes are as follows: t = { p = print } t.p(“just a test!”)   Passed to other function calls as arguments (also known as […]

  • Meta table and meta method learning notes in Lua


    A metatable is a collection of default operation methods for each type of value in Lua. For example, numbers can be added, subtracted, multiplied, and divided, strings can be connected and merged, a pair of key value values can be inserted into a table, functions can be called, and so on. These operations are performed […]

  • Table learning notes in Lua


    tablestayLuaLi is an important data structure. It can be said to be the basis of other data structures. The usual data structures such as arrays, records, linear tables, queues, and sets can be represented by tables, even global variables(_G)、modularThese important Lua elements, such as, metatable, are all table structures. It can be said that table […]

  • Lua learning notes C API traversal table implementation code


    Lua interacts with C through a virtual stack. The positive index values from bottom to top, and the negative index values from top to bottom. The table structure in Lua can use any data as a key to get values. There are two ways to access elements in a table using the C API:   […]

  • The solution of making callback function support callback object method in Lua


    In cocos2d Lua, there are many asynchronous or delayed operations, such as background loadingpictureWait for a certain time to execute the code, etc. Functions of these functions usually require a function to be passed in as a parameter.   Copy codeThe codes are as follows: –Load an image in the background and output a message […]

  • Implementing continue in disguise in Lua to jump out of the loop


    There is no continue keyword in Lua, which is sometimes inconvenient. It may lead to deep if then nesting in the loop. But we can use a little trick to achieve the same function:   Copy codeThe codes are as follows: for i = 1, 100 do     while true do         if i % […]

  • Tips for creating global variables in Lua (forbid unexpected global variables)


    Lua has a feature that the variables defined by default are global. To avoid this, we need to use the local keyword when defining variables. However, it is inevitable that there will be forgetting. It is difficult to find some bugs at this time. So we can use a little trick to change the way […]