KeraLua
Lua Hook Event Masks
Disabled hook
The call hook: is called when the interpreter calls a function. The hook is called just after Lua enters the new function, before the function gets its arguments.
The return hook: is called when the interpreter returns from a function. The hook is called just before Lua leaves the function. There is no standard way to access the values to be returned by the function.
The line hook: is called when the interpreter is about to start the execution of a new line of code, or when it jumps back in the code (even to the same line). (This event only happens while Lua is executing a Lua function.)
The count hook: is called after the interpreter executes every count instructions. (This event only happens while Lua is executing a Lua function.)
Type for C# callbacks
In order to communicate properly with Lua, a C function must use the following protocol, which defines the way parameters and results are passed: a C function receives its arguments from Lua in its stack in direct order (the first argument is pushed first). So, when the function starts, lua_gettop(L) returns the number of arguments received by the function. The first argument (if any) is at index 1 and its last argument is at index lua_gettop(L). To return values to Lua, a C function just pushes them onto the stack, in direct order (the first result is pushed first), and returns the number of results. Any other value in the stack below the results will be properly discarded by Lua. Like a Lua function, a C function called by Lua can also return many results.
Type for debugging hook functions callbacks.
Type for continuation functions
The reader function used by lua_load. Every time it needs another piece of the chunk, lua_load calls the reader, passing along its data parameter. The reader must return a pointer to a block of memory with a new piece of the chunk and set size to the block size
The type of the memory-allocation function used by Lua states. The allocator function must provide a functionality similar to realloc
Lua state class, main interface to use Lua library.
Internal Lua handle pointer.
Encoding for the string conversions
ASCII by default.
Returns a pointer to a raw memory area associated with the given Lua state. The application can use this area for any purpose; Lua does not use it for anything.
Each new thread has this area initialized with a copy of the area of the main thread.
Get the main thread object, if the object is the main thread will be equal this
Initialize Lua state, and open the default libs
flag to enable/disable opening the default libs
Initialize Lua state with allocator function and user data value
This method will NOT open the default libs.
Creates a new thread running in a new, independent state. Returns NULL if it cannot create the thread or 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 (see lua_Alloc). The second argument, ud, is an opaque pointer that Lua passes to the allocator in every call.
LuaAlloc allocator function called to alloc/free memory
opaque pointer passed to allocator
Get the Lua object from IntPtr
Useful for LuaFunction callbacks, if the Lua object was already collected will return null.
Finalizer, will dispose the lua state if wasn't closed
Dispose lua state
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
Dispose the lua context (calling Close)
Converts the acceptable index idx into an equivalent absolute index (that is, one that does not depend on the stack top).
Performs an arithmetic or bitwise operation over the two values (or one, in the case of negations) at the top of the stack, with the value at the top being the second operand, pops these values, and pushes the result of the operation. The function follows the semantics of the corresponding Lua operator (that is, it may call metamethods).
Sets a new panic function and returns the old one
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. Finally you call lua_call; nargs is the number of arguments that you pushed onto the stack.
All arguments and the function value are popped from the stack when the function is called. The function results are pushed onto the stack when the function returns.
The number of results is adjusted to nresults, unless nresults is LUA_MULTRET. In this case, all results from the function are pushed;
Lua takes care that the returned values fit into the stack space, but it does not ensure any extra space in the stack. The function results are pushed onto the stack in direct order (the first result is pushed first), so that after the call the last result is on the top of the stack.
This function behaves exactly like lua_call, but allows the called function to yield
Ensures that the stack has space for at least n extra slots (that is, that you can safely push up to n values into it). It returns false if it cannot fulfill the request,
Compares two Lua values. Returns 1 if the value at index index1 satisfies op when compared with the value at index index2
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 value on the stack (that is, the function does nothing);
Copies the element at index fromidx into the valid index toidx, replacing the value at that position
Creates a new empty table and pushes it onto the stack. Parameter narr is a hint for how many elements the table will have as a sequence; parameter nrec is a hint for how many other elements the table will have
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
Generates a Lua error, using the value at the top of the stack as the error object. This function does a long jump
Controls the garbage collector.
Returns the memory-allocation function of a given state. If ud is not NULL, Lua stores in *ud the opaque pointer given when the memory-allocator function was set.
Pushes onto the stack the value t[k], where t is the value at the given index. As in Lua, this function may trigger a metamethod for the "index" event (see §2.4).
Returns the type of the pushed value.
Pushes onto the stack the value t[k], where t is the value at the given index. As in Lua, this function may trigger a metamethod for the "index" event (see §2.4).
Returns the type of the pushed value.
Pushes onto the stack the value of the global name. Returns the type of that value
Pushes onto the stack the value t[i], where t is the value at the given index
Returns the type of the pushed value
Gets information about a specific function or function invocation.
This function returns false on error (for instance, an invalid option in what).
Gets information about a specific function or function invocation.
This function returns false on error (for instance, an invalid option in what).
Gets information about a local variable of a given activation record or a given function.
Gets information about a local variable of a given activation record or a given function.
If the value at the given index has a metatable, the function pushes that metatable onto the stack and returns 1
Gets information about the interpreter runtime stack.
Gets information about the interpreter runtime stack.
Pushes onto the stack the value t[k], where t is the value at the given index and k is the value at the top of the stack.
Returns the type of the pushed value
Pushes onto the stack the value t[k], where t is the value at the given index and k is the value at the top of the stack.
Returns the type of the pushed value
Returns the index of the top element in the stack. 0 means an empty stack.
Returns the index of the top element in the stack.
Pushes onto the stack the Lua value associated with the full userdata at the given index.
Returns the type of the pushed value.
Gets information about the n-th upvalue of the closure at index funcindex. It pushes the upvalue's value onto the stack and returns its name. Returns NULL (and pushes nothing) when the index n is greater than the number of upvalues.
For C functions, this function uses the empty string "" as a name for all upvalues. (For Lua functions, upvalues are the external local variables that the function uses, and that are consequently included in its closure.)
Upvalues have no particular order, as they are active through the whole function. They are numbered in an arbitrary order.
Returns the type of the pushed value.
Returns the current hook function.
Returns the current hook count.
Returns the current hook mask.
Moves the top element into the given valid index, shifting up the elements above this index to open space. This function cannot be called with a pseudo-index, because a pseudo-index is not an actual stack position.
Returns if the value at the given index is a boolean
Returns if the value at the given index is a C(#) function
Returns if the value at the given index is a function
Returns if the value at the given index is an integer
Returns if the value at the given index is light user data
Returns if the value at the given index is nil
Returns if the value at the given index is none
Check if the value at the index is none or nil
Returns if the value at the given index is a number
Returns if the value at the given index is a string or a number (which is always convertible to a string)
Returns if the value at the given index is a string
NOTE: This is different from the lua_isstring, which return true if the value is a number
Returns if the value at the given index is a table.
Returns if the value at the given index is a thread.
Returns if the value at the given index is a user data.
Returns if the given coroutine can yield, and 0 otherwise
Push the length of the value at the given index on the stack. It is equivalent to the '#' operator in Lua (see §3.4.7) and may trigger a metamethod for the "length" event (see §2.4). The result is pushed on the stack.
Loads a Lua chunk without running it. 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.
The lua_load function uses a user-supplied reader function to read the chunk (see lua_Reader). The data argument is an opaque value passed to the reader function.
Creates a new empty table and pushes it onto the stack
Creates a new thread, pushes it on the stack, and returns a pointer to a lua_State that represents this new thread. The new thread returned by this function shares with the original thread its global environment, but has an independent execution stack.
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. The host program can freely use this memory
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).
Calls a function in protected mode.
This function behaves exactly like lua_pcall, but allows the called function to yield
Pops n elements from the stack.
Pushes a boolean value with value b onto the stack.
Pushes a new C closure onto the stack. When a C function is created, it is possible to associate
some values with it, thus creating a C closure (see §4.4); these values are then accessible to the function
whenever it is called. To associate values with a C function, first these values must be pushed onto the
stack (when there are multiple values, the first value is pushed first).
Then lua_pushcclosure is called to create and push the C function onto the stack,
with the argument n telling how many values will be associated with the function.
lua_pushcclosure also pops these values from the stack.
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.
Pushes the global environment onto the stack.
Pushes an integer 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, a void*. 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 reference data (C# object) onto the stack.
This function uses lua_pushlightuserdata, but uses a GCHandle to store the reference inside the Lua side.
The CGHandle is create as Normal, and will be freed when the value is pop
Pushes binary buffer onto the stack (usually UTF encoded string) or any arbitraty binary data
Pushes a string onto the stack
Push a instring using string.Format
PushString("Foo {0}", 10);
Pushes a nil value onto the stack.
Pushes a double with value n onto the stack.
Pushes the thread represented by L onto the stack. Returns true if this thread is the main thread of its state.
Pushes a copy of the element at the given index onto the stack. (lua_pushvalue)
The method was renamed, since pushvalue is a bit vague
Returns true if the two values in indices index1 and index2 are primitively equal (that is, without calling the __eq metamethod). Otherwise returns false. Also returns false if any of the indices are not valid.
Similar to GetTable, but does a raw access (i.e., without metamethods).
Returns the type of the pushed value
Similar to GetTable, but does a raw access (i.e., without metamethods).
Returns the type of the pushed value
Pushes onto the stack the value t[n], where t is the table at the given index. The access is raw, that is, it does not invoke the __index metamethod.
Returns the type of the pushed value
Pushes onto the stack the value t[n], where t is the table at the given index. The access is raw, that is, it does not invoke the __index metamethod.
Pushes onto the stack the value t[k], where t is the table at the given index and k is the pointer p represented as a light userdata. The access is raw; that is, it does not invoke the __index metamethod.
Returns the type of the pushed value.
Returns the raw "length" of the value at the given index: for strings, this is the string length; for tables, this is the result of the length operator ('#') with no metamethods; for userdata, this is the size of the block of memory allocated for the userdata; for other values, it is 0.
Similar to lua_settable, but does a raw assignment (i.e., without metamethods).
Similar to lua_settable, but does a raw assignment (i.e., without metamethods).
Does the equivalent of t[i] = v, where t is the table at the given 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 the __newindex metamethod.
index of table
value
Does the equivalent of t[i] = v, where t is the table at the given 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 the __newindex metamethod.
Does the equivalent of t[p] = v, where t is the table at the given index, p is encoded as a light userdata, and v is the value at the top of the stack.
Sets the C# delegate f as the new value of global name
Removes the element at the given valid index, shifting down the elements above this index to fill the gap. This function cannot be called with a pseudo-index, because a pseudo-index is not an actual stack position.
Moves the top element into the given valid index without shifting any element (therefore replacing the value at that given index), and then pops the top element.
To start a coroutine, you push onto the thread stack the main function plus any arguments; then you call lua_resume,
with nargs being the number of arguments. This call returns when the coroutine suspends or finishes its execution.
When it returns, the stack contains all values passed to lua_yield, or all values returned by the body function.
lua_resume returns LUA_YIELD if the coroutine yields, LUA_OK if the coroutine finishes its execution without errors,
or an error code in case of errors (see lua_pcall).
In case of errors, the stack is not unwound, so you can use the debug API over it.
The error object is on the top of the stack.
To resume a coroutine, you remove any results from the last lua_yield, put on its stack only the values to be passed as results from yield,
and then call lua_resume.
The parameter from represents the coroutine that is resuming L.
If there is no such coroutine, this parameter can be NULL.
Rotates the stack elements between the valid index idx and the top of the stack. The elements are rotated n positions in the direction of the top, for a positive n, or -n positions in the direction of the bottom, for a negative n. The absolute value of n must not be greater than the size of the slice being rotated. This function cannot be called with a pseudo-index, because a pseudo-index is not an actual stack position.
Changes the allocator function of a given state to f with user data ud.
Does the equivalent to t[k] = v, where t is the value at the given index and v is the value at the top of the stack.
Sets the debugging hook function.
Argument f is the hook function. mask specifies on which events the hook will be called: it is formed by a bitwise OR of the constants
Hook function callback
hook mask
count (used only with LuaHookMas.Count)
Pops a value from the stack and sets it as the new value of global name.
Does the equivalent to t[n] = v, where t is the value at the given index and v is the value at the top of the stack.
Sets the value of a local variable of a given activation record. It assigns the value at the top of the stack to the variable and returns its name. It also pops the value from the stack.
Returns NULL (and pops nothing) when the index is greater than the number of active local variables.
Sets the value of a local variable of a given activation record. It assigns the value at the top of the stack to the variable and returns its name. It also pops the value from the stack.
Returns NULL (and pops nothing) when the index is greater than the number of active local variables.
Pops a table from the stack and sets it as the new metatable for the value at the given index.
Does the equivalent to t[k] = v, where t is the value at the given index, v is the value at the top of the stack, and k is the value just below the top
Accepts any 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. 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 NULL (and pops nothing) when the index n is greater than the number of upvalues.
Pops a value from the stack and sets it as the new value associated to the full userdata at the given index.
The status can be 0 (LUA_OK) for a normal thread, an error code if the thread finished the execution of a lua_resume with an error, or LUA_YIELD if the thread is suspended.
You can only call functions in threads with status LUA_OK. You can resume threads with status LUA_OK (to start a new coroutine) or LUA_YIELD (to resume a coroutine).
Converts the zero-terminated string s to a number, pushes that number into the stack,
Converts the Lua value at the given index to a C# boolean value
Converts a value at the given index to a C# function. That value must be a C# function; otherwise, returns NULL
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 (see §3.4.3); otherwise, lua_tointegerx returns 0.
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 (see §3.4.3); otherwise, lua_tointegerx returns 0.
Converts the Lua value at the given as byte array
Converts the Lua value at the given index to a byte array.
Calls __tostring field if present
Converts the Lua value at the given index to a C# string
Converts the Lua value at the given index to a C# string
Calls __tostring field if present
Converts the Lua value at the given index to a C# double
Converts the Lua value at the given index to a C# double?
Converts the value at the given index to a generic C pointer (void*). The value can 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.
Typically this function is used only for hashing and debug information.
Converts the value at the given index to a Lua thread
or return the self if is the main thread
Return an object (refence) at the index
Important if a object was push the object need to fetched using
this method, otherwise the C# object will never be collected
True to free the GCHandle
If the value at the given index is a full userdata, returns its block address. If the value is a light userdata, returns its pointer. Otherwise, returns NULL
Returns the name of the type of the value at the given index.
Name of the type of the value at the given index
Returns a unique identifier for the upvalue numbered n from the closure at index funcindex.
Returns the pseudo-index that represents the i-th upvalue of the running function
Make the n1-th upvalue of the Lua closure at index funcindex1 refer to the n2-th upvalue of the Lua closure at index funcindex2
Return the version of Lua (e.g 503)
Exchange values between different threads of the same state.
This function pops n values from the current stack, and pushes them onto the stack to.
This function is equivalent to lua_yieldk, but it has no continuation (see §4.7). Therefore, when the thread resumes, it continues the function that called the function calling lua_yield.
Yields a coroutine (thread). When a C function calls lua_yieldk, the running coroutine suspends its execution, and the call to lua_resume that started this coroutine returns
Number of values from the stack that will be passed as results to lua_resume.
Checks whether cond is true. If it is not, raises an error with a standard message
Raises an error reporting a problem with argument arg of the C function that called it, using a standard message that includes extramsg as a comment:
If the object at index obj has a metatable and this metatable has a field e, this function calls this field passing the object as its only argument.
If there is no metatable or no metamethod, this function returns false (without pushing any value on the stack)
Checks whether the function has an argument of any type (including nil) at position arg.
Checks whether the function argument arg is an integer (or can be converted to an integer)
Checks whether the function argument arg is a string and returns this string;
Checks whether the function argument arg is a string and returns this string;
Checks whether the function argument arg is a number and returns this number.
Checks whether the function argument arg is a string and searches for this string in the array lst
Grows the stack size to top + sz elements, raising an error if the stack cannot grow
Checks whether the function argument arg has type type
Checks whether the function argument arg is a userdata of the type tname
True to release the GCHandle
Checks whether the function argument arg is a userdata of the type tname (see luaL_newmetatable) and returns the userdata address
Loads and runs the given file
It returns false if there are no errors or true in case of errors.
Loads and runs the given string
It returns false if there are no errors or true in case of errors.
Raises an error. The error message format is given by fmt plus any extra arguments
This function produces the return values for process-related functions in the standard library
This function produces the return values for file-related functions in the standard library
Pushes onto the stack the field e from the metatable of the object at index obj and returns the type of the pushed value
Pushes onto the stack the metatable associated with name tname in the registry (see luaL_newmetatable) (nil if there is no metatable associated with that name)
Returns the type of the pushed value.
Ensures that the value t[fname], where t is the value at index idx, is a table, and pushes that table onto the stack. Returns true if it finds a previous table there and false if it creates a new table
Returns the "length" of the value at the given index as a number; it is equivalent to the '#' operator in Lua
Loads a buffer as a Lua chunk
Loads a buffer as a Lua chunk
Loads a string as a Lua chunk
Loads a string as a Lua chunk
Loads a file as a Lua chunk. This function uses lua_load to load the chunk in the file named filename
The status of operation
Loads a file as a Lua chunk.
Return the status
Creates a new table and registers there the functions in list library.
Creates a new table with a size optimized to store all entries in the array l (but does not actually store them)
Creates a new table to be used as a metatable for userdata
If the registry already has the key tname, returns false.,
Opens all standard Lua libraries into the given state.
If the function argument arg is an integer (or convertible to an integer), returns this integer. If this argument is absent or is nil, returns d
default value
If the function argument arg is a string, returns this string. If this argument is absent or is nil, returns d ///
If the function argument arg is a string, returns this string. If this argument is absent or is nil, returns d
If the function argument arg is a number, returns this number. If this argument is absent or is nil, returns d
Creates and returns a reference, in the table at index t, for the object at the top of the stack (and pops the object).
If modname is not already present in package.loaded, calls function openf with string modname as an argument and sets the call result in package.loaded[modname], as if that function has been called through require
Registers all functions in the array l (see luaL_Reg) into the table on the top of the stack (below optional upvalues, see next). ///
Sets the metatable of the object at the top of the stack as the metatable associated with name tname in the registry
Test if the value at index is a reference data
True to release the GCHandle of object
This function works like luaL_checkudata, except that, when the test fails, it returns NULL instead of raising an error.
Creates and pushes a traceback of the stack L1
Tells at which level to start the traceback
Creates and pushes a traceback of the stack L1
appended at the beginning of the traceback
Tells at which level to start the traceback
Returns the name of the type of the value at the given index.
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
Pushes onto the stack a string identifying the current position of the control at level lvl in the call stack
Used by Compare
compares for equality (==)
compares for less than
compares for less or equal
Structure for lua debug information
Do not change this struct because it must match the lua structure lua_Debug
Reinhard Ostermeier
Get a LuaDebug from IntPtr
Debug event code
a reasonable name for the given function. Because functions in Lua are first-class values, they do not have a fixed name: some functions can be the value of multiple global variables, while others can be stored only in a table field
explains the name field. The value of namewhat can be "global", "local", "method", "field", "upvalue", or "" (the empty string)
the string "Lua" if the function is a Lua function, "C" if it is a C function, "main" if it is the main part of a chunk
the name of the chunk that created the function. If source starts with a '@', it means that the function was defined in a file where the file name follows the '@'.
the current line where the given function is executing. When no line information is available, currentline is set to -1
the line number where the definition of the function ends.
number of upvalues
number of parameters
true if the function is a vararg function (always true for C functions).
true if this function invocation was called by a tail call. In this case, the caller of this level is not in the stack.
a "printable" version of source, to be used in error messages
Garbage Collector operations
Stops the garbage collector.
Restarts the garbage collector.
Performs a full garbage-collection cycle.
Returns the current amount of memory (in Kbytes) in use by Lua.
Returns the remainder of dividing the current amount of bytes of memory in use by Lua by 1024
Performs an incremental step of garbage collection.
Sets data as the new value for the pause of the collector (see §2.5) and returns the previous value
sets data as the new value for the step multiplier of the collector
returns a boolean that tells whether the collector is running
Whenever a hook is called, its ar argument has its field event set to the specific event that triggered the hook
The call hook: is called when the interpreter calls a function. The hook is called just after Lua enters the new function, before the function gets its arguments.
The return hook: is called when the interpreter returns from a function. The hook is called just before Lua leaves the function. There is no standard way to access the values to be returned by the function.
The line hook: is called when the interpreter is about to start the execution of a new line of code, or when it jumps back in the code (even to the same line). (This event only happens while Lua is executing a Lua function.)
The count hook: is called after the interpreter executes every count instructions. (This event only happens while Lua is executing a Lua function.)
Tail Call
Operation value used by Arith method
adition(+)
substraction (-)
Multiplication (*)
Modulo (%)
Exponentiation (^)
performs float division (/)
performs floor division (//)
performs bitwise AND
performs bitwise OR (|)
performs bitwise exclusive OR (~)
performs left shift
performs right shift
performs mathematical negation (unary -)
performs bitwise NOT (~)
LuaRegister store the name and the delegate to register a native function
Function name
Function delegate
Enum for pseudo-index used by registry table
pseudo-index used by registry table
Registry index
At this index the registry has the main thread of the state.
At this index the registry has the global environment.
Lua Load/Call status return
success
Yield
a runtime error.
syntax error during precompilation
memory allocation error. For such errors, Lua does not call the message handler.
error while running a __gc metamethod. For such errors, Lua does not call the message handler
error while running the message handler.
Lua types
LUA_TNIL
LUA_TBOOLEAN
LUA_TLIGHTUSERDATA
LUA_TNUMBER
LUA_TSTRING
LUA_TTABLE
LUA_TFUNCTION
LUA_TUSERDATA
LUA_TTHREAD
//