Lua Introduction: Lua is a dynamic scripting language that is often used in Game Development. I feel it is flexible and concise. Currently, for our project, the biggest feature is that game updates can be designed as a resource update method.
Because my goal is to achieve Lua using the cocos2d-x API to achieve game programming, so I just have a general understanding of the next one-way call process, the reverse call process is not in-depth understanding. When using Lua, let's briefly introduce some things that need to be paid attention to when learning Lua.
It can be divided into: Lua data type, Lua stack, and Lua memory. Recently, I also searched for some Lua resources on the Internet. I found that the next three aspects are the core of Lua.
Lua Stack)
Data Types in Lua: nil, booleans, numbers, strings, functions, and userdata.
Nil has only one value: Nil. an uninitialized global variable is nil by default, and can be deleted by setting the global variable to nil.
Booleans has two values: true and false. You should be familiar with it, but note that all values in Lua can be used as conditions, you just need to remember that in the conditions of the control structure, except for whether flase and nil are true, all other values are true, and 0 and empty strings are replaced, so that you will not be confused.
Numbers indicates the real number, and Lua does not have an integer. It indicates the number in Lua.
Strings: There is nothing to say about the string. Here we only mention Lua's string operations. The "+" Operation of the string and number will automatically convert the string to the numeric type. To connect a number to a string, use the... two-point operator.
Functions: in Lua, a function is a type of value (the same as other variables). This means that a function can be stored in a variable, used as a function parameter, or as a function return value.
Lua interacts with other languages and exchanges data through stacks. In fact, you can think of a stack as a box. If you want to give it data, you need to put the data one by one in order. Of course, Lua has completed the execution, there may be results returned to you, so Lua will use your boxes to continue to store them one by one. If you want to retrieve the returned data from the top of the box, what if you want to obtain your input parameters? It is also very simple. Just retrieve the data according to the number of returned data on the top, and then retrieve the data one by one in order. However, we would like to remind you that the stack position is always relative. For example,-1 indicates the current stack top, and-2 indicates the next data position at the top of the current stack. Stack is the place where data is exchanged. There must be some stack concepts. When you initialize a stack, the stack bottom is 1, and the stack top is relative to-1. to say something about the image, you can think of the stack as a ring, there is a pointer to mark the current position. If-1 is the top of the current stack, and if-2 is the position of the parameter at the top of the current stack. And so on. Of course, you can also get them in the forward order. Note that many Lua APIs start with 1. This is somewhat different from C ++. In addition, in the subscript of the stack, a positive number indicates the subscript at the absolute bottom of the stack, and a negative number indicates the relative address at the top of the stack. This must have a clear concept, otherwise it will be easy to see Dizzy.
Here we need to move out a more important concept. Lua is not a C ++. For C ++ programmers, a function will automatically create stacks, after the function is executed, the stack is automatically cleared. Lua does not do this for you. For Lua, it does not have the function concept. A stack corresponds to a lua_state pointer, that is, you must manually clear the stacks you don't need. Otherwise, junk data occupies your memory. Most of the memory online problems are concentrated on global variables, because Lua's default variables are global, so remember to release them.
LuaDetails and examples of Calling C ++ code in: Some APIs are not very understandable, including reading online tutorials, but a website can be provided, you can study it.
Http://blog.csdn.net/favormm/article/details/5796610
From: http://blog.sina.com.cn/s/blog_61ece09901012vlk.html