Module rglua::lua[][src]

Re-exports

pub use types::*;

Modules

LuaJIT specific global constants

Constants

This is libc’s default so we’ll roll with it Used internally for LuaBuffer.

Index of the lua environment.
This is like getfenv() or _ENV in later lua versions

Error when running the error handler, code used by functions like super::lua_pcall

Memory allocation, error code used by many functions like super::lua_load

Runtime error, code used by functions like super::lua_pcall

Syntax error, code used by functions like super::lua_load

Enum used with super::lua_gc - Restarts the garbage collector

Enum used with super::lua_gc - Returns the total number of live Lua objects in the current Lua state

Enum used with super::lua_gc - Returns the total number of live Lua objects in the current Lua state, plus the total number of Lua objects in unreachable threads

Enum used with super::lua_gc - Restarts the garbage collector

Enum used with super::lua_gc - Sets lua_gc’s pause threshold.

Enum used with super::lua_gc - Sets lua_gc’s step multiplier.

Enum used with super::lua_gc - Performs a single step of the garbage collector.

Enum used with super::lua_gc - Stops the garbage collector.

Index of _G

Size of LuaDebug.short_src

Minimum number of stack levels guaranteed to C whenever it is called into by lua.

Number of returns to use in functions like lua_pcall to represent 0 or more.

Number of primitive lua types (excluding garrysmod userdata types)

OK status code used by several functions like super::lua_status, super::lua_pcall

Index of the lua registry.
What you’d get from debug.getregistry()

Boolean type

Function type created by super::lua_pushcfunction, super::lua_pushcclosure or retrieved from lua.

‘Light’ Userdata type. This is just a pointer to something owned by C without a custom metatable, as a TUSERDATA may have.

‘nil’ type

‘None’ / ‘No value’ type.

Number type.
This is a double, or f64

String type, this is a LuaString

Table type created by super::lua_newtable

Thread / Coroutine type, created by super::lua_newthread

‘Heavy’ Userdata type managed by lua.
Created by super::lua_newuserdata

YIELD status code used by super::lua_status

Statics

Path to lua_shared.dll relative to std::env::current_dir()

Path to lua_shared.dll relative to std::env::current_dir() This tries to retrieve LUA_SHARED_PATH, creates a libloading::Library to it and returns it. If it could not find lua_shared.dll or create a libloading::Library, this will panic!

This is a C API extension to allow control of the VM from “C”

Adds the string pointed to by s with length l to the LuaBuffer b. The string may contain embedded zeros.

Adds the zero-terminated string pointed to by s to the LuaBuffer b (see luaL_Buffer). The string may not contain embedded zeros.

Adds the value at the top of the stack to the buffer LuaBuffer b. Pops the value. This is the only function on string buffers that can (and must) be called with an extra element on the stack, which is the value to be added to the buffer.

Raises an error with the following message, where func is retrieved from the call stack:

Initializes a buffer b. This function does not allocate any space; the buffer must be declared as a variable.

Calls a metamethod. If the object at index obj has a metatable and this metatable has a field e, this function calls this field and passes the object as its only argument.

Checks whether the function has an argument of any type (including nil) at position narg.

Same as luaL_checknumber, but casts it to an integer.

Checks whether the function argument narg is a string and returns this string. If len is not 0 fills *len with the string’s length.

Checks whether the value at stack index ‘narg’ is a number and returns this number. If it is not a lua number, will throw an error to Lua.

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.

Checks whether the function argument narg has type t. See lua_type for the encoding of types for t.

Checks whether the function argument narg is a userdata of the type tname (see luaL_newmetatable).

Raises an error. The error message format is given by fmt plus any extra arguments, following the same rules of lua_pushfstring. It also adds at the beginning of the message the file name and the line number where the error occurred, if this information is available.

This function produces the return values for process-related functions in the standard library (os.execute and io.close). Although, those don’t exist in gmod..

This function produces the return values for file-related functions in the standard library (like File:seek)

Function used internally by lua

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.

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

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.

Loads a file as a Lua chunk. This function uses lua_load to load the chunk in the file named filename. If filename is None, then it loads from the standard input. The first line in the file is ignored if it starts with a # (shebang)

Same as how lua_loadx is to lua_load. You should probably use luaL_loadfile instead.

Loads a string as a Lua chunk. This function uses lua_load to load the chunk in the zero-terminated string s. This function returns the same results as lua_load. Also as lua_load, this function only loads the chunk; it does not run it.

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. In both cases pushes onto the stack the final value associated with tname in the registry.

Creates a metatable with type and typeid Same as luaL_newmetatable, but also sets the MetaName and MetaID fields of the metatable

Creates a new Lua state. This calls lua_newstate with an allocator based on the standard C realloc function and then sets a panic function (see lua_atpanic) that prints an error message to the standard error output in case of fatal errors.

Internally called by luaL_register, opens given list of LuaRegs with number of functions provided explicitly

Opens all of the standard libraries for a lua state

If the function argument narg is a number, returns this number cast to a LuaInteger. If this argument is absent or is nil, returns d. Otherwise, raises an error.

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 the function argument arg is a number, returns this number. If this argument is absent or is nil, returns d. Otherwise, raises an error.

Returns an address to a space of size $crate::lua::BUFFERSIZE where you can copy a string to be added to buffer LuaBuffer b. 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.

Finishes the use of buffer b leaving the final string on the top of the stack.

Creates and returns a reference, in the table at index t, for the object at the top of the stack (and pops the object). A reference is a unique integer key. As long as you do not manually add integer keys into table t, luaL_ref ensures the uniqueness of the key it returns. You can retrieve an object referred by reference r by calling lua_rawgeti(L, t, r). Function luaL_unref frees a reference and its associated object.

Registers a reg of functions onto the Lua State’s _G[libname]. For example you could set libname to cstr!(“math”) to add functions onto the math table or create it if it does not exist.

Creates and pushes a traceback of the stack L1. If msg is not None it is appended at the beginning of the traceback. The level parameter tells at which level to start the traceback.

Generates an error with a message like the following:

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. If ref is LUA_NOREF or LUA_REFNIL, this does nothing.

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 following format:

Sets a new panic function and returns the old one. If an error happens outside any protected environment, Lua calls a panic function and then calls exit(EXIT_FAILURE), thus exiting the host application. Your panic function can avoid this exit by never returning (e.g., doing a long jump). The panic function can access the error message at the top of the stack.

Calls a function. To call a function you must use the following protocol: first, the function to be called is pushed onto the stack; then, the arguments to the function are pushed in direct order – that is, the first argument is pushed first.

Ensures that there are at least extra free stack slots in the stack. It returns C ‘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.

Destroys the given lua state. You probably don’t want to do this, unless you just want to self destruct the server / your client.

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, this 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.

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.

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.

Returns 1 or 0 for if the two values at given indices are equal, calling __eq metamethods along the way unlike lua_rawequal. Also returns 0 if any of the indices are non valid.

Generates a Lua error. The error message (which can actually be a Lua value of any type) must be on the stack top.T This function does a long jump, and therefore never returns. (see luaL_error).

Controls lua’s garbage collector Performs different tasks depending on what you provide to the what parameter.

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.

Pushes onto the stack the environment table of the value at the given index.

Pushes onto the stack the value t[k], where t is the value at idx. As in Lua, this function may trigger a metamethod for the “index” event (see §2.8).

Returns the current hook function.

Returns the current hook count.

Returns the current hook mask.

Returns information about a specific function or function invocation.

Gets information about a local variable of a given activation record. The parameter ar must be a valid activation record that was filled by a previous call to lua_getstack or given as argument to a hook (see lua_Hook). The index n selects which local variable to inspect (1 is the first parameter or active local variable, and so on, until the last active local variable). lua_getlocal pushes the variable’s value onto the stack and returns its name.

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.

Get information about the interpreter runtime stack. This function fills in the priv part of the LuaDebug structure with information about the function that is running at the given level.

Pushes onto the stack the value t[k], where t is the value at the given valid index and k is the value at the top of the stack. This function pops the key from the stack (putting the resulting value in its place). As in Lua, this function may trigger a metamethod for the “index” event (see §2.8).

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).

Gets information about a closure’s upvalue. This is basically debug.getlocal. (For Lua functions, upvalues are the external local variables that the function uses, and that are consequently included in its closure.)

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.

Returns 1 if the value at the given acceptable index is a C function, and 0 otherwise.

Returns 1 if the value at the given acceptable index is a number or a string convertible to a number, and 0 otherwise.

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.

Returns 1 if the value at the given acceptable index is a userdata (either full or light), and 0 otherwise.

Returns 1 if the value at acceptable index index1 is smaller than the value at acceptable index index2, following the semantics of the Lua < operator (that is, may call metamethods).

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.

Function used by lua_load internally. mode is whether to take the chunk as bytecode or as text. You should just use lua_load instead though.

Creates a new, independent state. Note you might be looking for luaL_newstate, which has no parameters Returns None if cannot create the state (due to lack of memory). The argument f is the allocator function; Lua does all memory allocation for this state through this function. The second argument, ud, is an opaque pointer that Lua simply passes to the allocator in every call.

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. There is no explicit function to close or to destroy a thread. Threads are subject to garbage collection, like any Lua object.

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.

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). If there are no more elements in the table, then lua_next returns 0 (and pushes nothing).

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.

Calls a function in protected mode. Both nargs and nresults have the same meaning as in lua_call. If there are no errors during the call, lua_pcall behaves exactly like lua_call.

Pushes a boolean onto the stack. Note this is still a c_int so use 0 for false and 1 for true.

Pushes a c function on the stack with associated values.

Pushes a formatted LuaString to the stack

Pushes a number with value n onto the stack.

Pushes a light userdata onto the stack. Userdata represent C values in Lua. A light userdata represents a pointer. It is a value (like a number): you do not create it, it has no individual metatable, and it is not collected (as it was never created). A light userdata is equal to “any” light userdata with the same C address.

Pushes a string of length sz onto the stack.

Pushes a nil value onto the stack.

Pushes the number num onto the stack.

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.

Pushes a given thread (representing l) to the stack.

Pushes a copy of the element at the given valid index onto the stack.

Returns 1 or 0 for if the two values at given indices are equal, without calling metamethods, as lua_equal does. Also returns 0 if any of the indices are non valid.

This is the same as lua_gettable, but without calling any metamethods

Pushes onto the stack the value t[n], where t is the value at the given valid index. The access is raw; that is, it does not invoke metamethods.

Same as lua_settable, but without calling any metamethods.

Does the equivalent of t[n] = v, where t is the value at the given valid index and v is the value at the top of the stack. This function pops the value from the stack. The assignment is raw; that is, it does not invoke metamethods.

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. (Example of pseudoindices are LUA_GLOBALSINDEX and globals::REGISTRYINDEX)

Replaces object at index (idx) with the object at the top of the stack (-1) and pops the stack.

Starts and resumes a coroutine in a given thread. Blame garry for the _real

Changes the allocator function of a given state to f with user data ud.

Pops a table from the stack and sets it as the new environment for the value at the given index.

Does the equivalent to t[k] = v, where t is the value at the given valid index and v is the value at the top of the stack. This function pops the value from the stack. As in Lua, this function may trigger the __newindex metamethod.

Sets the debugging hook function.

Sets the value of a local variable of a given activation record. Parameters ar and n are as in lua_getlocal (see lua_getlocal). lua_setlocal assigns the value at the top of the stack to the variable and returns its name. It also pops the value from the stack.

Pops a table from the stack and sets it as the new metatable for the value at the given acceptable index.

Does the equivalent to t[k] = v, where t is the value at the given valid index, v is the value at the top of the stack, and k is the value just below the top.

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.

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.

Returns the status of the thread/coroutine l.

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 returning 0. This 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.)

Converts a value at the given acceptable index to a C function. That value must be a C function; otherwise, returns None.

Converts the Lua value at the given acceptable index to the signed integral type LuaInteger. The Lua value must be a number or a string convertible to a number; otherwise, this returns 0. If the number is not an integer, it is truncated in some non-specified way.

Converts the Lua value at the given index to the signed integral type lua_Integer. The Lua value must be an integer, or a number or string convertible to an integer; otherwise, this returns 0. If isnum is not None, its referent is assigned a boolean value that indicates whether the operation succeeded.

Converts the Lua value at the given index to a C string. If len is not 0, it also sets *len with the string length. The Lua value must be a string or a number; otherwise, the function returns a nullptr. 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.)

Converts the Lua value at the given acceptable index to a LuaNumber. The Lua value must be a number or a string convertible to a number; otherwise, this returns 0.

Converts the Lua value at the given index to a LuaNumber (f64). The Lua value must be a number or a string convertible to a number; otherwise, this returns 0. If isnum is not None, its referent is assigned a boolean value that indicates whether the operation succeeded.

Converts the value at the given acceptable index to a generic C pointer (void*). The value can be a userdata, a table, a thread, or a function; otherwise this returns None. Different objects will give different pointers. There is no way to convert the pointer back to its original value.

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 None.

Returns the value at the given index assuming it is a userdata.

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: TNIL, TNUMBER, TBOOLEAN, TSTRING, TTABLE, TFUNCTION, TUSERDATA, TTHREAD, and TLIGHTUSERDATA.

Returns the name of the type typeid which must be one the values returned by lua_type. Use luaL_typename if you want to get it directly from a value in the stack.

Returns an unique identifier for the upvalue numbered n from the closure at index funcindex. Parameters funcindex and n are as in the lua_getupvalue (see lua_getupvalue) (but n cannot be greater than the number of upvalues). These unique identifiers allow a program to check whether different closures share upvalues. Lua closures that share an upvalue (that is, that access a same external local variable) will return identical ids for those upvalue indices.

Make the n1 upvalue of the Lua closure at index fidx1 refer to the n2 upvalue of the Lua closure at index fidx2.

Exchange values between different threads of the same global state. This function pops n values from the stack from, and pushes them onto the stack to.

Yields a coroutine. This function should only be called as the return expression of a C function, as follows:

Opens the standard library functions (like assert) for a lua state

Opens the standard ‘bit’ library for a lua state

Opens the standard ‘debug’ library for a lua state

Opens the standard ‘jit’ library for a lua state

Opens the standard ‘math’ library for a lua state

Opens the standard ‘os’ library for a lua state

Opens the standard ‘package’ library for a lua state

Opens the standard ‘string’ library for a lua state

Opens the standard ‘table’ library for a lua state

Functions

If a condition is false, throws an argument error at numarg

Asserts that a string argument exists at index ‘i’

Loads and pcalls a file’s lua code Returns if the code was successfully executed Error will be left on the stack if the code failed to execute

Loads and pcalls a string of lua code Returns if the code was successfully executed Error will be left on the stack if the code failed to execute

Returns value at crate::lua::REGISTRYINDEX with name ‘name’

Tries to see if the given value at index arg is nil or none, if so, returns default value. Otherwise, runs func, passing the lua state and arg indent and returns the value of that

Like lua_tostring or luaL_checkstring, but instead of returning an invalid string / erroring, It returns the given default string.

This function works like luaL_checkudata, except that, when the test fails, it returns None instead of throwing an error. Adapted from Lua 5.3, note this does not actually exist in gluajit

Returns the type name of object at index i

Gets a value from _G Internally calls lua_getfield with crate::lua::GLOBALSINDEX

Returns if the value at the given index is a boolean.

Returns if the value at the given index is a C or Lua function.

Returns if the value at the given index is nil. You might want to use lua_isnoneornil instead.

Returns if the value at the given index is none (element outside of stack / invalid)

Returns if the value at the given index is none (invalid) or nil.

Returns if the value at the given index is a table.

Returns if the value at the given index is a thread.

Creates a new empty table and pushes it onto the stack. It is equivalent to lua_createtable(l, 0, 0).

Pops n elements from the lua stack.

Pushes an angle onto the stack.

Pushes a “C” function to the stack

Pushes a vector onto the stack

Sets the C function f as the value of global name name.

Starts and resumes a coroutine in a given thread

Sets a value in _G Internally calls lua_setfield with crate::lua::GLOBALSINDEX

Equivalent to lua_tolstring with len equal to 0 This may return None if the value at idx is not a string or a number, use luaL_optstring instead if you do not desire an Option<> or unwrap when you are absolutely sure of the type.