Common function library summaries in LUA

Source: Internet
Author: User
Tags mathematical functions natural logarithm square root strfind

LUA Library functions

These functions are part of the LUA programming language, click here to learn more.

ASSERT (value)-Checks whether a value is non-nil, if not (if the debug command is opened in Wow.exe), displays a dialog box and outputs error debugging information

CollectGarbage ()-Garbage collector. (added to 1.10.1)

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

Error ("error message", level)-outputs a defined error message when an error occurs. Use Pcall () (see below) to catch the error.

Gcinfo ()-Returns the amount of memory used in the plug-in (KB) and the current garbage collector usage in kilobytes (KB).

Getfenv (function or integer)-Returns the stack structure or stack level of the function that this table has acquired

Getmetatable (obj, mtable)-Gets the current meta-table or user data object.

LoadString ("LUA Code")-parses a LUA code block in a string and returns the result as a function

Next (table, index)-Returns the next key, a pair of table values. Allow traversal of entire table

Pcall (func, arg1, arg2, ...)-protected call. Executes the function contents, capturing all exceptions and errors at the same time.

Select (Index, list)-Returns the value of the item in this list. Or the index of this item in the list

Setfenv (function or integer, table)-Sets the stack structure or stack level of the function that this table has acquired

Setmetatable (obj, mtable)-Sets the current table's meta-table or user data object

Time (table)-Returns the value from a Unix

Type (VAR)-Determines the current variable, "number", "string", "table", "function", or "UserData".

Unpack (table)-Unzip a table. Returns all values in the current table.

Xpcall (func, Err)-Returns a Boolean value indicating the function executed successfully and the error message that the call failed. In addition, the function or the wrong return value

Mathematical functions

These table functions can also refer to the LUA libraries (they all start with math. See the Math Library for more information).

Trigonometric functions are not referenced, including angle-to-radian conversions. Blizzard's version uses angles. and the standard math library of LUA 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 value of this angle value

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

Atan2 (y, X)-Returns the arc tangent of the y/x in the angle.

Ceil (value)-Returns an integer, regardless of the number after the decimal point, in which the integer part is 1

COS (degrees)-returns the cosine of an angle

DEG (radians)-radians conversion angle

Exp (value)-Returns the exponential value of this value

Floor (value)-Returns the integer value of this value

Frexp (NUM)-Returns the value of the current digit after the decimal point and the number of digits after the decimal point

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

Log (value)-Returns the natural logarithm of this value (base e)

LOG10 (value)-Returns a base value of 10

Max (value[, Values ...])-Find the maximum value in a pile of values

Min (Value[,values ...])-Find the minimum value in a pile of values

MoD (Value,modulus)-Returns the remainder of this value

rad (degrees)-angle conversion radians

Random ([[[Lower,] upper])-Returns a random number (optional bounds are integer values)

Randomseed (Seed)-Seeding a pseudo-random number generator

Sin (degrees)-returns the sinusoidal value of the current angle

sqrt (value)-Returns the square root of a numeric value (for example, 100 squared root is 10)

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

String Library

These table functions can also refer to the LUA string library (they all start with string. Refer to the strings library for more information)

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

Gsub (string,pattern,replacement[, Limitcount])-Global substitution

Strbyte (string[, index])-The conversion string is an integer value (you can specify a character).

Strchar (asciicode[, ...])-Converts an integer to the corresponding character

Strfind (String, pattern[, initpos[, plain])-searches for the specified content in a specified target string (the third parameter is an index) and returns its specific position.

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

Strlower (String)-Converts the letter of a string to lowercase format

Strmatch (String, pattern[, Initpos])-unlike strfind, MACTH returns a specific value, and find returns the position of this value

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

Strsub (String, index[, EndIndex])-Returns the value of the specified position of the string.

Strupper (String)-Converts the letter of a string to an uppercase format

Tonumber (arg[, Base)-Returns a numeric value if the argument can be converted to a number. You can specify the type of conversion. Default is a decimal integer

ToString (ARG)-The conversion parameter is a string

The following string functions are unique to wow

Strtrim (String)-remove space before and after string

Strsplit (delimiter, String)-split string

Strjoin (delimiter, String, string[, ...])-concatenate strings by delimiter

Table functions

These table functions can also refer to the LUA table library (they all start with "table.") and see table Library F for more information.

Also know that many tables are designed to have only numeric indexes, starting at 1 and without endings (like {[1] = "Foo", [3] = "Bar"}---[2] is not present, so it is nil value). Working with no other table makes no difference, but it is likely to produce unexpected results. In writing Lua, this is the usual bug.

foreach (table,function)-Executes a function for each element in a table

Foreachi (table,function)-executes functions for each element in the table, accessed sequentially (not recommended, can be replaced with ipairs)

GETN (table)-Returns the size of the current table when it is used as a chat table. Now obsolete, you can use the # symbol directly. Use # (table) instead of TABLE.GETN (table)

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

Pairs (table)-Returns an iteration through the table

Sort (table[, comp])-Sort an array and optionally specify an optional order function

Tinsert (table[, POS], value)-Inserts an element into the specified position (default at the end of the table)

Tremove (table[, POS])-Deletes the element at the specified position (the last of the default table)

Bit Functions

World of Warcraft contains the Lua bitlib library (they all take "bit." Start). Same as the bitwise operation of C. Bit operations libraries are not part of the LUA standard library, but are used in Wow 1.9

Bit.bnot (a)-Returns the supplement to a A

Bit.band (W1,...)-Returns the bit of W with

Bit.bor (W1,...)-Returns the bit of W or

Bit.bxor (W1,...)-Returns the bit XOR of W

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

Bit.rshift (b)-Returns a logical right offset to B-bit

Bit.arshift (b)-Returns a arithmetic offset to B-bit

Bit.mod (b)-Returns the integer remainder of a divided by B

Lua is a scripting language that uses these functions to compare your data structures very slowly. Unless you have a very large database and need to protect the RAM used, save your information to several or individual variables.

Common function library summaries in LUA

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.