Base globals
The base globals are functions implemented by Lua that are always available globally.
Global functions
|
|||||||||||
Takes in a boolean value where, on the condition that it evaluates to false or nil an error is thrown with the specified message. | |||||||||||
Syntax | assert(
|
||||||||||
Returns | nil | ||||||||||
Part of | CC:Tweaked | ||||||||||
API | Base globals | ||||||||||
| |||||||||||
|
|
|||||||||||
Loads and then runs a file, using loadfile. The following is what the internals of this function look like:
function dofile(fileName)
local f = assert(loadfile(fileName))
return f()
end
|
|||||||||||
Syntax | dofile(
|
||||||||||
Returns | whatever the file returns | ||||||||||
Part of | CC:Tweaked (source) | ||||||||||
API | Base globals | ||||||||||
See also | loadfile | ||||||||||
|
|
|||||||||||
Throws an error with the specified message at the current line and call frame or if specified, level frames upward. | |||||||||||
Syntax | error(
|
||||||||||
Returns | nil | ||||||||||
Part of | CC:Tweaked | ||||||||||
API | Base globals | ||||||||||
| |||||||||||
|
|
|||
Returns the metatable of a table - this is whatever has been set with setmetatable. Some keys in this metatable will (if they exist) be called when certain operators are used - see the Lua Users wiki. However if the metatable contains the __metatable key the value of it will be returned instead. If there is no metatable nil is returned. | |||
Syntax | getmetatable(
|
||
Returns | table | ||
Part of | CC:Tweaked | ||
API | Base globals |
Ipairs
|
|||||||||||
Loads chunk ld (or, if ld is a function, loads the chunk returned by it) as a function and returns it. Error messages use source if available, or a representation of ld. | |||||||||||
Syntax | load(
|
||||||||||
Returns | function or nil | ||||||||||
Part of | CC:Tweaked | ||||||||||
API | Base globals | ||||||||||
|
|
|||||||||||
Takes a filename and will return a function if it's succesful. If it's not, it will return nil and a error message.
|
|||||||||||
Syntax | loadfile(
|
||||||||||
Returns | function string | ||||||||||
Part of | CC:Tweaked (source) | ||||||||||
API | Base globals | ||||||||||
|
Loadstring
|
|||||||||||
Gets the next index and its value of the table table starting at index. If index is nil, then it returns an initial index and value. This function returns nil if called with the last index or table is nil. However, the order that indices are returned are not in order, even if table has numerical indices. | |||||||||||
Syntax | next(
|
||||||||||
Returns | various index, various value | ||||||||||
Part of | CC:Tweaked | ||||||||||
API | Base globals | ||||||||||
|
Package Pairs
|
|||||||||||
Calls func (with arguments as parameters) in protected mode—That is, any errors thrown while the function is executing are caught and returned by the nearest enclosing pcall. | |||||||||||
Syntax | pcall(
|
||||||||||
Returns | bool false, any error | bool true, any returns | ||||||||||
Part of | Lua (source) | ||||||||||
API | Base globals | ||||||||||
|
|
|||||||||||
Prints any number of arguments (space separated) at the current cursor position in the current term. All the arguments will automatically be converted to a string using the tostring function, and concatenated, separated by spaces. This function automatically moves to the next line after writing. As well as this, it performs text wrapping, meaning if the string is too big for the term, it will continue writing on the next line. print returns the number of lines it printed. | |||||||||||
Syntax | print(
|
||||||||||
Returns | number linesPrinted | ||||||||||
Part of | CC:Tweaked (source) | ||||||||||
API | BIOS globals | ||||||||||
| |||||||||||
| |||||||||||
|
Rawequal Rawget Rawset Select Setmetatable
|
|||||||||||
Parses a number contained in a string. Useful for retrieving numeric values from user input. If str cannot be parsed as a number, the function will return nil. | |||||||||||
Syntax | tonumber(
|
||||||||||
Returns | number | nil | ||||||||||
Part of | Lua (source) | ||||||||||
API | Base globals | ||||||||||
|
|
|||||||||||
Converts x to a string.
x.."" . |
|||||||||||
Syntax | tostring(
|
||||||||||
Returns | string | ||||||||||
Part of | Lua (source) | ||||||||||
API | Base globals | ||||||||||
|
|
|||||||||||
Returns a string representing the type of the given variable. | |||||||||||
Syntax | type(
|
||||||||||
Returns | string type | ||||||||||
Part of | CC:Tweaked | ||||||||||
API | Base globals | ||||||||||
| |||||||||||
|
Xpcall
gollark: What could POSSIBLY go wrong with having the only usable web rendering engine be controlled by Google?
gollark: Although that *should* make it just pass it directly for 0, hm.
gollark: > * So: if the arg is a PyLong, use its absolute value.> * Otherwise use its hash value, cast to unsigned.
gollark: https://github.com/python/cpython/blob/fa2eee975dbf7d2728021ef9d97328bbe88351cf/Modules/_randommodule.c#L266
gollark: The `super().seed(a)` function it passes stuff onto may be doing things internally.
This article is issued from Computercraft. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.