A Lua operation.
This type is suitable for most users. It uses a default exception for error handling. Users who need more control over error handling can use LuaE with a custom error type instead.
:: a typeCtrl KGHC 9.10.3 · lts/ghc-9.10.x · 248f8f0 · 2026-10-05
Modulehslua-2.3.1Haskell2010
Functions and utilities enabling the seamless integration of a Lua interpreter into a Haskell project.
This module combines and re-exports the functionality of the HsLua
framework. Basic access to the Lua API is provided by from
Hackage package lua.Lua.Core
A Lua operation.
This type is suitable for most users. It uses a default exception for error handling. Users who need more control over error handling can use LuaE with a custom error type instead.
A Lua computation. This is the base type used to run Lua programs
of any kind. The Lua state is handled automatically, but can be
retrieved via state.
LuaunLua :: ReaderT LuaEnvironment IO aMonadReader LuaEnvironment (LuaE e)Defined in hslua-core-2.3.2 · HsLua.Core.Types(LuaError e, Pushable a) => Exposable e (LuaE e a)Defined in hslua-classes-2.3.1 · HsLua.Class.ExposableMonad (LuaE e)Defined in hslua-core-2.3.2 · HsLua.Core.TypesFunctor (LuaE e)Defined in hslua-core-2.3.2 · HsLua.Core.TypesLuaError e => MonadFail (LuaE e)Defined in hslua-core-2.3.2 · HsLua.Core.Error · orphanApplicative (LuaE e)Defined in hslua-core-2.3.2 · HsLua.Core.TypesLuaError e => Alternative (LuaE e)Defined in hslua-core-2.3.2 · HsLua.Core.Error · orphanMonadIO (LuaE e)Defined in hslua-core-2.3.2 · HsLua.Core.TypesMonadCatch (LuaE e)Defined in hslua-core-2.3.2 · HsLua.Core.TypesMonadMask (LuaE e)Defined in hslua-core-2.3.2 · HsLua.Core.TypesMonadThrow (LuaE e)Defined in hslua-core-2.3.2 · HsLua.Core.Types(LuaError e, Peekable a) => Invokable (LuaE e a)Defined in hslua-classes-2.3.1 · HsLua.Class.InvokableCompares two Lua values. Returns True if the value at index
idx1 satisfies op when compared with the value at index idx2,
following the semantics of the corresponding Lua operator (that is,
it may call metamethods). Otherwise returns False. Also returns
False if any of the indices is not valid.
The value of op must be of type RelationalOperator:
EQ: compares for equality (==) LT: compares for less than (<) LE: compares for less or equal (<=)
Wraps hslua_compare. See also lua_compare.
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); if n is 0,
the result is the empty string. Concatenation is performed following
the usual semantics of Lua (see
§3.4.6 of the Lua
manual).
Wraps hslua_concat. See also lua_concat.
Any type that you wish to use for error handling in HsLua must be
an instance of the LuaError class.
popException :: LuaE e eConverts the error at the top of the stack into an exception and pops the error off the stack.
This function is expected to produce a valid result for any Lua value; neither a Haskell exception nor a Lua error may result when this is called.
pushException :: e -> LuaE e ()Pushes an exception to the top of the Lua stack. The pushed Lua
object is used as an error object, and it is recommended that
calling tostring() on the object produces an informative message.
luaException :: String -> eCreates a new exception with the given message.
Name of a function, table field, or chunk; the name must be valid UTF-8 and may not contain any nul characters.
Implementation note: this is a newtype instead of a simple type
Name = ByteString alias so we can define a UTF-8 based IsString
instance. Non-ASCII users would have a bad time otherwise.
Pushes onto the stack the value t[k], where t is the value at
the given stack index. As in Lua, this function may trigger a
metamethod for the "index" event (see
§2.4 of Lua's
manual).
Errors on the Lua side are propagated.
See also lua_getfield.
Pushes onto the stack the value of the global name.
Errors on the Lua side are propagated.
Wraps hslua_getglobal.
Alias for nthTop.
Pops n elements from the stack.
See also: lua_pop.
Pushes a copy of the element at the given index onto the stack.
Wraps lua_pushvalue.
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.
Wraps lua_remove.
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.
This function pops the value from the stack. As in Lua, this function may trigger a metamethod for the "newindex" event (see §2.4 of the Lua 5.4 Reference Manual).
Errors on the Lua side are caught and rethrown as a Exception.
See also: lua_setfield.
Pops a value from the stack and sets it as the new value of global
name.
Errors on the Lua side are caught and rethrown as Exception.
Wraps hslua_setglobal. See also: lua_setglobal.
Index of the topmost stack element.
Signals to Lua that an error has occurred and that the error object is at the top of the stack.
Lua comparison operations.
Eq RelationalOperatorDefined in hslua-core-2.3.2 · HsLua.Core.TypesOrd RelationalOperatorDefined in hslua-core-2.3.2 · HsLua.Core.TypesShow RelationalOperatorDefined in hslua-core-2.3.2 · HsLua.Core.TypesThe type of integers in Lua.
By default this type is Int64, but that can be changed to
different values in Lua. (See LUA_INT_TYPE in luaconf.h.)
See lua_Integer.
Bounded IntegerDefined in lua-2.3.2 · Lua.TypesEnum IntegerDefined in lua-2.3.2 · Lua.TypesEq IntegerDefined in lua-2.3.2 · Lua.TypesIntegral IntegerDefined in lua-2.3.2 · Lua.TypesNum IntegerDefined in lua-2.3.2 · Lua.TypesOrd IntegerDefined in lua-2.3.2 · Lua.TypesRead IntegerDefined in lua-2.3.2 · Lua.TypesReal IntegerDefined in lua-2.3.2 · Lua.TypesShow IntegerDefined in lua-2.3.2 · Lua.TypesPeekable IntegerDefined in hslua-classes-2.3.1 · HsLua.Class.PeekablePushable IntegerDefined in hslua-classes-2.3.1 · HsLua.Class.PushableEnumeration used as type tag. See lua_type.
TypeNonenon-valid stack index
TypeNiltype of Lua's nil value
TypeBooleantype of Lua booleans
TypeLightUserdatatype of light userdata
TypeNumbertype of Lua numbers. See Lua.Number
TypeStringtype of Lua string values
TypeTabletype of Lua tables
TypeFunctiontype of functions, either normal or CFunction
TypeUserdatatype of full user data
TypeThreadtype of Lua threads
Bounded TypeDefined in hslua-core-2.3.2 · HsLua.Core.TypesEnum TypeDefined in hslua-core-2.3.2 · HsLua.Core.TypesEq TypeDefined in hslua-core-2.3.2 · HsLua.Core.TypesOrd TypeDefined in hslua-core-2.3.2 · HsLua.Core.TypesRead TypeDefined in hslua-core-2.3.2 · HsLua.Core.TypesShow TypeDefined in hslua-core-2.3.2 · HsLua.Core.TypesMoves 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.
Wraps lua_insert.
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 (or the empty string for no additional text).
Loads and runs the given file. Note that the filepath is interpreted by Lua, not Haskell. The resulting chunk is named using the UTF8 encoded filepath.
Loads and runs the given string.
Returns OK on success, or an error if either loading of the string or calling of the thunk failed.
Pushes onto the stack the field e from the metatable of the
object at index obj and returns the type of the pushed value. If
the object does not have a metatable, or if the metatable does not
have this field, pushes nothing and returns TypeNil.
Wraps luaL_getmetafield.
Pushes onto the stack the metatable associated with name tname in
the registry (see newmetatable) (nil if there is no metatable
associated with that name). Returns the type of the pushed value.
Wraps luaL_getmetatable.
Push referenced value from the table at the given index.
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.
Loads a ByteString as a Lua chunk.
This function returns the same results as load. name is the
chunk name, used for debug information and error messages. Note that
name is used as a C string, so it may not contain null-bytes.
Wraps luaL_loadbuffer.
Key to the registry field that holds the table of loaded modules.
Loads a file as a Lua chunk. This function uses lua_load (see
load) to load the chunk in the file named filename. If
filename is Nothing, then it loads from the standard input. The
first line in the file is ignored if it starts with a #.
The string mode works as in function load.
This function returns the same results as load, but it has an
extra error code ErrFile for file-related errors (e.g., it
cannot open or read the file).
As load, this function only loads the chunk; it does not run
it.
See luaL_loadfile.
Loads a string as a Lua chunk. This function uses lua_load to
load the chunk in the given ByteString. The given string may not
contain any NUL characters.
This function returns the same results as lua_load (see
load).
Also as load, this function only loads the chunk; it does not
run it.
See luaL_loadstring.
If the registry already has the key tname, returns False.
Otherwise, creates a new table to be used as a metatable for
userdata, adds to this new table the pair __name = tname, adds to
the registry the pair [tname] = new table, and returns True. (The
entry __name is used by some error-reporting functions.)
In both cases pushes onto the stack the final value associated with
tname in the registry.
The value of tname is used as a C string and hence must not contain
null bytes.
Wraps luaL_newmetatable.
Creates a new Lua state. It calls lua_newstate with an allocator
based on the standard C realloc function and then sets a panic
function (see §4.4
of the Lua 5.4 Reference Manual) that prints an error message to the
standard error output in case of fatal errors.
Wraps hsluaL_newstate. See also: luaL_newstate.
Key to the registry field that holds the table of loader functions.
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, ref ensures the uniqueness of the
key it returns. You can retrieve an object referred by reference r
by calling rawgeti t r. Function unref frees a reference and
its associated object.
If the object at the top of the stack is nil, ref returns the
constant refnil. The constant noref is guaranteed to
be different from any reference returned by ref.
Wraps luaL_ref.
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.
If glb is true, also stores the module into global modname.
Leaves a copy of the module on the stack.
See requirehs for a version intended to be used with Haskell
actions.
Converts any Lua value at the given index to a ByteString in a reasonable format. The resulting string is pushed onto the stack and also returned by the function.
If the value has a metatable with a __tostring field, then
tolstring' calls the corresponding metamethod with the value as
argument, and uses the result of the call as its result.
Wraps hsluaL_tolstring.
Creates and pushes a traceback of the stack L1. If a message is given it is appended at the beginning of the traceback. The level parameter tells at which level to start the traceback.
Wraps luaL_traceback.
Releases reference ref from the table at index idx (see
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.
Wraps luaL_unref. See also: luaL_unref.
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:
chunkname:currentline:Level 0 is the running function, level 1 is the function that called the running function, etc.
This function is used to build a prefix for error messages.
Pushes Haskell function as a callable userdata. All values created will be garbage collected. The function should behave similar to a CFunction.
Error conditions should be indicated by raising a catchable exception
or by returning the result of .Lua.error
Example:
mod23 :: Lua NumResults
mod23 = do
mn <- tointeger (nthBottom 1)
case mn of
Nothing -> pushstring "expected an integer" *> error
Just n -> pushinteger (n `mod` 23)
pushHaskellFunction mod23
setglobal "mod23"Converts a pre C function to a Lua function and pushes it to the stack.
Pre C functions collect parameters from the stack and return a CInt
that represents number of return values left on the stack.
See CFunction for more info.
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 Nothing (and pushes nothing) when the index n
is greater than the number of upvalues.
See debug.getupvalue for more information about upvalues.
[0, +(0|1), -]Wraps lua_getupvalue.
Sets the value of a closure’s upvalue. It assigns the value on the top of the stack to the upvalue and returns its name. It also pops the value from the stack.
Returns Nothing (and pops nothing) when the index n is greater
than the number of upvalues.
Parameters funcindex and n are as in the function getupvalue.
[-(0|1), +0, -]Wraps lua_setupvalue.
Default Lua error type. Exceptions raised by Lua-related operations.
Change the error type of a computation.
Raises an exception in the Lua monad.
Retrieve and pop the top object as an error message. This is very similar to tostring', but ensures that we don't recurse if getting the message failed.
This helpful as a "last resort" method when implementing popException.
pushTypeMismatchError :: ByteStringname or description of expected type
-> StackIndexstack index of mismatching object
-> LuaE e ()Creates an error to notify about a Lua type mismatch and pushes it to the stack.
Converts a Lua error at the top of the stack into a Haskell exception and throws it.
Raises an exception that's appropriate when the type of a Lua object at the given index did not match the expected type. The name or description of the expected type is taken as an argument.
Return either the result of a Lua computation or, if an exception was thrown, the error.
Registers a preloading function. Takes an module name and the Lua operation which produces the package.
Load a module, defined by a Haskell action, under the given name.
Similar to luaL_requiref: 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.
Leaves a copy of the module on the stack.
Converts the acceptable index idx into an equivalent absolute
index (that is, one that does not depend on the stack top).
Wraps lua_absindex.
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 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 multret. In this case, all results from the
function are pushed. Lua takes care that the returned values fit into
the stack space. 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.
Any error inside the called function is propagated as exception of
type e.
The following example shows how the host program can do the equivalent to this Lua code:
a = f("how", t.x, 14)Here it is in Haskell (assuming the OverloadedStrings language extension):
getglobal "f" -- function to be called
pushstring "how" -- 1st argument
getglobal "t" -- table to be indexed
getfield (-1) "x" -- push result of t.x (2nd arg)
remove (-2) -- remove 't' from the stack
pushinteger 14 -- 3rd argument
call 3 1 -- call 'f' with 3 arguments and 1 result
setglobal "a" -- set global 'a'Note that the code above is "balanced": at its end, the stack is back to its original configuration. This is considered good programming practice.
See lua_call.
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, either because it would cause
the stack to be larger than a fixed maximum size (typically at least
several thousand elements) or because it cannot allocate memory for
the extra space. This function never shrinks the stack; if the stack
already has space for the extra slots, it is left unchanged.
Wraps lua_checkstack.
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 that create multiple states, such as daemons or web servers, will probably need to close states as soon as they are not needed.
Same as lua_close.
Copies the element at index fromidx into the valid index toidx,
replacing the value at that position. Values at other positions are
not affected.
Wraps lua_copy.
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. Lua may use these hints to preallocate memory for the new table. This preallocation is useful for performance when you know in advance how many elements the table will have. Otherwise you can use the function lua_newtable.
Wraps lua_createtable.
Returns True 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 False. Also
returns False if any of the indices is non valid. Uses compare
internally.
Pushes onto the stack the n-th user value associated with the
full userdata at the given index and returns the type of the pushed
value.
If the userdata does not have that value, pushes nil and returns LUA_TNONE.
Wraps lua_getiuservalue.
If the value at the given index has a metatable, the function
pushes that metatable onto the stack and returns True. Otherwise,
the function returns False and pushes nothing on the stack.
Wraps lua_getmetatable.
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.
This function pops the key from the stack, pushing the resulting value in its place. As in Lua, this function may trigger a metamethod for the "index" event (see §2.4 of Lua's manual).
Errors on the Lua side are caught and rethrown.
Wraps hslua_gettable. See also: lua_gettable.
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).
Wraps lua_gettop.
Returns True if the value at the given index is a boolean, and False otherwise.
Wraps lua_isboolean.
Returns True if the value at the given index is a C function, and False otherwise.
Wraps lua_iscfunction.
Returns True if the value at the given index is a function (either C or Lua), and False otherwise.
Wraps lua_isfunction.
Returns True if the value at the given index is an integer (that
is, the value is a number and is represented as an integer), and
False otherwise.
Wraps lua_isinteger.
Returns True if the value at the given index is a light userdata,
and False otherwise.
Wraps lua_islightuserdata.
Returns True if the given index is not valid, and False otherwise.
Wraps lua_isnone.
Returns True if the given index is not valid or if the value at the given index is *nil*, and False otherwise.
Wraps lua_isnoneornil.
Returns True if the value at the given index is a number or a string convertible to a number, and False otherwise.
Wraps lua_isnumber.
Returns True if the value at the given index is a string or a number (which is always convertible to a string), and False otherwise.
Wraps lua_isstring.
Returns True if the value at the given index is a table, and False otherwise.
Wraps lua_istable.
Returns True if the value at the given index is a thread, and False otherwise.
Wraps lua_isthread.
Returns True if the value at the given index is a userdata (either full or light), and False otherwise.
Wraps lua_isuserdata.
Tests whether the object under the first index is smaller than that
under the second. Uses compare internally.
Loads a Lua chunk (without running it). If there are no errors,
load pushes the compiled chunk as a Lua function on top of the
stack. Otherwise, it pushes an error message.
The return values of load are:
OK: no errors;
ErrSyntax: syntax error during pre-compilation;
ErrMem: memory allocation error;
: error while running a ErrGcmm__gc metamethod. (This error
has no relation with the chunk being loaded. It is generated by the
garbage collector.)
This function only loads a chunk; it does not run it.
load automatically detects whether the chunk is text or binary, and
loads it accordingly (see program luac).
The load function uses a user-supplied reader function to read
the chunk (see Reader). The data argument is an opaque value
passed to the reader function.
The chunkname argument gives a name to the chunk, which is used for
error messages and in debug information (see
§4.7). Note that the
chunkname is used as a C string, so it may not contain null-bytes.
This is a wrapper of lua_load.
Creates a new empty table and pushes it onto the stack. It is
equivalent to createtable 0 0.
See also: lua_newtable.
This function creates and pushes on the stack a new full userdata,
with nuvalue associated Lua values, called user values, plus an
associated block of raw memory with size bytes. (The user values
can be set and read with the functions lua_setiuservalue and
lua_getiuservalue.)
The function returns the address of the block of memory. Lua ensures that this address is valid as long as the corresponding userdata is alive (see §2.5). Moreover, if the userdata is marked for finalization (see §2.5.3), its address is valid at least until the call to its finalizer.
This function wraps lua_newuserdatauv.
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 next returns False
(and pushes nothing).
Errors on the Lua side are caught and rethrown as a Exception.
This function wraps hslua_next. See also: lua_next.
Pushes Lua's base library onto the stack.
This function pushes and and calls luaopen_base.
Pushes Lua's debug library onto the stack.
This function pushes and and calls luaopen_io.
Pushes Lua's io library onto the stack.
This function pushes and and calls luaopen_io.
Opens all standard Lua libraries into the current state and sets each library name as a global value.
This function wraps luaL_openlibs.
Pushes Lua's math library onto the stack.
This function pushes and and calls luaopen_math.
Pushes Lua's os library onto the stack.
This function pushes and and calls luaopen_os.
Pushes Lua's package library onto the stack.
This function pushes and and calls luaopen_package.
Pushes Lua's string library onto the stack.
This function pushes and and calls luaopen_string.
Pushes Lua's table library onto the stack.
This function pushes and and calls luaopen_table.
Calls a function in protected mode.
Both nargs and nresults have the same meaning as in call. If
there are no errors during the call, pcall behaves exactly like
call. However, if there is any error, pcall catches it, pushes
a single value on the stack (the error message), and returns the
error code. Like call, pcall always removes the function and
its arguments from the stack.
If msgh is Nothing, then the error object returned on the stack
is exactly the original error object. Otherwise, when msgh is Just
idx, the stack index idx is the location of a message handler.
(This index cannot be a pseudo-index.) In case of runtime errors,
this function will be called with the error object and its return
value will be the object returned on the stack by pcall.
Typically, the message handler is used to add more debug information
to the error object, such as a stack traceback. Such information
cannot be gathered after the return of pcall, since by then the
stack has unwound.
This function wraps lua_pcall.
Pushes a boolean value with the given value onto the stack.
This functions wraps lua_pushboolean.
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
§3.4); these values
are then accessible to the function whenever it is called. To
associate values with a C function, first these values should be
pushed onto the stack (when there are multiple values, the first
value is pushed first). Then pushcclosure is called to create and
push the C function onto the stack, with the argument n telling how
many values should be associated with the function. pushcclosure also
pops these values from the stack.
The maximum value for n is 255.
Wraps lua_pushcclosure.
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.
Any function to be callable by Lua must follow the correct protocol
to receive its parameters and return its results (see CFunction)
Same as flip pushcclosure 0.
lua_pushcfunction.
Pushes the global environment onto the stack.
Wraps lua_pushglobaltable.
Pushes an integer with with the given value onto the stack.
Wraps lua_pushinteger.
Pushes a light userdata onto the stack.
Userdata represent C values in Lua. A light userdata represents a
pointer, a Ptr a (i.e., void* in C). 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.
Wraps lua_pushlightuserdata.
Pushes a nil value onto the stack.
Wraps lua_pushnil.
Pushes a float with the given value onto the stack.
Wraps lua_pushnumber.
Pushes the 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.
Wraps lua_pushlstring.
Pushes the current thread onto the stack. Returns True if this thread is
the main thread of its state, False otherwise.
Wraps lua_pushthread.
Returns True if the two values in indices idx1 and idx2 are
primitively equal (that is, without calling the __eq metamethod).
Otherwise returns False. Also returns False if any of the indices
are not valid.
Wraps lua_rawequal.
Similar to gettable, but does a raw access (i.e., without
metamethods).
Wraps lua_rawget.
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.
Wraps lua_rawgeti.
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.
Wraps lua_rawlen.
Similar to settable, but does a raw assignment (i.e., without
metamethods).
Wraps lua_rawset.
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.
Wraps lua_rawseti.
Sets the C function f as the new value of global name.
Behaves like "lua_register".
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.
Wraps lua_replace.
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.
Pops a value from the stack and sets it as the new n-th user
value associated to the full userdata at the given index. Returns 0
if the userdata does not have that value.
Wraps lua_setiuservalue.
Pops a table from the stack and sets it as the new metatable for the value at the given index.
Wraps lua_setmetatable.
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.
This function pops both the key and the value from the stack. As in Lua, this function may trigger a metamethod for the "newindex" event (see §2.4 of the Lua 5.4 Reference Manual).
Errors on the Lua side are caught and rethrown.
Wraps hslua_settable.
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.
Wraps lua_settop.
Sets the warning function to be used by Lua to emit warnings (see
WarnFunction). The ud parameter sets the value ud passed to the
warning function.
Returns the status of this Lua thread.
The status can be OK for a normal thread, an error value if the
thread finished the execution of a lua_resume with an error, or
Yield if the thread is suspended.
You can only call functions in threads with status OK. You can resume threads with status OK (to start a new coroutine) or Yield (to resume a coroutine).
Wraps lua_status.
Converts the Lua value at the given index to a haskell boolean
value. Like all tests in Lua, toboolean returns True for any Lua
value different from false and nil; otherwise it returns False.
(If you want to accept only actual boolean values, use isboolean
to test the value's type.)
Wraps lua_toboolean.
Converts a value at the given index to a C function. That value
must be a C function; otherwise, returns Nothing.
Wraps lua_tocfunction.
Converts the Lua value at the given acceptable index to the signed
integral type Integer. The Lua value must be an integer, a
number or a string convertible to an integer (see
§3.4.3 of the Lua
5.4 Reference Manual); otherwise, tointeger returns Nothing.
If the number is not an integer, it is truncated in some non-specified way.
Wraps lua_tointegerx. See also: lua_tointeger.
Converts the Lua value at the given index to a Number. The
Lua value must be a number or a string convertible to a number;
otherwise, tonumber returns Nothing.
Wraps lua_tonumberx. See also lua_tonumber.
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 nullPtr. 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.
Wraps lua_topointer.
Converts the Lua value at the given index to a ByteString. The Lua value must be a string or a number; otherwise, the function returns Nothing. If the value is a number, then tostring also changes the actual value in the stack to a string. (This change confuses next when tostring is applied to keys during a table traversal.)
Wraps lua_tolstring.
Converts the value at the given index to a Lua thread (represented
as State). This value must be a thread; otherwise, the function
returns Nothing.
Wraps lua_tothread.
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 Nothing..
Wraps lua_touserdata.
Returns the name of the type encoded by the value tp, which must
be one the values returned by ltype.
Wraps lua_typename.
Returns the pseudo-index that represents the i-th upvalue of the
running function (see <https://www.lua.org/manual/5.4/manual.html#4.2
§4.2> of the Lua 5.4 reference manual).
See also: lua_upvalueindex.
Wrapper of a Lua state whose lifetime is managed by the Haskell garbage collector and has a finalizer attached. This means that the state does not have to be closed explicitly, but will be closed automatically when the value is garbage collected in Haskell.
Closes the Lua state and runs all finalizers associated with it. The state _may not_ be used after it has been closed.
Creates a new Lua state that is under the control of the Haskell garbage collector.
Run Lua computation using the default HsLua state as starting point. Exceptions are masked, thus avoiding some issues when using multiple threads. All exceptions are passed through; error handling is the responsibility of the caller.
Run the given Lua computation; exceptions raised in Haskell code are caught, but other exceptions (user exceptions raised in Haskell, unchecked type errors, etc.) are passed through.
Runs a Lua action with a state that's managed by GC.
Like , but adds a traceback if an error occurs.call
Run the given file as a Lua program, while also adding a traceback to the error message if an error occurs.
Like pcall, but sets an appropriate message handler function,
thereby adding a stack traceback if an error occurs.
Lua status values.
Commands to control the garbage collector.
GCStopstops the garbage collector.
GCRestartrestarts the garbage collector
GCCollectperforms a full garbage-collection cycle.
GCCountreturns the current amount of memory (in Kbytes) in use by Lua.
GCCountbreturns the remainder of dividing the current amount of bytes of memory in use by Lua by 1024.
GCStep CIntperforms an incremental step of garbage
collection, corresponding to the allocation of
stepsize Kbytes.
GCInc CInt CInt CIntChanges the collector to incremental mode
with the given parameters (see
<https://www.lua.org/manual/5.4/manual.html#2.5.1
§2.5.1>). Returns the previous mode
(LUA_GCGEN or LUA_GCINC).
Parameters: pause, stepmul, and stepsize.
GCGen CInt CIntChanges the collector to generational mode
with the given parameters (see
<https://www.lua.org/manual/5.4/manual.html#2.5.2
§2.5.2>). Returns the previous mode
(LUA_GCGEN or LUA_GCINC).
GCIsRunningreturns a boolean that tells whether the collector is running (i.e., not stopped).
Haskell function that can be called from Lua. The HsLua equivallent of a PreCFunction.
LuaError e => Exposable e (HaskellFunction e)Defined in hslua-classes-2.3.1 · HsLua.Class.ExposableEnvironment in which Lua computations are evaluated.
LuaEnvironmentluaEnvState :: StateLua interpreter state
MonadReader LuaEnvironment (LuaE e)Defined in hslua-core-2.3.2 · HsLua.Core.TypesOption for multiple returns in pcall.
Value signaling that no reference was found.
Value signaling that no reference was created.
Pseudo stack index of the Lua registry.
Run Lua computation with the given Lua state. Exception handling is left to the caller; resulting exceptions are left unhandled.
Get the Lua state of this Lua computation.
Run the given operation, but crash if any Haskell exceptions occur.
This function is identical to runWith; it exists for backwards compatibility.
fromuserdata :: StackIndexstack index of userdata
-> Nameexpected name of userdata object
-> LuaE e (Maybe a)Retrieves a Haskell object from userdata at the given index. The userdata must have the given name.
Creates a new userdata wrapping the given Haskell object. The userdata is pushed to the top of the stack.
Creates and registers a new metatable for a userdata-wrapped Haskell value; checks whether a metatable of that name has been registered yet and uses the registered table if possible.
Returns True if a new metatable was created, and False otherwise.
Using a metatable created by this functions ensures that the pointer to the Haskell value will be freed when the userdata object is garbage collected in Lua.
The name may not contain a nul character.
Sets a warning function. This is a simplified version of
lua_setwarnf. The given function is called with the concatenated
warning components as the single argument.
Control messages are handled internally and are not passed on the
warning hook. As with the default warning function, the control
messages @on and @off can switch error reporting to stderr on
and off. The given Haskell function will be called in either case,
even when the error is not written to stderr.
Wraps hsluaL_setwarnf.
Stack index of the nth element from the bottom of the stack.
Stack index of the nth element from the top of the stack.
Convert a reference to its C representation.
Create a reference from its C representation.
Lift a computation from the IO monad. This allows us to run IO computations in any monadic stack, so long as it supports these kinds of operations (i.e. IO is the base monad for the stack).
import Control.Monad.Trans.State -- from the "transformers" library
printState :: Show s => StateT s IO ()
printState = do
state <- get
liftIO $ print stateHad we omitted liftIO, we would have ended up with this error:
• Couldn't match type ‘IO’ with ‘StateT s IO’
Expected type: StateT s IO ()
Actual type: IO ()The important part here is the mismatch between StateT s IO () and IO ().
Luckily, we know of a function that takes an IO a and returns an (m a): liftIO,
enabling us to run the program and see the expected results:
> evalStateT printState "hello"
"hello"
> evalStateT printState 3
3
Reference to a stored value.
Type for C functions.
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, 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.Functions.lua_gettop. 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.Lua.Functions.lua_gettop
See lua_CFunction.
The number of arguments consumed curing a function call.
The number of results returned by a function call.
Eq NumResultsDefined in lua-2.3.2 · Lua.TypesNum NumResultsDefined in lua-2.3.2 · Lua.TypesOrd NumResultsDefined in lua-2.3.2 · Lua.TypesShow NumResultsDefined in lua-2.3.2 · Lua.TypesThe type of floats in Lua.
By default this type is Double, but that can be changed in Lua to
a single float or a long double. (See LUA_FLOAT_TYPE in
luaconf.h.)
See lua_Number.
Eq NumberDefined in lua-2.3.2 · Lua.TypesFloating NumberDefined in lua-2.3.2 · Lua.TypesFractional NumberDefined in lua-2.3.2 · Lua.TypesNum NumberDefined in lua-2.3.2 · Lua.TypesOrd NumberDefined in lua-2.3.2 · Lua.TypesRead NumberDefined in lua-2.3.2 · Lua.TypesReal NumberDefined in lua-2.3.2 · Lua.TypesRealFloat NumberDefined in lua-2.3.2 · Lua.TypesRealFrac NumberDefined in lua-2.3.2 · Lua.TypesShow NumberDefined in lua-2.3.2 · Lua.TypesPeekable NumberDefined in hslua-classes-2.3.1 · HsLua.Class.PeekablePushable NumberDefined in hslua-classes-2.3.1 · HsLua.Class.PushableType of Haskell functions that can be turned into C functions.
This is the same as a dereferenced CFunction.
A stack index
Enum StackIndexDefined in lua-2.3.2 · Lua.TypesEq StackIndexDefined in lua-2.3.2 · Lua.TypesNum StackIndexDefined in lua-2.3.2 · Lua.TypesOrd StackIndexDefined in lua-2.3.2 · Lua.TypesShow StackIndexDefined in lua-2.3.2 · Lua.TypesAn opaque structure that points to a thread and indirectly (through the thread) to the whole state of a Lua interpreter. The Lua library is fully reentrant: it has no global variables. All information about a state is accessible through this structure.
Synonym for lua_State *. See
lua_State.
Eq StateDefined in lua-2.3.2 · Lua.TypesGeneric StateDefined in lua-2.3.2 · Lua.TypesPeekable StateDefined in hslua-classes-2.3.1 · HsLua.Class.Peekabletype Rep State = D1 ('MetaData "State"
"Lua.Types"
"lua-2.3.2-70lbxEsccETF14NSmxmYYI"
'True) (C1 ('MetaCons "State"
'PrefixI 'False) (S1 ('MetaSel 'Nothing 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Ptr ()))))Defined in lua-2.3.2 · Lua.TypesPush list as numerically indexed table.
Lifts a Lua operation into the Peek monad.
Record to keep track of failure contexts while retrieving objects from the Lua stack.
Success !aFailure ByteString [Name]Error message and stack of contexts
Monad ResultDefined in hslua-marshalling-2.3.1 · HsLua.Marshalling.PeekFunctor ResultDefined in hslua-marshalling-2.3.1 · HsLua.Marshalling.PeekMonadFail ResultDefined in hslua-marshalling-2.3.1 · HsLua.Marshalling.PeekApplicative ResultDefined in hslua-marshalling-2.3.1 · HsLua.Marshalling.PeekFoldable ResultDefined in hslua-marshalling-2.3.1 · HsLua.Marshalling.PeekTraversable ResultDefined in hslua-marshalling-2.3.1 · HsLua.Marshalling.PeekAlternative ResultDefined in hslua-marshalling-2.3.1 · HsLua.Marshalling.PeekMonadPlus ResultDefined in hslua-marshalling-2.3.1 · HsLua.Marshalling.PeekEq a => Eq (Result a)Defined in hslua-marshalling-2.3.1 · HsLua.Marshalling.PeekShow a => Show (Result a)Defined in hslua-marshalling-2.3.1 · HsLua.Marshalling.PeekFunction to retrieve a value from Lua's stack.
Function to push a value to Lua's stack.
Lua operation with an additional failure mode that can stack errors from different contexts; errors are not based on exceptions).
(LuaError e, Pushable a) => Exposable e (Peek e a)Defined in hslua-classes-2.3.1 · HsLua.Class.ExposableMonad (Peek e)Defined in hslua-marshalling-2.3.1 · HsLua.Marshalling.PeekFunctor (Peek e)Defined in hslua-marshalling-2.3.1 · HsLua.Marshalling.PeekMonadFail (Peek e)Defined in hslua-marshalling-2.3.1 · HsLua.Marshalling.PeekApplicative (Peek e)Defined in hslua-marshalling-2.3.1 · HsLua.Marshalling.PeekAlternative (Peek e)Defined in hslua-marshalling-2.3.1 · HsLua.Marshalling.PeekMonadPlus (Peek e)Defined in hslua-marshalling-2.3.1 · HsLua.Marshalling.PeekReads a numerically indexed table t into a list, where the length of
the list is equal to rawlen(t). The operation will fail unless all
numerical fields between 1 and rawlen(t) can be retrieved.
Pushes a lazy ByteString as a raw string.
Push a floating point number to the Lua stack. Uses a string representation for all types which do not match the float properties of the Number type.
Pushes a String as a UTF-8 encoded Lua string.
Pushes a Text value as a UTF-8 encoded string.
Runs the peek action, resetting the stack top afterwards. This can be used with peek actions that might otherwise leave elements on the stack in case of a failure.
Fails the peek operation.
Create a peek failure record from an error message.
Force creation of an unwrapped result, throwing an exception if that's not possible.
Converts a Peek action into a LuaE action, throwing an exception in case of a peek failure.
Runs the peek action and Lua action in sequence, even if the peek action fails.
Converts a Result into an Either, where Left holds the reportable
string in case of an failure.
Add context information to the peek traceback stack.
Runs the peeker function.
Transform the result using the given function.
Try all peekers and return the result of the first to succeed.
Retrieves a Bool as a Lua boolean.
Retrieves a ByteString as a raw string.
Get value at key from a table.
Retrieves an Integral value from the Lua stack.
Read a table into a list of pairs.
Retrieves a lazy ByteString as a raw string.
Retrieves a key-value Lua table as Map.
Retrieves a Lua string as Name.
Succeeds if the value at the given index is nil.
Returns empty if the value at the given index is nil;
otherwise returns the result of peeker p.
Returns empty if the value at the given index is none;
otherwise returns the result of peeker p.
Succeeds if the given index is not valid or if the value at this
index is nil.
Returns empty if the value at the given index is none or
nil; otherwise returns the result of peeker p.
Retrieves a value pair from a table. Expects the values to be stored in a numerically indexed table; does not access metamethods.
Retrieves a value by getting a String from Lua, then using readMaybe to convert the String into a Haskell value.
Retrieves a Set from an idiomatic Lua representation. A set in Lua is idiomatically represented as a table with the elements as keys. Elements with falsy values are omitted.
Retrieves a String from an UTF-8 encoded Lua string.
Retrieves a String-like value from an UTF-8 encoded Lua string.
This should not be used to peek ByteString values or other values for which construction via fromString can result in loss of information.
Retrieves a Text value as an UTF-8 encoded string.
Retrieves a value triple from a table. Expects the values to be stored in a numerically indexed table, with no metamethods.
Report the expected and actual type of the value under the given index if conversion failed.
typeChecked Use test to check whether the value at stack index n has
the correct type and use peekfn to convert it to a Haskell
value if possible. A successfully received value is wrapped
using the Right constructor, while a type mismatch results
in Left PeekError with the given error message.
typeMismatchMessage :: Nameexpected type
-> StackIndexindex of offending value
-> Peek e ByteStringGenerate a type mismatch error.
Pushes an object as a table, defined by a list of field-names/push-function pairs.
Pushes a Bool as a Lua boolean.
Pushes a ByteString as a raw string.
Pushes an Integer to the Lua stack. Values representable as Lua
integers are pushed as such; bigger integers are represented using
their string representation.
Push list of pairs as default key-value Lua table.
Push Map as default key-value Lua table.
Pushes a Name as a UTF-8 encoded Lua string.
Push non-empty list as numerically indexed table.
Pushes a pair of values as a two element list.
Push a Set as idiomatic Lua set, i.e., as a table with the set
elements as keys and true as values.
Pushes a value triple as a three element list.
pushIterator :: LuaError e=> (a -> LuaE e NumResults)pusher for the values
-> [a]list to iterate over lazily
-> LuaE e NumResultsPushes three values to the stack that can be used in a generic for loop to lazily iterate over all values in the list. Keeps the remaining list in a userdata state.
If the values pusher function returns NumResults 0 for a list
item, then this item will be skipped and the values for the next item
will be pushed.
Lua metadata operation types.
Addthe addition (+) operation. If any operand for an
addition is not a number (nor a string coercible to a
number), Lua will try to call a metamethod. First, Lua will
check the first operand (even if it is valid). If that
operand does not define a metamethod for __add, then Lua
will check the second operand. If Lua can find a
metamethod, it calls the metamethod with the two operands
as arguments, and the result of the call (adjusted to one
value) is the result of the operation. Otherwise, it raises
an error.
Subthe subtraction (-) operation. Behavior similar to the
addition operation.
Multhe multiplication (*) operation. Behavior similar to the
addition operation.
Divthe division (/) operation. Behavior similar to the
addition operation.
Modthe modulo (%) operation. Behavior similar to the
addition operation.
Powthe exponentiation (^) operation. Behavior similar to the
addition operation.
Unmthe negation (unary -) operation. Behavior similar to the
addition operation.
Idivthe floor division (//) operation. Behavior similar to
the addition operation.
Bandthe bitwise AND (&) operation. Behavior similar to the
addition operation, except that Lua will try a metamethod
if any operand is neither an integer nor a value coercible
to an integer (see §3.4.3).
Borthe bitwise OR (|) operation. Behavior similar to the
bitwise AND operation.
Bxorthe bitwise exclusive OR (binary ~) operation. Behavior
similar to the bitwise AND operation.
Bnotthe bitwise NOT (unary ~) operation. Behavior similar to
the bitwise AND operation.
Shlthe bitwise left shift (<<) operation. Behavior similar
to the bitwise AND operation.
Shrthe bitwise right shift (>>) operation. Behavior
similar to the bitwise AND operation.
Concatthe concatenation (..) operation. Behavior similar to
the addition operation, except that Lua will try a
metamethod if any operand is neither a string nor a number
(which is always coercible to a string).
Lenthe length (#) operation. If the object is not a string,
Lua will try its metamethod. If there is a metamethod, Lua
calls it with the object as argument, and the result of the
call (always adjusted to one value) is the result of the
operation. If there is no metamethod but the object is a
table, then Lua uses the table length operation (see
§3.4.7). Otherwise, Lua raises an error.
Eqthe equal (==) operation. Behavior similar to the
addition operation, except that Lua will try a metamethod
only when the values being compared are either both tables
or both full userdata and they are not primitively equal.
The result of the call is always converted to a boolean.
Ltthe less than (<) operation. Behavior similar to the
addition operation, except that Lua will try a metamethod
only when the values being compared are neither both
numbers nor both strings. The result of the call is always
converted to a boolean.
Lethe less equal (<=) operation. Unlike other operations,
the less-equal operation can use two different events.
First, Lua looks for the __le metamethod in both
operands, like in the less than operation. If it cannot
find such a metamethod, then it will try the __lt
metamethod, assuming that a <= b is equivalent to not (b <
a). As with the other comparison operators, the result is
always a boolean. (This use of the __lt event can be
removed in future versions; it is also slower than a real
__le metamethod.)
IndexThe indexing access operation table[key]. This event
happens when table is not a table or when key is not
present in table. The metamethod is looked up in table.
NewindexThe indexing assignment table[key] = value. Like the
index event, this event happens when table is not a table
or when key is not present in table. The metamethod is
looked up in table.
CallThe call operation func(args). This event happens when
Lua tries to call a non-function value (that is, func is
not a function). The metamethod is looked up in func. If
present, the metamethod is called with func as its first
argument, followed by the arguments of the original call
(args). All results of the call are the result of the
operation. (This is the only metamethod that allows
multiple results.)
TostringThe operation used to create a string representation of the object.
Pairsthe operation of iterating over the object's key-value pairs.
CustomOperation Namea custom operation, with the metamethod name as parameter.
alias :: AliasIndexproperty alias
-> Textdescription
-> [AliasIndex]sequence of nested properties
-> Member e fn aDefine an alias for another, possibly nested, property.
possibleProperty Declares a new read- and writable property which is not always available.
possibleProperty' Declares a new read- and writable property which is not always available.
property Declares a new read- and writable property.
property' Declares a new read- and writable typed property.
readonly Creates a read-only object property. Attempts to set the value will cause an error.
readonly' Creates a read-only object property. Attempts to set the value will cause an error.
Returns documentation for this type.
Type specifier for a UDType
A type member, either a method or a variable.
A read- and writable property on a UD object.
PropertypropertyGet :: a -> LuaE e NumResultspropertySet :: Maybe (StackIndex -> a -> LuaE e a)propertyDescription :: TextpropertyType :: TypeSpecIndex types allowed in aliases (strings and integers)
Eq AliasIndexDefined in hslua-objectorientation-2.3.1 · HsLua.ObjectOrientationOrd AliasIndexDefined in hslua-objectorientation-2.3.1 · HsLua.ObjectOrientationIsString AliasIndexDefined in hslua-objectorientation-2.3.1 · HsLua.ObjectOrientationdeftypeGeneric Defines a new type, defining the behavior of objects in Lua. Note that the type name must be unique.
deftypeGeneric' Defines a new type that could also be treated as a list; defines the behavior of objects in Lua. Note that the type name must be unique.
Ensures that the type has been fully initialized, i.e., that all metatables have been created and stored in the registry. Returns the name of the initialized type.
The hook can be used to perform additional setup operations. The
function is called as the last step after the type metatable has been
initialized: the fully initialized metatable will be at the top of
the stack at that point. Note that the hook will not be called if
the type's metatable already existed before this function was
invoked.
Use a documented function as an object method.
Retrieves a userdata value of the given type.
pushUDGeneric :: LuaError e=> (UDTypeWithList e fn a itemtype -> LuaE e ())push docs
-> UDTypeWithList e fn a itemtypeuserdata type
-> avalue to push
-> LuaE e ()Pushes a userdata value of the given type.
Alias for a different property of this or of a nested object.
type ListSpec e a itemtype = ((Pusher e itemtype, a -> [itemtype]), (Peeker e itemtype, a -> [itemtype] -> a))Pair of pairs, describing how a type can be used as a Lua list. The first pair describes how to push the list items, and how the list is extracted from the type; the second pair contains a method to retrieve list items, and defines how the list is used to create an updated value.
A userdata type, capturing the behavior of Lua objects that wrap Haskell values. The type name must be unique; once the type has been used to push or retrieve a value, the behavior can no longer be modified through this type.
A userdata type, capturing the behavior of Lua objects that wrap Haskell values. The type name must be unique; once the type has been used to push or retrieve a value, the behavior can no longer be modified through this type.
This type includes methods to define how the object should behave as
a read-only list of type itemtype.
UDTypeWithListudName :: NameudOperations :: [(Operation, fn)]udProperties :: Map Name (Property e a)udMethods :: Map Name fnudAliases :: Map AliasIndex AliasudListSpec :: Maybe (ListSpec e a itemtype)udFnPusher :: fn -> LuaE e ()Named and documented Lua module.
ModulemoduleName :: NamemoduleDescription :: TextmoduleFields :: [Field e]moduleFunctions :: [DocumentedFunction e]moduleOperations :: [(Operation, DocumentedFunction e)]moduleTypeInitializers :: [LuaE e Name]Lua metadata operation types.
Addthe addition (+) operation. If any operand for an
addition is not a number (nor a string coercible to a
number), Lua will try to call a metamethod. First, Lua will
check the first operand (even if it is valid). If that
operand does not define a metamethod for __add, then Lua
will check the second operand. If Lua can find a
metamethod, it calls the metamethod with the two operands
as arguments, and the result of the call (adjusted to one
value) is the result of the operation. Otherwise, it raises
an error.
Subthe subtraction (-) operation. Behavior similar to the
addition operation.
Multhe multiplication (*) operation. Behavior similar to the
addition operation.
Divthe division (/) operation. Behavior similar to the
addition operation.
Modthe modulo (%) operation. Behavior similar to the
addition operation.
Powthe exponentiation (^) operation. Behavior similar to the
addition operation.
Unmthe negation (unary -) operation. Behavior similar to the
addition operation.
Idivthe floor division (//) operation. Behavior similar to
the addition operation.
Bandthe bitwise AND (&) operation. Behavior similar to the
addition operation, except that Lua will try a metamethod
if any operand is neither an integer nor a value coercible
to an integer (see §3.4.3).
Borthe bitwise OR (|) operation. Behavior similar to the
bitwise AND operation.
Bxorthe bitwise exclusive OR (binary ~) operation. Behavior
similar to the bitwise AND operation.
Bnotthe bitwise NOT (unary ~) operation. Behavior similar to
the bitwise AND operation.
Shlthe bitwise left shift (<<) operation. Behavior similar
to the bitwise AND operation.
Shrthe bitwise right shift (>>) operation. Behavior
similar to the bitwise AND operation.
Concatthe concatenation (..) operation. Behavior similar to
the addition operation, except that Lua will try a
metamethod if any operand is neither a string nor a number
(which is always coercible to a string).
Lenthe length (#) operation. If the object is not a string,
Lua will try its metamethod. If there is a metamethod, Lua
calls it with the object as argument, and the result of the
call (always adjusted to one value) is the result of the
operation. If there is no metamethod but the object is a
table, then Lua uses the table length operation (see
§3.4.7). Otherwise, Lua raises an error.
Eqthe equal (==) operation. Behavior similar to the
addition operation, except that Lua will try a metamethod
only when the values being compared are either both tables
or both full userdata and they are not primitively equal.
The result of the call is always converted to a boolean.
Ltthe less than (<) operation. Behavior similar to the
addition operation, except that Lua will try a metamethod
only when the values being compared are neither both
numbers nor both strings. The result of the call is always
converted to a boolean.
Lethe less equal (<=) operation. Unlike other operations,
the less-equal operation can use two different events.
First, Lua looks for the __le metamethod in both
operands, like in the less than operation. If it cannot
find such a metamethod, then it will try the __lt
metamethod, assuming that a <= b is equivalent to not (b <
a). As with the other comparison operators, the result is
always a boolean. (This use of the __lt event can be
removed in future versions; it is also slower than a real
__le metamethod.)
IndexThe indexing access operation table[key]. This event
happens when table is not a table or when key is not
present in table. The metamethod is looked up in table.
NewindexThe indexing assignment table[key] = value. Like the
index event, this event happens when table is not a table
or when key is not present in table. The metamethod is
looked up in table.
CallThe call operation func(args). This event happens when
Lua tries to call a non-function value (that is, func is
not a function). The metamethod is looked up in func. If
present, the metamethod is called with func as its first
argument, followed by the arguments of the original call
(args). All results of the call are the result of the
operation. (This is the only metamethod that allows
multiple results.)
TostringThe operation used to create a string representation of the object.
Pairsthe operation of iterating over the object's key-value pairs.
CustomOperation Namea custom operation, with the metamethod name as parameter.
Defines a function parameter of type Bool.
Defines a function result of type Bool.
integralParam Defines a function parameter for an integral type.
Defines a function result for an integral type.
Defines a function parameter of type String.
Defines a function result of type Text.
Defines a function parameter of type Text.
Defines a function result of type Text.
Name of the registry field holding the documentation table. The documentation table is indexed by the documented objects, like module tables and functions, and contains documentation strings as values.
The table is an ephemeron table, i.e., an entry gets garbage collected if the key is no longer reachable.
Function that retrieves documentation.
Pushes the documentation for the element at the given stack index. Returns the type of the documentation object.
Pushes the documentation of a field as a table with string fields
name and description.
Pushes the documentation of a function as a table with string
fields, name, description, and since, sequence field
parameters, and sequence or string field results.
Pushes the documentation of a module as a table with string fields
name and description.
Registers the object at the top of the stack as documentation for
the object at index idx. Pops the documentation of the stack.
Like ($), but left associative.
Inline version of updateFunctionDescription.
Inline version of applyParameter.
Inline version of returnResults.
Return a flexible number of results that have been pushed by the function action.
Result of a call to a Haskell function.
List of function results in the order in which they are returned in Lua.
Helper type used to create HaskellFunctions.
Functor (HsFnPrecursor e)Defined in hslua-packaging-2.3.1 · HsLua.Packaging.FunctionFunction parameter.
Partially apply a parameter.
Begin wrapping a monadic Lua function such that it can be turned into a documented function exposable to Lua.
functionResult :: Pusher e amethod to push the Haskell result to Lua
-> TypeSpecLua type of result
-> Textresult description
-> FunctionResults e aCreates a function result.
Just like defun, but uses an empty name for the documented
function. Should be used when defining methods or operators.
Turns a pure function into a monadic Lua function.
The resulting function is strict.
Turns a binary function into a Lua function.
The resulting function is strict in both its arguments.
Turns a ternary function into a Lua function.
The resulting function is strict in all of its arguments.
Turns a quarternary function into a Lua function.
The resulting function is strict in all of its arguments.
Turns a quinary function into a Lua function.
The resulting function is strict in all of its arguments.
Makes a parameter optional.
optionalParameter Deprecated. Use `opt (parameter ...)` instead.
Creates an optional parameter.
DEPRECATED: Use opt (parameter ...) instead.
parameter Creates a parameter.
Pushes a documented Haskell function to the Lua stack, making it usable as a normal function in Lua. At the same time, the function docs are registered in the documentation table.
Like returnResult, but returns only a single result.
Take a HaskellFunction precursor and convert it into a full HaskellFunction, using the given FunctionResults to return the result to Lua.
Take a HaskellFunction precursor and convert it into a full HaskellFunction, using the given FunctionResults to return the result to Lua.
Renames a documented function.
Sets the library version at which the function was introduced in its current form.
Create a HaskellFunction precursor from a monadic function, selecting the stack index after which the first function parameter will be placed.
Updates the description of a Haskell function. Leaves the function unchanged if it has no documentation.
Preload self-documenting module using the module's default name.
Add the module under a different name to the table of preloaded packages.
Pushes a documented module to the Lua stack.
Registers a Module; leaves a copy of the module table on the stack.
Haskell equivallent to CFunction, i.e., function callable from Lua.
Self-documenting module field
FieldfieldName :: TextfieldType :: TypeSpecfieldDescription :: TextfieldPushValue :: LuaE e ()Documentation for a Haskell function
FunctionDocfunctionDescription :: TextparameterDocs :: [ParameterDoc]functionResultsDocs :: ResultsDocfunctionSince :: Maybe VersionVersion in which the function was introduced.
Eq FunctionDocDefined in hslua-packaging-2.3.1 · HsLua.Packaging.TypesOrd FunctionDocDefined in hslua-packaging-2.3.1 · HsLua.Packaging.TypesShow FunctionDocDefined in hslua-packaging-2.3.1 · HsLua.Packaging.TypesDocumentation for function parameters.
Eq ParameterDocDefined in hslua-packaging-2.3.1 · HsLua.Packaging.TypesOrd ParameterDocDefined in hslua-packaging-2.3.1 · HsLua.Packaging.TypesShow ParameterDocDefined in hslua-packaging-2.3.1 · HsLua.Packaging.TypesDocumentation for a single return value of a function.
Eq ResultValueDocDefined in hslua-packaging-2.3.1 · HsLua.Packaging.TypesOrd ResultValueDocDefined in hslua-packaging-2.3.1 · HsLua.Packaging.TypesShow ResultValueDocDefined in hslua-packaging-2.3.1 · HsLua.Packaging.TypesDocumentation for the return values of a function.
ResultsDocList [ResultValueDoc]List of individual results
ResultsDocMult TextFlexible results
Eq ResultsDocDefined in hslua-packaging-2.3.1 · HsLua.Packaging.TypesOrd ResultsDocDefined in hslua-packaging-2.3.1 · HsLua.Packaging.TypesShow ResultsDocDefined in hslua-packaging-2.3.1 · HsLua.Packaging.TypesType definitions containing documented functions.
A userdata type, capturing the behavior of Lua objects that wrap Haskell values. The type name must be unique; once the type has been used to push or retrieve a value, the behavior can no longer be modified through this type.
deftype :: LuaError e=> Nametype name
-> [(Operation, DocumentedFunction e)]operations
-> [Member e (DocumentedFunction e) a]methods
-> DocumentedType e aDefines a new type, defining the behavior of objects in Lua. Note that the type name must be unique.
deftype' :: LuaError e=> Nametype name
-> [(Operation, DocumentedFunction e)]operations
-> [Member e (DocumentedFunction e) a]methods
-> Maybe (ListSpec e a itemtype)list access
-> DocumentedTypeWithList e a itemtypeDefines a new type that could also be treated as a list; defines the behavior of objects in Lua. Note that the type name must be unique.
Ensures that the type has been fully initialized, i.e., that all metatables have been created and stored in the registry. Returns the name of the initialized type.
Use a documented function as an object method.
operation :: Operationthe kind of operation
-> DocumentedFunction efunction used to perform the operation
-> (Operation, DocumentedFunction e)Declares a new object operation from a documented function.
Retrieves a userdata value of the given type.
Pushes a userdata value of the given type.
udparam :: LuaError e=> DocumentedTypeWithList e a itemtypeexpected type
-> Textparameter name
-> Textparameter description
-> Parameter e aDefines a function parameter that takes the given type.
udresult :: LuaError e=> DocumentedTypeWithList e a itemtyperesult type
-> Textresult description
-> FunctionResults e aDefines a function result of the given type.
alias :: AliasIndexproperty alias
-> Textdescription
-> [AliasIndex]sequence of nested properties
-> Member e fn aDefine an alias for another, possibly nested, property.
possibleProperty Declares a new read- and writable property which is not always available.
possibleProperty' Declares a new read- and writable property which is not always available.
property Declares a new read- and writable property.
property' Declares a new read- and writable typed property.
readonly Creates a read-only object property. Attempts to set the value will cause an error.
readonly' Creates a read-only object property. Attempts to set the value will cause an error.
Returns documentation for this type.
Type specifier for a UDType
A type member, either a method or a variable.
A read- and writable property on a UD object.
Operations and functions that can be pushed to the Lua stack. This
is a helper function not intended to be used directly. Use the
toHaskellFunction wrapper instead.
partialApply :: StackIndex -> a -> Peek e NumResultsHelper function, called by toHaskellFunction. Should do a
partial application of the argument at the given index to the
underlying function. Recurses if necessary, causing further partial
applications until the operation is a easily exposable to Lua.
LuaError e => Exposable e (HaskellFunction e)Defined in hslua-classes-2.3.1 · HsLua.Class.Exposable(Peekable a, Exposable e b) => Exposable e (a -> b)Defined in hslua-classes-2.3.1 · HsLua.Class.Exposable(LuaError e, Pushable a) => Exposable e (LuaE e a)Defined in hslua-classes-2.3.1 · HsLua.Class.Exposable(LuaError e, Pushable a) => Exposable e (Peek e a)Defined in hslua-classes-2.3.1 · HsLua.Class.ExposablePushes the given value as a function to the Lua stack.
See toHaskellFunction for details.
Imports a Haskell function and registers it at global name.
Convert a Haskell function to a function type directly exposable to Lua. Any Haskell function can be converted provided that:
Any exception of type e will be caught.
Important: this does not catch exceptions other than e;
exception handling must be done by the Haskell function. Failure to
do so will cause the program to crash.
E.g., the following code could be used to handle an Exception of type FooException, if that type is an instance of MonadCatch and Pushable:
toHaskellFunction (myFun `catchM` (\e -> raiseError (e :: FooException)))Helper class used to make Lua functions useable from Haskell.
Invoke a Lua function. Use as:
v <- invoke "proc" "abc" (1::Int) (5.0::Double)A value that can be read from the Lua stack.
Peekable ByteStringDefined in hslua-classes-2.3.1 · HsLua.Class.PeekablePeekable ByteStringDefined in hslua-classes-2.3.1 · HsLua.Class.PeekablePeekable IntegerDefined in hslua-classes-2.3.1 · HsLua.Class.PeekablePeekable BoolDefined in hslua-classes-2.3.1 · HsLua.Class.PeekablePeekable DoubleDefined in hslua-classes-2.3.1 · HsLua.Class.PeekablePeekable FloatDefined in hslua-classes-2.3.1 · HsLua.Class.PeekablePeekable IntDefined in hslua-classes-2.3.1 · HsLua.Class.PeekablePeekable CFunctionDefined in hslua-classes-2.3.1 · HsLua.Class.PeekablePeekable IntegerDefined in hslua-classes-2.3.1 · HsLua.Class.PeekablePeekable NumberDefined in hslua-classes-2.3.1 · HsLua.Class.PeekablePeekable StateDefined in hslua-classes-2.3.1 · HsLua.Class.PeekablePeekable TextDefined in hslua-classes-2.3.1 · HsLua.Class.PeekablePeekable ()Defined in hslua-classes-2.3.1 · HsLua.Class.PeekablePeekable (Ptr a)Defined in hslua-classes-2.3.1 · HsLua.Class.PeekablePeekable [Char]Defined in hslua-classes-2.3.1 · HsLua.Class.PeekablePeekable a => Peekable (Optional a)Defined in hslua-classes-2.3.1 · HsLua.Class.UtilPeekable a => Peekable [a]Defined in hslua-classes-2.3.1 · HsLua.Class.Peekable(Ord a, Peekable a) => Peekable (Set a)Defined in hslua-classes-2.3.1 · HsLua.Class.Peekable(Ord a, Peekable a, Peekable b) => Peekable (Map a b)Defined in hslua-classes-2.3.1 · HsLua.Class.Peekable(Peekable a, Peekable b) => Peekable (a, b)Defined in hslua-classes-2.3.1 · HsLua.Class.Peekable(Peekable a, Peekable b, Peekable c) => Peekable (a, b, c)Defined in hslua-classes-2.3.1 · HsLua.Class.Peekable(Peekable a, Peekable b, Peekable c, Peekable d) => Peekable (a, b, c, d)Defined in hslua-classes-2.3.1 · HsLua.Class.Peekable(Peekable a, Peekable b, Peekable c, Peekable d, Peekable e) => Peekable (a, b, c, d, e)Defined in hslua-classes-2.3.1 · HsLua.Class.Peekable(Peekable a, Peekable b, Peekable c, Peekable d, Peekable e, Peekable f) => Peekable (a, b, c, d, e, f)Defined in hslua-classes-2.3.1 · HsLua.Class.Peekable(Peekable a, Peekable b, Peekable c, Peekable d, Peekable e, Peekable f, Peekable g) => Peekable (a, b, c, d, e, f, g)Defined in hslua-classes-2.3.1 · HsLua.Class.Peekable(Peekable a, Peekable b, Peekable c, Peekable d, Peekable e, Peekable f, Peekable g, Peekable h) => Peekable (a, b, c, d, e, f, g, h)Defined in hslua-classes-2.3.1 · HsLua.Class.PeekableRetrieves a Peekable value from the stack. Throws an exception of
type e if the given stack index does not a suitable value.
A value that can be pushed to the Lua stack.
Pushable ByteStringDefined in hslua-classes-2.3.1 · HsLua.Class.PushablePushable ByteStringDefined in hslua-classes-2.3.1 · HsLua.Class.PushablePushable IntegerDefined in hslua-classes-2.3.1 · HsLua.Class.PushablePushable BoolDefined in hslua-classes-2.3.1 · HsLua.Class.PushablePushable DoubleDefined in hslua-classes-2.3.1 · HsLua.Class.PushablePushable FloatDefined in hslua-classes-2.3.1 · HsLua.Class.PushablePushable IntDefined in hslua-classes-2.3.1 · HsLua.Class.PushablePushable CFunctionDefined in hslua-classes-2.3.1 · HsLua.Class.PushablePushable IntegerDefined in hslua-classes-2.3.1 · HsLua.Class.PushablePushable NumberDefined in hslua-classes-2.3.1 · HsLua.Class.PushablePushable TextDefined in hslua-classes-2.3.1 · HsLua.Class.PushablePushable ()Defined in hslua-classes-2.3.1 · HsLua.Class.PushablePushable (Ptr a)Defined in hslua-classes-2.3.1 · HsLua.Class.PushablePushable [Char]Defined in hslua-classes-2.3.1 · HsLua.Class.PushablePushable a => Pushable (Set a)Defined in hslua-classes-2.3.1 · HsLua.Class.PushablePushable a => Pushable (Optional a)Defined in hslua-classes-2.3.1 · HsLua.Class.UtilPushable a => Pushable [a]Defined in hslua-classes-2.3.1 · HsLua.Class.Pushable(Pushable a, Pushable b) => Pushable (Map a b)Defined in hslua-classes-2.3.1 · HsLua.Class.Pushable(Pushable a, Pushable b) => Pushable (a, b)Defined in hslua-classes-2.3.1 · HsLua.Class.Pushable(Pushable a, Pushable b, Pushable c) => Pushable (a, b, c)Defined in hslua-classes-2.3.1 · HsLua.Class.Pushable(Pushable a, Pushable b, Pushable c, Pushable d) => Pushable (a, b, c, d)Defined in hslua-classes-2.3.1 · HsLua.Class.Pushable(Pushable a, Pushable b, Pushable c, Pushable d, Pushable e) => Pushable (a, b, c, d, e)Defined in hslua-classes-2.3.1 · HsLua.Class.Pushable(Pushable a, Pushable b, Pushable c, Pushable d, Pushable e, Pushable f) => Pushable (a, b, c, d, e, f)Defined in hslua-classes-2.3.1 · HsLua.Class.Pushable(Pushable a, Pushable b, Pushable c, Pushable d, Pushable e, Pushable f, Pushable g) => Pushable (a, b, c, d, e, f, g)Defined in hslua-classes-2.3.1 · HsLua.Class.Pushable(Pushable a, Pushable b, Pushable c, Pushable d, Pushable e, Pushable f, Pushable g, Pushable h) => Pushable (a, b, c, d, e, f, g, h)Defined in hslua-classes-2.3.1 · HsLua.Class.PushableName of the registry slot holding the metatable given to array tables. The registry entry can be replaced with a different table if needed.
Gets the ToAeson function from a Lua userdata object.
Retrieves an Aeson Value from the Lua stack.
Retrieves a value from the Lua stack via JSON.
Pushes a function that converts the object at a given index into a Value.
Hslua StackValue instance for the Aeson Value data type.
Pushes a value to the Lua stack as a JSON-like value.
Like getglobal, but knows about packages and nested tables. E.g.
getglobal' "math.sin"will return the function sin in package math.
Like setglobal, but knows about packages and nested tables. E.g.
pushstring "0.9.4"
setglobal' "mypackage.version"All tables and fields, except for the last field, must exist.
Get, then pop the value at the top of the stack. The pop operation is executed even if the retrieval operation failed.
Newtype wrapper intended to be used for optional Lua values. Nesting this type is strongly discouraged as missing values on inner levels are indistinguishable from missing values on an outer level; wrong values would be the likely result.
Try to convert the value at the given stack index to a Haskell value. Returns Left with the error on failure.
Raise a Lua error, using the given value as the error object.