| parrotcode: Lua Basic Library | |
| Contents | Language Implementations | Lua |

lib/luabasic.pir - Lua Basic Library

The basic library provides some core functions to Lua.
See "Lua 5.0 Reference Manual", section 5.1 "Basic Functions".

_G_G._G = _G).
Lua itself does not use this variable; changing its value does not affect any environment.
(Use setfenv to change environments.)_VERSION"Lua 5.0".
assert (v [, message])v is nil or false; otherwise,
returns this value.
message is an error message; when absent,
it defaults to "assertion failed!"collectgarbage ([limit])limit is absent,
it defaults to zero (thus forcing a garbage-collection cycle).dofile (filename)dofile executes the contents of the standard input (stdin).
Returns any value returned by the chunk.
In case of errors,
dofile propagates the error to its caller (that is,
it does not run in protected mode).error (message [, level])message as the error message.
Function error never returns.level argument specifies where the error message points the error.
With level 1 (the default),
the error position is where the error function was called.
Level 2 points the error to where the function that called error was called; and so on.getfenv (f)f can be a Lua function or a number,
which specifies the function at that stack level: Level 1 is the function calling getfenv.
If the given function is not a Lua function,
or if f is 0,
getfenv returns the global environment.
The default for f is 1."__fenv" field,
returns the associated value,
instead of the environment.getmetatable (object)"__metatable" field,
returns the associated value.
Otherwise,
returns the metatable of the given object.gcinfo ()ipairs (t)t,
and 0,
so that the construction for i,v in ipairs(t) do ... end
1,t[1]), (2,t[2]), ... , up to the first integer key with a nil value in the table.loadfile (filename)loadlib (libname, funcname)libname. Inside this library, looks for a function funcname and returns this function as a C function.libname must be the complete file name of the C library, including any eventual path and extension.loadstring (string [, chunkname])chunkname is the name to be used in error messages and debug information. assert(loadstring(s))()
next (table [, index])next returns the next index of the table and the value associated with the index. When called with nil as its second argument, next returns the first index of the table and its associated value. When called with the last index, or with nil in an empty table, next returns nil. If the second argument is absent, then it is interpreted as nil.next only considers fields with non-nil values. The order in which the indices are enumerated is not specified, even for numeric indices. (To traverse a table in numeric order, use a numerical for or the ipairs function.)next is undefined if, during the traversal, you assign any value to a non-existent field in the table.pairs (t)next function and the table t (plus a nil), so that the construction for k,v in pairs(t) do ... end
t.pcall (f, arg1, arg2, ...)f with the given arguments in protected mode. That means that any error inside f is not propagated; instead, pcall catches the error and returns a status code. Its first result is the status code (a boolean), which is true if the call succeeds without errors. In such case, pcall also returns all results from the call, after this first result. In case of any error, pcall returns false plus the error message.print (e1, e2, ...)stdout, using the tostring function to convert them to strings. This function is not intended for formatted output, but only as a quick way to show a value, typically for debugging. For formatted output, use format.rawequal (v1, v2)v1 is equal to v2, without invoking any metamethod. Returns a boolean.rawget (table, index)table[index], without invoking any metamethod. table must be a table; index is any value different from nil.rawset (table, index, value)table[index] to value, without invoking any metamethod. table must be a table, index is any value different from nil, and value is any Lua value.require (packagename)_LOADED to determine whether packagename is already loaded. If it is, then require returns the value that the package returned when it was first loaded. Otherwise, it searches a path looking for a file to load.LUA_PATH is a string, this string is the path. Otherwise, require tries the environment variable LUA_PATH. As a last resort, it uses the predefined path "?;?.lua".require will change each interrogation mark in the template to packagename, and then will try to load the resulting file name. So, for instance, if the path is "./?.lua;./?.lc;/usr/local/?/?.lua;/lasttry"
require "mod" will try to load the files ./mod.lua, ./mod.lc, /usr/local/mod/mod.lua, and /lasttry, in that order._LOADED, the package name with the value that the package returned, and returns that value. If the package returns nil (or no value), require converts this value to true. If the package returns false, require also returns false. However, as the mark in table _LOADED is false, any new attempt to reload the file will happen as if the package was not loaded (that is, the package will be loaded again).require signals an error.require defines the global variable _REQUIREDNAME with the package name. The package being loaded always runs within the global environment.setfenv (f, table)f can be a Lua function or a number, which specifies the function at that stack level: Level 1 is the function calling setfenv.f is 0 setfenv changes the global environment of the running thread. If the original environment has a "__fenv" field, setfenv raises an error.setmetatable (table, metatable)"__metatable" field, raises an error.tonumber (e [, base])tonumber returns that number; otherwise, it returns nil.tostring (e)format."__tostring" field, tostring calls the corresponding value with e as argument, and uses the result of the call as its result.type (v)"nil" (a string, not the value nil), "number", "string", "boolean", "table", "function", "thread", and "userdata".unpack (list) return list[1], list[2], ..., list[n]
table.getn function.xpcall (f, err)pcall, except that you can set a new error handler.xpcall calls function f in protected mode, using err as the error handler. Any error inside f is not propagated; instead, xpcall catches the error, calls the err function with the original error object, and returns a status code. Its first result is the status code (a boolean), which is true if the call succeeds without errors. In such case, xpcall also returns all results from the call, after this first result. In case of any error, xpcall returns false plus the result from err.
Francois Perrad.
|
|
|