LuaProgramming Skills Learning tutorial is the content to be introduced in this article, mainly to learnLUAProgramming skills, so that you can learn more easily, first to the details of this article.LuaVersion 5.1 has been officially released. Now we should put all the discussions on this version.
Use local whenever possibleVariableNot globalVariable. This isLuaThe easiest mistake for beginners. The global variable is actually placed in a global table
A brief talk about object-oriented in LuaThe table in Lua is an object that looks at the following simple code:The above code will output TB1 ~= TB2. Note that two objects that have the same worth are two different, while the table in Lua is a reference type. As I've also summarized in the modules and packages in Lua, we are a table-based module that allows you t
upvalues.
Unlike Lua's closure, C's closure cannot share upvalues. Each closure has its own private upvalues. However, you can set different functions to make upvalues represent the same table. In this way, this table becomes a mechanism for all functions in the database to share data.
Lua5.2 provides a function to implement the above mechanism. We have used lual_newlib to open the C library, and Lua uses the following macro to implement the function
Analysis on Exception Handling in Lua Programming
This article mainly introduces the exception handling in Lua programming, which is the basic knowledge in Lua beginners. For more information, see
Error Handling required
Error handling is necessary because operations in the
LuaProgramming LanguageInstallEnvironment is the content to be introduced in this article,LuaIt is an extended programming language designed to support generic procedural programming and provide relevant data descriptions.LuaIt also supports object-oriented programming,FunctionData-driven programming provides good supp
I. Preface
Lua was invented by Robert ierusalimschy, Waldemar Celes and Luiz Henrique De Figueiredo in 1993. Lua was designed to easily embed the host language, enhances system scalability and customization. Lua has more than 20 thousand lines of source code, which is very simple and compact. In the current Script Engine, Lua
To put it simply, object-oriented in Lua
The table in Lua is an object that looks at the following simple code:
Copy Code code as follows:
Local TB1 = {A = 1, b = 2}
Local TB2 = {A = 1, b = 2}
Local TB3 = tb1
if tb1 = = Tb2 Then
Print ("TB1 = = TB2")
Else
Print ("Tb1 ~= TB2")
End
tb3.a = 3
Print (tb1.a)
The code above will output TB1 ~= TB2. Shows that two obje
uesrdata is not managed by garbage collector. Sometimes light userdata performs lightweight replacement of full userdata. However, this is not absolute. First, light userdata has no retriable, so there is no way to know their types. Second, full userdata is not very popular. Actually, light userdata is used for comparison. Because full userdata is an object, it is equal only to itself. Light userdata represents a C pointer, so it is equal to any userdata that represents the same pointer. Theref
This article mainly introduces the exception handling in LUA programming, which is the basic knowledge in Lua's introductory study, and the friend who wants to refer to
Error handling is required
Error handling is necessary because operations in the real world typically require complex operations, including file operations, database transactions, and Web service invocations. No one cares about the wrong b
The test environment is vs200520.luaforwindows_v5.1.4-45.exe + WIN7.1.install luadevelopment environment luaforwindows_v5.1.4-45.exe2. Start VS2005 and select "Win2 console application" in the "win32" project type under C ++"3. tool -- option -- project and solution -- VC ++ directory -- executable Program (C: \ Program Files \ Lua \ 5.1); contains file (C: \ Program Files \ Lua \ 5.1 \ include); library Fi
Lua-Object-Oriented Programming
Lua is not a language designed for Object-Oriented purposes. Therefore, it does not directly support object-oriented programming only in the original ecological syntax, however, Lua's design still contains a lot of object-oriented ideas. Understanding them also helps to understand some
function is invoked. The 2-level error where the call to the wrong function is called, and so on. Pass a 0-level message that avoids adding an error to the location information.Pcall and Xpcall
Programming in Lua to avoid raising these errors and handling errors requires the use of features Pcall or Xpcall.
Pcall (f, arg1, ...) function to invoke the functionality required by the protection mode. If ther
Lua introductory lecture about Lua programming Bible courses
Lua programming Bible, Chinese version! This course introduces the basic knowledge of Lua language to students with programming
is passed to the VM through APIS such as lua_pushstring, you need to refresh it. This includes at least one re-hash and matching process. An article on my blog discussed this issue.
In Lua, the inheritance of Lua implements oo. Virtual tables usually set a retriable and _ index, while inheritance concatenates virtual tables with the _ index of the retriable. When there are too many class inheritance layers
, very well understood;
Call the new constructor to create an instance object that has a name field;
Call Object:setname ("Jellythink") statement, set a new name, but do not have this field in OBJECTC? OK, go to the parent class, first go to the CA to find, all of a sudden found, and then called the Setname,setname in the self point is objectc; After setting, it is equivalent to modifying the name value of the OBJECTC field;
Call Objectc:getname (), OBJECTC still does not have this f
strings passed from C to LuaString constants work very quickly inside Lua Vm, but when a string is transferred from C to Lua VM through APIS such as lua_pushstring to VM, You need to refresh it. This includes at least one re-hash and matching process. An article on my blog discussed this issue.
Inheritance in LuaIn Lua, oo is implemented. A virtual table usuall
How to Use nested loops in Lua Programming
This article describes how to use nested loops in Lua programming. It is the basic knowledge of Lua beginners. For more information, see
The Lua pro
Concurrentlua -- Concurrent-oriented Lua Programming
Original article addressLinker translates this article only to provide more information.Introduction
Concurrentlua is an implementation of a non-shared asynchronous message passing model. This model comes from the Erlang language.She adapted the concurrency elements of Erlang and integrated them into Lua.A core element of concurrentlua is process. A proce
, size_t L);/**Press a string into the stack**/Lua_apivoid(lua_pushstring) (Lua_state *l,Const Char*s);/**to press a string into the stack and format it**/Lua_apiConst Char* (lua_pushvfstring) (Lua_state *l,Const Char*FMT, va_list ARGP);/**to press a string into the stack and format itformatting with mutable parameters**/Lua_apiConst Char* (lua_pushfstring) (Lua_state *l,Const Char*FMT, ...);/**Press a C function into the stack**/Lua_apivoid(lua_pushcclosure) (Lua_state *l, lua_cfunction FN,intn
LuaThe difference from other programming language syntaxes is what we will introduce in this article, mainly fromLUADifferent from other programming languagesLUAFor more information about how to use the script language, see this article.
Variable does not need to declare the type (variable type), and does not need to be declared before use for the first time
The following statements are written in C languag
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.