Required documents for beginners: Lua function learning notes

Source: Internet
Author: User
Tags strfind

Lua FunctionLearning notes are the content to be introduced in this article.LUA FunctionSo that we can learn quickly. TheseFunctionAllLuaFor a part of the programming language, Click here for more information.

Assert (value)-check whether a value is non-nil. If not, the dialog box is displayed and the debugging message is output.

Collectgarbage ()-mustard collector. (Added at 1.10.1)

Date (format, time)-returns the current time on the user's machine.

Error ("error message", level)-When errors occur, a defined error message is output. capture errors using pcall () (see the following.

Gcinfo ()-unused plug-in memory (kb) and current usage (kB ).

Getfenv (function or integer)-return this table to obtain the stack construction possible stack level of the function.

Getmetatable (obj, mtable)-obtain the metadata object before the object.

Loadstring ("Lua code")-analyzes the lua code block in the string and returns the result as a function.

Next (table, index)-return the next key, a pair of table values. Approval for traversing the full table

Pcall (func, arg1, arg2.

Select (index, list)-return to select the item value in this list. It may be the index value of this item in the list.

Setfenv (function or integer, table)-set the stack level of the function that has been acquired from this table.

Setretriable (obj, mtable)-set the metadata objects of the current table.

Time (table)-returns a unix time Value

Type (var)-deduce the current variable type, "number", "string", "table", "function" may be "userdata ".

Unpack (table)-extract a table. Return all values in the current table.

Xpcall (func, err)-returns a Boolean value to indicate the function that wins the execution and call the incorrect message that fails. In addition, the return value of the function that runs the function may be incorrect.

Mathematical functions

These table functions can also be referenced in the Lua function library (both of them start with math. For more information, see the math library ).

Trigonometric functions are unreferenced, including angle-> radians conversion. Blizzard's version utilization angle. Lua's standardized math library uses radians.

Abs (value)-returns the absolute value of the current value

Acos (value)-returns the arc cosine of this angle value.

Asin (value)-returns the arc sine of this angle value

Atan (value)-returns the arc tangent of this angle value

Atan2 (y, x)-returns the arc tangent of Y/X from the angle.

Ceil (value)-returns an integer. No matter how many digits are after the decimal point, the integer is entered in 1.

Cos (degrees)-Return angle cosine value

Deg (radians)-radians conversion Angle

Exp (value)-returns the exponent value of this value

Floor (value)-returns the integer of this value

Frexp (num)-returns the current number after the decimal point and the number of digits after the decimal point

Ldexp (value, multiple)-output a multiple of this value

Log (value)-returns the generous logarithm of this value (base number e)

Log10 (value)-returns the base value of 10.

Max (value [, values...])-find the maximum value in a bunch of values

Min (value [, values...])-find the minimum value in a bunch of values

Mod (value, modulus)-return the remainder of this value

Rad (degrees)-angle conversion radians

Random ([[lower,] upper])-returns a random number (the optional boundary is an integer)

Randomseed (seed)-seed the pseudo-random number generator

Sin (degrees)-returns the sine of the current angle

Sqrt (value)-the square root value of the return value (for example, the square root of 100 is 10)

Tan (degrees)-returns the tangent of the current angle

String Library

These table functions can also be referenced in the Lua string Library (they all start with string. For more information, see the string library)

Format (formatstring [, value [,...])-style string

Gsub (string, pattern, replacement [, limitCount])-overall Rotation

Strbyte (string [, index])-converts a string to an integer (a character can be specified ).

Strchar (asciiCode [,...])-converts an integer to a corresponding character

Strfind (string, pattern [, initpos [, plain])-searches the specified content in a specified target string (the third parameter is the index) and returns its informative location.

Strlen (string)-returns the number of characters in the current string

Strlower (string)-converts letters in a string to lowercase

Strmatch (string, pattern [, initpos])-unlike strfind, macth returns an informative value, while find returns the position of this value.

Strrep (seed, count)-returns the number of seed copies of a string

Strsub (string, index [, endIndex])-return the value at the specified position of the string.

Strupper (string)-converts string letters into uppercase letters

Tonumber (arg [, base])-returns a value if the parameter can be converted to a number. It can specify the type of conversion. It is a decimal integer.

Tostring (arg)-the conversion parameter is a string

The following string functions are unique to wow.

Strtrim (string)-Remove spaces before and after the string

Strsplit (delimiter, string)-split string

Strjoin (delimiter, string, string [,...])-connect strings Based on delimiter

Table Functions

These table functions can also be referenced in the Lua Table Library (they all start with "table.". For more information, see Table database f ).

It is also known that many tables are designed to only have numerical indexes, starting at 1 and not ending (such as like {[1] = "foo ", [3] = "bar"} --- [2] indicates the nil value that does not exist ). at work, wq.0431wq.com is not different from any other tables, but it is very likely that there will be undiscovered results. in writing lua, this is also a bug that can be mentioned at leisure.

Foreach (table, function)-enforces a function for each element in the table

Foreachi (table, function)-executes the function for each element in the table in order (without evaluation, you can use ipairs rotation)

Getn (table)-returns the current table size when it is treated as a chat table. it has been discarded. You can use the # symbol directly. rotate a table using # (table. getn (table)

Ipairs (table)-returns an iterative integer traversal table.

Pairs (table)-return an iterative traversal table

Sort (table [, comp])-sorts an array and specifies an optional sequence function.

Tinsert (table [, pos], value)-insert an element to a specified position (at the end of the table by default)

Tremove (table [, pos])-removes the elements at the specified position (the last in the default table)

Bit Functions

World of Warcraft includedLuaBitLib Library (both of which start with "bit."). Similar to bits in C. the bits in C are notLuaSpecificationsFunctionA part of the database, but it is used in WoW 1.9

Bit. bnot (a)-returns compensation for

Bit. band (w1,...)-return w's bit and

Bit. bor (w1,...)-return w's bit or

Bit. bxor (w1,...)-returns the bitwise OR of w.

Bit. lshift (a, B)-return a to the left offset to B

Bit. rshift (a, B)-return the right offset of a logic to B

Bit. arshift (a, B)-return a arithmetic offset to B

Bit. mod (a, B)-returns the integer remainder of a divided by B

LuaIs a scripting language.FunctionIt is extremely slow to compare your data structures, unless you have an extremely large database and the necessary defense RAM utilization, keep your messages to several or individual variables.

Summary: required documents for beginners:Lua FunctionThe content of the study notes has been introduced. I hope this article will help you!

Related Article

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.