LUA basic function library "go"

Source: Internet
Author: User

Transferred from: http://www.cnblogs.com/whiteyun/archive/2009/08/12/1543184.html

The base library is a LUA built-in library that does not require additional loading

Assert (v [, message])
Function: Equivalent to the assertion of C,
Parameters:
V: When the expression V is nil or false will trigger an error,
Message: The information returned when an error occurs, default to "assertion failed!"


--------------------------------------------------------------------------------

CollectGarbage (opt [, Arg])
Function: A common interface for the garbage collector to operate the garbage collector
Parameters:
OPT: Operating method flag
"Stop": Stop the garbage collector
"Restart": Restart the garbage collector
"Collect": Perform a full garbage collection cycle
"Count": Returns the amount of memory used in the current LUA (in kilobytes)
"Step": Step through a garbage collection. The step "size" is specified by the parameter arg (large values require multiple steps to complete), and multiple experiments are required to achieve optimal results if you want to accurately specify the step size. Returns true if the step completes a collection loop at a time
"Setpause": Sets the value of arg/100 as the amount of time provisionally collected
"Setstepmul": Sets the value of arg/100 as the increment of step (that is, the new step = Old Step *arg/100)


--------------------------------------------------------------------------------

Dofile (filename)
Function: Opens and executes a LUA block, and when the parameter filename is omitted, the contents of the standard input device (stdin) are executed. Returns the return value of all blocks. When an error occurs, Dofile reflects the error to the caller
Note: Dofile cannot be run in protected mode


--------------------------------------------------------------------------------

Error (message [, Level])
Function: Terminates the function being executed and returns the contents of the message as an error message (the error function will never return)
Typically, error appends information from the wrong location to the message header.
The level parameter indicates where the error was obtained,
level=1[default]: To invoke the error location (file + line number)
Level=2: The function that indicates which function called the error
Level=0: Do not add error location information


--------------------------------------------------------------------------------

_G Global Environment Table (global variables)
Function: Table _g._g = _g of variable values that record global environment


--------------------------------------------------------------------------------

Getfenv (f)
Function: Returns the current environment table for function f
Parameters: F can be the level of the function or call stack, level 1[default] is the current function, level 0 or other value will return the global environment _g


--------------------------------------------------------------------------------

Getmetatable (object)
Function: Returns the meta-table of the specified object (if the meta-table of object. The __metatable key has a value, the meta table of object is returned. The value of __metatable), and nil is returned when object has no meta-table


--------------------------------------------------------------------------------

Ipairs (t)
Function: Returns three value iteration function, table, 0
Multiple key names and key-value pairs for exhaustive tables
such as: For i,v in Ipairs (t) do

End
Each loop assigns the index I, the key value to V
Note: This function can only be used for tables accessed with a numeric index such as: t={"1", "Cash"}


--------------------------------------------------------------------------------

Load (func [, Chunkname])
Function: Load a function in a block, each call to Func will return a string that joins the previous knot, and will return nil at the end of the block
When no error occurs, a compiled block is returned as a function, otherwise nil plus error information is returned, and the environment for this function is the global environment
Chunkname for error and debug information


--------------------------------------------------------------------------------

LoadFile ([filename])
Features: Similar to load, but loaded with files or content loaded with standard input (stdin) when filename is not specified


--------------------------------------------------------------------------------

LoadString (string [, Chunkname])
Function: Similar to load, but loaded with a string of content
such as: Assert (LoadString (s)) ()


--------------------------------------------------------------------------------

Next (table [, index])
Function: Allows the program to traverse each field in the table, returning the next index and the value of the index.
Parameters: Table: Tables to traverse
Index: The number in the previous cable of the index to be returned, when index is nil[], returns the value of the first index, or nil if the index number is the last index or the table is empty
Note: You can use next (t) to detect if the table is empty (this function can only be used for tables with a numeric index similar to ipairs)


--------------------------------------------------------------------------------

Ipairs (t)
Function: Returns three values next function, table, 0
Multiple key names and key-value pairs for exhaustive tables
such as: for n,v in pairs (t) do

End
Each loop assigns the index I, the key value to V
Note: This function can only be used for tables accessed with the key name index such as: t={id= "1", name= "cash"}


--------------------------------------------------------------------------------

Pcall (f, arg1,)
function: Calling a function in protected mode (that is, the error that occurs will not be reflected to the caller)
When the calling function succeeds in returning true, False is returned with an error message when it fails


--------------------------------------------------------------------------------

Print (...)
function: Simply format the contents of the output parameters in ToString mode


--------------------------------------------------------------------------------

Rawequal (v1, v2)
Function: Detects if V1 is equal to V2, this function does not invoke any meta-table methods


--------------------------------------------------------------------------------

Rawget (Table,index)
Function: Gets the value of the specified index in the table, this function does not invoke the method of any meta-table, returns the corresponding value successfully, and returns nil when the index does not exist
Note: This function can only be used for tables accessed with a numeric index such as: t={"1", "Cash"}


--------------------------------------------------------------------------------

Rawset (table, Index,value)
Function: Sets the value of the specified index in the table, which does not invoke the method of any of the meta-tables, and this function returns the table


--------------------------------------------------------------------------------

Select (index,)
Function: When index is numeric, all parameters with index greater than index are returned: for example: Select (2, "A", "B") returns "B"
When index is "#", the total number of parameters is returned (excluding index)


--------------------------------------------------------------------------------

Setfenv (f, table)
Function: Set the Environment table for function f
Parameters: F can be a function or call stack level, level 1[default] is the current function, level 0 sets the current thread's environment table


--------------------------------------------------------------------------------

Setmetatable (table,metatable)
Function: Sets the meta-table metatable for the specified table, and cancels the table's meta table if metatable is nil, triggering an error when metatable has a __metatable field
Note: You can only specify a meta table for a lua_ttable table type


--------------------------------------------------------------------------------

Tonumber (e [, Base])
Function: Attempts to convert the parameter E to a number and returns nil when it cannot be converted
Base (2~36) indicates that the parameter e is currently used in the binary, the default is 10, such as Tonumber (11,2) =3


--------------------------------------------------------------------------------

TOSTIRNG (e)
Function: Converts the argument e to a string, and this function will trigger the __tostring event of the meta-table


--------------------------------------------------------------------------------

Type (v)
Function: Returns the type name of the parameter ("nil", "Number", "string", "Boolean", "table", "function", "thread", "UserData")


--------------------------------------------------------------------------------

Unpack (list [, I [, J]])
Function: Returns the value of the index of the specified table, I is the starting index, and J is the end index
Note: This function can only be used for tables accessed with a numeric index, otherwise it will only return nil such as: t={"1", "Cash"}


--------------------------------------------------------------------------------

_version
Function: Returns the current LUA version number "LUA 5.1".


--------------------------------------------------------------------------------

Xpcall (f, Err)
Function: Similar to Pcall, calling a function in protected mode (that is, the error that occurs will not be reflected to the caller)
However, you can specify a new error-handling function handle
When the calling function succeeds in returning true, the failure returns false plus err returns the result

LUA basic function library "go"

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.