Tao.Lua SDK Documentation

Lua Methods

The methods of the Lua class are listed below. For a complete list of Lua class members, see the Lua Members topic.

Public Static (Shared) Methods

lua_asset
lua_atpanic
lua_call
lua_checkstack Ensures that there are at least extra free stack slots in the stack. It returns false if it cannot grow the stack to that size. This function never shrinks the stack; if the stack is already larger than the new size, it is left unchanged.
lua_close Destroys all objects in the given Lua state (calling the corresponding garbage-collection metamethods, if any) and frees all dynamic memory used by this state. On several platforms, you may not need to call this function, because all resources are naturally released when the host program ends. On the other hand, long-running programs, such as a daemon or a web server, might need to release states as soon as they are not needed, to avoid growing too large.
lua_concat Concatenates the n values at the top of the stack, pops them, and leaves the result at the top. If n is 1, the result is the single string on the stack (that is, the function does nothing); if n is 0, the result is the empty string. Concatenation is done following the usual semantics of Lua.
lua_cpcall Calls the C function func in protected mode. func starts with only one element in its stack, a light userdata containing ud. In case of errors, lua_cpcall returns the same error codes as lua_pcall, plus the error object on the top of the stack; otherwise, it returns zero, and does not change the stack. All values returned by func are discarded.
lua_createtable Creates a new empty table and pushes it onto the stack. The new table has space pre-allocated for narr array elements and nrec non-array elements. This pre-allocation is useful when you know exactly how many elements the table will have. Otherwise you can use the function lua_newtable.
lua_dump Dumps a function as a binary chunk. Receives a Lua function on the top of the stack and produces a binary chunk that, if loaded again, results in a function equivalent to the one dumped. As it produces parts of the chunk, lua_dump calls function writer (see lua_Writer) with the given data to write them.
lua_equal Returns 1 if the two values in acceptable indices index1 and index2 are equal, following the semantics of the Lua == operator (that is, may call metamethods). Otherwise returns 0. Also returns 0 if any of the indices is non valid.
lua_error Generates a Lua error. The error message (which can actually be a Lua value of any type) must be on the stack top. This function does a long jump, and therefore never returns. (see luaL_error).
lua_gc Controls the garbage collector.
lua_getallocf Returns the memory-allocation function of a given state. If ud is not NULL, Lua stores in *ud the opaque pointer passed to lua_newstate.
lua_getfenv Pushes onto the stack the environment table of the value at the given index.
lua_getfield Pushes onto the stack the value t[k], where t is the value at the given valid index index. As in Lua, this function may trigger a metamethod for the "index" event
lua_getgccount
lua_getglobal Pushes onto the stack the value of the global name.
lua_gethook Returns the current hook function.
lua_gethookcount Returns the current hook count.
lua_gethookmask Returns the current hook mask.
lua_getinfo Returns information about a specific function or function invocation.
lua_getlocal Gets information about a local variable of a given activation record.
lua_getmetatable Pushes onto the stack the metatable of the value at the given acceptable index. If the index is not valid, or if the value does not have a metatable, the function returns 0 and pushes nothing on the stack.
lua_getref
lua_getregistry
lua_getstack Get information about the interpreter runtime stack.
lua_gettable Pushes onto the stack the value t[k], where t is the value at the given valid index index and k is the value at the top of the stack.
lua_gettop Returns the index of the top element in the stack. Because indices start at 1, this result is equal to the number of elements in the stack (and so 0 means an empty stack).
lua_getupvalue Gets information about a closure's upvalue. (For Lua functions, upvalues are the external local variables that the function uses, and that are consequently included in its closure.) lua_getupvalue gets the index n of an upvalue, pushes the upvalue's value onto the stack, and returns its name. funcindex points to the closure in the stack. (Upvalues have no particular order, as they are active through the whole function. So, they are numbered in an arbitrary order.)
lua_insert Moves the top element into the given valid index, shifting up the elements above this index to open space. Cannot be called with a pseudo-index, because a pseudo-index is not an actual stack position.
lua_isboolean Returns 1 if the value at the given acceptable index has type boolean, and 0 otherwise.
lua_iscfunction Returns 1 if the value at the given acceptable index is a C function, and 0 otherwise.
lua_isfunction Returns 1 if the value at the given acceptable index is a function (either C or Lua), and 0 otherwise.
lua_islightuserdata Returns 1 if the value at the given acceptable index is a light userdata, and 0 otherwise.
lua_isnil Returns 1 if the value at the given acceptable index is nil, and 0 otherwise.
lua_isnone
lua_isnoneornil
lua_isnumber Returns 1 if the value at the given acceptable index is a number or a string convertible to a number, and 0 otherwise.
lua_isstring Returns 1 if the value at the given acceptable index is a string or a number (which is always convertible to a string), and 0 otherwise.
lua_istable Returns 1 if the value at the given acceptable index is a table, and 0 otherwise.
lua_isthread Returns 1 if the value at the given acceptable index is a thread, and 0 otherwise.
lua_isuserdata Returns 1 if the value at the given acceptable index is a userdata (either full or light), and 0 otherwise.
lua_lessthan Returns 1 if the value at acceptable index index1 is smaller than the value at acceptable index index2, following the semantics of the Lua less then operator (that is, may call metamethods). Otherwise returns 0. Also returns 0 if any of the indices is non valid.
lua_load Loads a Lua chunk. If there are no errors, lua_load pushes the compiled chunk as a Lua function on top of the stack. Otherwise, it pushes an error message.
lua_newstate Creates a new, independent state.
lua_newtable Creates a new empty table and pushes it onto the stack.
lua_newthread Creates a new thread, pushes it on the stack, and returns a pointer to a lua_State that represents this new thread. The new state returned by this function shares with the original state all global objects (such as tables), but has an independent execution stack.
lua_newuserdata This function allocates a new block of memory with the given size, pushes onto the stack a new full userdata with the block address, and returns this address.
lua_next Pops a key from the stack, and pushes a key-value pair from the table at the given index (the "next" pair after the given key).
lua_objlen Returns the "length" of the value at the given acceptable index: for strings, this is the string length; for tables, this is the result of the length operator ('#'); for userdata, this is the size of the block of memory allocated for the userdata; for other values, it is 0.
lua_open
lua_pcall Calls a function in protected mode.
lua_pop Pops n elements from the stack.
lua_pushboolean Pushes a boolean value with value b onto the stack.
lua_pushcclosure Pushes a new C closure onto the stack.
lua_pushcfunction Pushes a C function onto the stack. This function receives a pointer to a C function and pushes onto the stack a Lua value of type function that, when called, invokes the corresponding C function.
lua_pushinteger Pushes a number with value n onto the stack.
lua_pushlightuserdata Pushes a light userdata onto the stack.
lua_pushliteral
lua_pushlstring Pushes the string pointed to by s with size len onto the stack. Lua makes (or reuses) an internal copy of the given string, so the memory at s can be freed or reused immediately after the function returns. The string can contain embedded zeros.
lua_pushnil Pushes a nil value onto the stack.
lua_pushnumber Pushes a number with value n onto the stack.
lua_pushstring Pushes the zero-terminated string pointed to by s onto the stack. Lua makes (or reuses) an internal copy of the given string, so the memory at s can be freed or reused immediately after the function returns. The string cannot contain embedded zeros; it is assumed to end at the first zero.
lua_pushthread Pushes the thread represented by L onto the stack.
lua_pushvalue Pushes a copy of the element at the given valid index onto the stack.
lua_rawequal Returns 1 if the two values in acceptable indices index1 and index2 are primitively equal (that is, without calling metamethods). Otherwise returns 0. Also returns 0 if any of the indices are non valid.
lua_rawget Similar to lua_gettable, but does a raw access (i.e., without metamethods).
lua_rawgeti Pushes onto the stack the value t[n], where t is the value at the given valid index index. The access is raw; that is, it does not invoke metamethods.
lua_rawset Similar to lua_settable, but does a raw assignment (i.e., without metamethods).
lua_rawseti Does the equivalent of t[n] = v, where t is the value at the given valid index index and v is the value at the top of the stack,
lua_ref
lua_register Sets the C function f as the new value of global name.
lua_remove Removes the element at the given valid index, shifting down the elements above this index to fill the gap. Cannot be called with a pseudo-index, because a pseudo-index is not an actual stack position.
lua_replace Moves the top element into the given position (and pops it), without shifting any element (therefore replacing the value at the given position).
lua_resume Starts and resumes a coroutine in a given thread.
lua_setallocf Changes the allocator function of a given state to f with user data ud.
lua_setfenv Pops a table from the stack and sets it as the new environment for the value at the given index.
lua_setfield Does the equivalent to t[k] = v, where t is the value at the given valid index index and v is the value at the top of the stack,
lua_setglobal Pops a value from the stack and sets it as the new value of global name.
lua_sethook Sets the debugging hook function.
lua_setlocal Sets the value of a local variable of a given activation record
lua_setmetatable Pops a table from the stack and sets it as the new metatable for the value at the given acceptable index.
lua_settable Does the equivalent to t[k] = v, where t is the value at the given valid index index, v is the value at the top of the stack, and k is the value just below the top.
lua_settop Accepts any acceptable index, or 0, and sets the stack top to this index. If the new top is larger than the old one, then the new elements are filled with nil. If index is 0, then all stack elements are removed.
lua_setupvalue Sets the value of a closure's upvalue. Parameters funcindex and n are as in lua_getupvalue (see lua_getupvalue). It assigns the value at the top of the stack to the upvalue and returns its name. It also pops the value from the stack.
lua_status Returns the status of the thread L.
lua_strlen
lua_toboolean Converts the Lua value at the given acceptable index to a C boolean value (0 or 1). Like all tests in Lua, lua_toboolean returns 1 for any Lua value different from false and nil; otherwise it returns 0. It also returns 0 when called with a non-valid index. (If you want to accept only actual boolean values, use lua_isboolean to test the value's type.)
lua_tocfunction Converts a value at the given acceptable index to a C function. That value must be a C function; otherwise, returns NULL.
lua_tointeger Converts the Lua value at the given acceptable index to the signed integral type lua_Integer. The Lua value must be a number or a string convertible to a number (see §2.2.1); otherwise, lua_tointeger returns 0.
lua_tolstring Converts the Lua value at the given acceptable index to a string (const char*). If len is not NULL, it also sets *len with the string length. The Lua value must be a string or a number; otherwise, the function returns NULL. If the value is a number, then lua_tolstring also changes the actual value in the stack to a string. (This change confuses lua_next when lua_tolstring is applied to keys during a table traversal.)
lua_tonumber Converts the Lua value at the given acceptable index to a number (see lua_Number). The Lua value must be a number or a string convertible to a number (see §2.2.1); otherwise, lua_tonumber returns 0.
lua_topointer Converts the value at the given acceptable index to a generic C pointer (void*). The value may be a userdata, a table, a thread, or a function; otherwise, lua_topointer returns NULL. Different objects will give different pointers. There is no way to convert the pointer back to its original value.
lua_tostring Equivalent to lua_tolstring with len equal to NULL.
lua_tothread Converts the value at the given acceptable index to a Lua thread (represented as lua_State*). This value must be a thread; otherwise, the function returns NULL.
lua_touserdata If the value at the given acceptable index is a full userdata, returns its block address. If the value is a light userdata, returns its pointer. Otherwise, returns NULL.
lua_type Returns the type of the value in the given acceptable index, or LUA_TNONE for a non-valid index (that is, an index to an "empty" stack position). The types returned by lua_type are coded by the following constants defined in lua.h: LUA_TNIL, LUA_TNUMBER, LUA_TBOOLEAN, LUA_TSTRING, LUA_TTABLE, LUA_TFUNCTION, LUA_TUSERDATA, LUA_TTHREAD, and LUA_TLIGHTUSERDATA.
lua_typename Returns the name of the type encoded by the value tp, which must be one the values returned by lua_type.
lua_unref
lua_upvalueindex
lua_xmove Exchange values between different threads of the same global state.
lua_yield Yields a coroutine.
luaI_openlib
luaL_addchar Adds the character c to the buffer B (see luaL_Buffer).
luaL_addlstring Adds the string pointed to by s with length l to the buffer B (see luaL_Buffer). The string may contain embedded zeros.
luaL_addsize Adds a string of length n previously copied to the buffer area (see luaL_prepbuffer) to the buffer B (see luaL_Buffer).
luaL_addstring Adds the zero-terminated string pointed to by s to the buffer B (see luaL_Buffer). The string may not contain embedded zeros.
luaL_addvalue Adds the value at the top of the stack to the buffer B (see luaL_Buffer). Pops the value.
luaL_argcheck Checks whether cond is true. If not, raises an error with the following message, where func is retrieved from the call stack:
bad argument #[numarg] to [func] ([extramsg])
luaL_argerror Raises an error with the following message, where func is retrieved from the call stack:
bad argument #[numarg] to [func] ([extramsg])
luaL_buffinit Initializes a buffer B. This function does not allocate any space; the buffer must be declared as a variable (see luaL_Buffer).
luaL_callmeta Calls a metamethod.
luaL_checkany Checks whether the function has an argument of any type (including nil) at position narg.
luaL_checkint Checks whether the function argument narg is a number and returns this number cast to an int.
luaL_checkinteger Checks whether the function argument narg is a number and returns this number cast to a lua_Integer.
luaL_checklong Checks whether the function argument narg is a number and returns this number cast to a long.
luaL_checklstring Checks whether the function argument narg is a string and returns this string; if l is not NULL fills *l with the string's length.
luaL_checknumber Checks whether the function argument narg is a number and returns this number.
luaL_checkoption Checks whether the function argument narg is a string and searches for this string in the array lst (which must be NULL-terminated). Returns the index in the array where the string was found. Raises an error if the argument is not a string or if the string cannot be found.
luaL_checkstack Grows the stack size to top + sz elements, raising an error if the stack cannot grow to that size. msg is an additional text to go into the error message.
luaL_checkstring Checks whether the function argument narg is a string and returns this string.
luaL_checktype Checks whether the function argument narg has type t.
luaL_checkudata Checks whether the function argument narg is a userdata of the type tname (see luaL_newmetatable).
luaL_dofile Loads and runs the given file.
luaL_dostring Loads and runs the given string.
luaL_findtable
luaL_getmetafield Pushes onto the stack the field e from the metatable of the object at index obj. If the object does not have a metatable, or if the metatable does not have this field, returns 0 and pushes nothing.
luaL_getmetatable Pushes onto the stack the metatable associated with name tname in the registry (see luaL_newmetatable).
luaL_getn
luaL_gsub Creates a copy of string s by replacing any occurrence of the string p with the string r. Pushes the resulting string on the stack and returns it.
luaL_loadbuffer Loads a buffer as a Lua chunk. This function uses lua_load to load the chunk in the buffer pointed to by buff with size sz.
luaL_loadfile Loads a file as a Lua chunk. This function uses lua_load to load the chunk in the file named filename. If filename is NULL, then it loads from the standard input. The first line in the file is ignored if it starts with a #.
luaL_loadstring Loads a string as a Lua chunk. This function uses lua_load to load the chunk in the zero-terminated string s.
luaL_newmetatable If the registry already has the key tname, returns 0. Otherwise, creates a new table to be used as a metatable for userdata, adds it to the registry with key tname, and returns 1.
luaL_newstate Creates a new Lua state, calling lua_newstate with an allocation function based on the standard C realloc function and setting a panic function (see lua_atpanic) that prints an error message to the standard error output in case of fatal errors.
luaL_openlibs Opens all standard Lua libraries into the given state.
luaL_opt
luaL_optint If the function argument narg is a number, returns this number cast to an int.
luaL_optinteger If the function argument narg is a number, returns this number cast to a lua_Integer. If this argument is absent or is nil, returns d. Otherwise, raises an error.
luaL_optlong If the function argument narg is a number, returns this number cast to a long. If this argument is absent or is nil, returns d. Otherwise, raises an error.
luaL_optlstring If the function argument narg is a string, returns this string. If this argument is absent or is nil, returns d. Otherwise, raises an error. If l is not NULL, fills the position *l with the results's length.
luaL_optnumber If the function argument narg is a number, returns this number. If this argument is absent or is nil, returns d. Otherwise, raises an error.
luaL_optstring If the function argument narg is a string, returns this string. If this argument is absent or is nil, returns d. Otherwise, raises an error.
luaL_prepbuffer Returns an address to a space of size LUAL_BUFFERSIZE where you can copy a string to be added to buffer B (see luaL_Buffer). After copying the string into this space you must call luaL_addsize with the size of the string to actually add it to the buffer.
luaL_pushresult Finishes the use of buffer B leaving the final string on the top of the stack.
luaL_putchar
luaL_ref Creates and returns a reference, in the table at index t, for the object at the top of the stack (and pops the object).
luaL_register Opens a library.
luaL_setn
luaL_typename Returns the name of the type of the value at index idx.
luaL_typerror Generates an error with a message.
luaL_unref Releases reference ref from the table at index t (see luaL_ref). The entry is removed from the table, so that the referred object can be collected. The reference ref is also freed to be used again.
luaL_where Pushes onto the stack a string identifying the current position of the control at level lvl in the call stack. Typically this string has the format {chunkname}:{currentline}:. Level 0 is the running function, level 1 is the function that called the running function, etc.
luaopen_base
luaopen_debug
luaopen_io
luaopen_math
luaopen_os
luaopen_package
luaopen_string
luaopen_table

Public Instance Methods

Equals (inherited from Object) 
GetHashCode (inherited from Object) 
GetType (inherited from Object) 
ToString (inherited from Object) 

See Also

Lua Class | Tao.Lua Namespace