Luajit::LuaState
Constructors
Class methods
Instance methods
Raises LuaError unless the value at index is a light userdata
Raises LuaError unless the value at index is a string with size
Raises LuaError unless the value at index is type
https://www.lua.org/manual/5.1/manual.html#lua_atpanic
Attaches a metatable to value at index with name tname if
a metatable exists, otherwise returns false
Raises LuaError if operation fails
Calls the C function block in protected mode
All values returned by block are discarded.
NOTE: Adopted from Lua 5.3, because LuaJIT's version has some inconsistencies when dealing with error handling that made it hard to work with.
Calls a metamethod
If object at index obj has a metatable with field event, this
method calls this field and passes the object as its only argument.
In this case, returns true and pushes onto the stack the value
returned by the call. Otherwise, returns false and pushes nothing
onto the stack.
Checks whether the value at index is a userdata of type tname and returns it
Raises LuaError unless tname matches
Starts and resumes a coroutine in a given thread
https://www.lua.org/manual/5.1/manual.html#lua_resume
Yields a coroutine
https://www.lua.org/manual/5.1/manual.html#lua_yield
Concatenates the n values at the top of the stack, pops them, and leaves the result at the top
If n == 1, does nothing
If n == 0, pushes empty string
Raises LuaError if operation fails
Creates a LuaRef for object at top of stack
Raises LuaError if value at top of stack is nil
Raises LuaError if ref cannot be created
Creates a new empty table and pushes it onto the stack
narr represents pre-allocated array elements
nrec represents pre-allocated non-array elements
Pre-allocation is useful when you know exactly how many elements the table will have.
Creates a full userdata with a type tname, and returns a pointer with the address of ptr
See #get_userdata
Returns true if the two values in indices index1 and index2 are equal
Follows the semantics of the Lua == operator (i.e. may call metamethods)
Raises LuaError if operation fails
Pushes onto the stack the value of the environment name
Raises LuaError if operation fails
Pushes onto the stack the environment table of the value at index
Pushes onto the stack the value t[k], where t is the value at index, and k is the name of the field
As in Lua, this function may trigger a metamethod for the "index" event.
Raises LuaError if operation fails
Pushes onto the stack the value of the global name
Raises LuaError if operation fails
Returns information about a specific function or function invocation
https://www.lua.org/manual/5.1/manual.html#lua_getinfo
Gets information about a local variable of ar
https://www.lua.org/manual/5.1/manual.html#lua_getlocal
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 false and pushes nothing.
Pushes onto the stack the metatable associated with tname in the registry
Raises LuaError if operation fails
See #new_metatable
Pushes onto the stack the metatable of the value at index
If index is not valid, or value does not have a metatable,
returns false.
Pushes onto the stack the value of the registry name
Raises LuaError if operation fails
Get information about the interpreter runtime stack
https://www.lua.org/manual/5.1/manual.html#lua_getstack
Pushes onto the stack the value t[k], where t is the value at index, and k is the value at the top of the stack
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
Raises LuaError if operation fails
Gets information about a closure's upvalue
https://www.lua.org/manual/5.1/manual.html#lua_getupvalue
Retrieves a full userdata at index with name tname and returns it
NOTE: Can only be used if the userdata was originally created from
#create_userdata.
Raises LuaError if operation fails
Moves the top element into index, shifting elements above to open space
WARNING: Cannot be called with a pseudo-index, because a pseudo-index is not an actual stack position.
Returns true if value at the given index is a function (either C or Lua)
Returns true if value at the given index is a light userdata
Returns true if value at the given index is not valid (refers to an element outside the current stack)
Returns true if value at the given index is not valid (refers to an element outside the current stack) or is nil
Returns true if value at the given index is a number or a string convertible to a number
Returns true if value at the given index is a string or a number (which is always convertible to a string)
Returns true if value at the given index is a userdata (either full or light)
Returns true if the value at index1 is smaller than the value at index2
Follows the semantics of the Lua < operator (i.e. may call metamethods)
Raises LuaError if operation fails
Creates a new table to be used as a metatable for userdata,
adds it to the registry with key tname, and returns true
If the registry already has the key tname, returns false.
In both cases pushes onto the stack the final value associated with tname in the registry.
Creates a new thread, represented as a new LuaState, and pushes it
onto the stack
Shares all global objects (such as tables), but has independent stack.
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.
Userdata represent C values in Lua. A full userdata represents a block of memory. It is an object (like a table): you must create it, it can have its own metatable, and you can detect when it is being collected. A full userdata is only equal to itself (under raw equality).
When Lua collects a full userdata with a gc metamethod, Lua calls the metamethod and marks the userdata as finalized. When this userdata is collected again then Lua frees its corresponding memory.
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.
Userdata represent C values in Lua. A full userdata represents a block of memory. It is an object (like a table): you must create it, it can have its own metatable, and you can detect when it is being collected. A full userdata is only equal to itself (under raw equality).
When Lua collects a full userdata with a gc metamethod, Lua calls the metamethod and marks the userdata as finalized. When this userdata is collected again then Lua frees its corresponding memory.
Pops a key from the stack, and pushes a key-value pair from the table at index (the "next" pair after the given key).
If there are no more elements in the table, then returns false (and pushes nothing).
While traversing a table, do not call #to_string directly on a key,
unless you know that the key is actually a string. Recall that
#to_string changes the value at the given index; this confuses
the next call to #next.
Raises LuaError if operation fails
A typical traversal looks like this:
# table is in the stack at index 't'
state.push(nil)
while state.next(t)
# uses 'key' (at index -2) and 'value' (at index -1)
puts "#{state.type_name_at(-2)} - #{state.type_name_at(-1)}"
# removes 'value'; keeps 'key' for next iteration
state.pop(1)
end
Calls a function in protected mode
https://www.lua.org/manual/5.1/manual.html#lua_pcall
Same as #pcall, but yields LuaStatus on failure
Pushes a light userdata onto the stack
A light userdata is equivalent to a Pointer
Pushes thread represented by x onto the stack, returns ThreadStatus
Raises LuaError at pos with expected type
Returns true if the two values in indices index1 and index2 are primitively equal
Does not call metamethods
Similar to #get_table, but does a raw access (i.e., without metamethods)
Pushes onto the stack the value t[n], where t is the value at index, and n is an array-like index
The access is raw; that is, it does not invoke metamethods.
Similar to #set_table, but does a raw assignment (i.e., without metamethods)
Does the equivalent of t[n] = v, where t is the value at index, v is the value at the top of the stack, and n is an array-like index
Pops the value from the stack.
The assignment is raw; that is, it does not invoke metamethods.
Opens a library with name and registers all functions in regs
Registers all functions in regs to table at the top of the stack
Registers a named function to table at the top of the stack
Raises LuaError if operation fails
Registers a global function
Raises LuaError if operation fails
Removes the element at index, shifting down elements above to fill gap
WARNING: Cannot be called with a pseudo-index, because a pseudo-index is not an actual stack position.
Moves the top element into the given position (and pops it), without shifting any element (therefore replacing the value at the given position)
Pops a value from the stack and sets it as the new value of environment name
Raises LuaError if operation fails
Pops a table from the stack and sets it as the new environment for the value at index
If the value at index is neither a function, nor a thread, nor a userdata, returns 0. Otherwise returns 1.
Does the equivalent to t[k] = v, where t is the value at index, k is the key, and v is the value at top of stack.
Pops the value from the stack.
Raises LuaError if operation fails
Pops a value from the stack and sets it as the new value of global name
Raises LuaError if operation fails
Sets the debugging hook function
https://www.lua.org/manual/5.1/manual.html#lua_sethook
Sets the value of a local variable of ar
https://www.lua.org/manual/5.1/manual.html#lua_setlocal
Pops a table from the stack and sets it as the new metatable for the value at index
Pops a value from the stack and sets it as the new value of registry name
Raises LuaError if operation fails
Does the equivalent to t[k] = v, where t is the value at index, v is the value at top of stack, and k the value just behind v
Pops both key and value from the stack.
Raises LuaError if operation fails
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
https://www.lua.org/manual/5.1/manual.html#lua_setupvalue
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).
Returns the "length" of the value at 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.
Converts value at index to LuaAny, otherwise returns nil
Converts the Lua value at index to Bool
Returns true for any Lua value different than false or nil
Returns false when called with a non-valid index
Same as #to_c_function?, but assumes value is not nil
Converts a value at index to a C function, otherwise returns nil
Converts the Lua value at index to Float64
The value must be a number or a string convertible to a number, otherwise returns 0
Converts the Lua value at index to Float64
The value must be a number or a string convertible to a number, otherwise returns 0
Converts the Lua value at index to Int64
The value must be a number or a string convertible to a number, otherwise returns 0
If the number is not an integer, it is truncated in some non-specific way
Converts the value at index to a Pointer
The value can be a userdata, a table, a thread, or a function; otherwise, returns nil.
Different objects will give different pointers. There is no way to convert the pointer back to its original value.
Converts the Lua value at index to a C string
The Lua value must be a string or a number, otherwise returns "".
If the value is a number, it also changes the actual value in the stack to a string.
Converts the Lua value at index to a C string
The Lua value must be a string or a number, otherwise returns "".
If the value is a number, it also changes the actual value in the stack to a string.
Converts the value at index to a Lua thread, otherwise returns nil
Same as #to_userdata?, but assumes value is not nil
If the value at index is a full userdata, returns its block address
If the value is a light userdata, returns its pointer
Otherwise returns nil
Returns the name of the type of the value at the given index