-- Hoogle documentation, generated by Haddock
-- See Hoogle, http://www.haskell.org/hoogle/


-- | Wrappers and helpers to bridge Haskell and <a>Lua</a>.
--   
--   It builds upon the <i>lua</i> package, which allows to bundle a Lua
--   interpreter with a Haskell program.
@package hslua-core
@version 2.3.2


-- | Encoding and decoding of String to and from UTF8.
module HsLua.Core.Utf8

-- | Decode <tt><a>ByteString</a></tt> to <tt><a>String</a></tt> using
--   UTF-8. Invalid input bytes are replaced with the Unicode replacement
--   character U+FFFD.
toString :: ByteString -> String

-- | Decode <tt><a>ByteString</a></tt> to <tt><a>Text</a></tt> using UTF-8.
--   Invalid input bytes are replaced with the Unicode replacement
--   character U+FFFD.
toText :: ByteString -> Text

-- | Encode <tt><a>String</a></tt> to <tt><a>ByteString</a></tt> using
--   UTF-8.
fromString :: String -> ByteString

-- | Encode <tt><a>Text</a></tt> to <tt><a>ByteString</a></tt> using UTF-8.
fromText :: Text -> ByteString


-- | The core Lua types, including mappings of Lua types to Haskell.
--   
--   This module has mostly been moved to <tt><a>Types</a></tt> and
--   currently re-exports that module. This module might be removed in the
--   future.
module HsLua.Core.Types

-- | 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 <tt><a>state</a></tt>.
newtype LuaE e a
Lua :: ReaderT LuaEnvironment IO a -> LuaE e a
[unLua] :: LuaE e a -> ReaderT LuaEnvironment IO a

-- | Environment in which Lua computations are evaluated.
newtype LuaEnvironment
LuaEnvironment :: State -> LuaEnvironment

-- | Lua interpreter state
[luaEnvState] :: LuaEnvironment -> State
newtype State
State :: Ptr () -> State
type Reader = FunPtr State -> Ptr () -> Ptr CSize -> IO Ptr CChar

-- | Turn a function of typ <tt>Lua.State -&gt; IO a</tt> into a monadic
--   Lua operation.
liftLua :: (State -> IO a) -> LuaE e a

-- | Turn a function of typ <tt>Lua.State -&gt; a -&gt; IO b</tt> into a
--   monadic Lua operation.
liftLua1 :: (State -> a -> IO b) -> a -> LuaE e b

-- | Get the Lua state of this Lua computation.
state :: LuaE e State

-- | Run Lua computation with the given Lua state. Exception handling is
--   left to the caller; resulting exceptions are left unhandled.
runWith :: State -> LuaE e a -> IO a

-- | Run the given operation, but crash if any Haskell exceptions occur.
--   
--   This function is identical to <a>runWith</a>; it exists for backwards
--   compatibility.
unsafeRunWith :: State -> LuaE e a -> IO a

-- | Commands to control the garbage collector.
data GCControl

-- | stops the garbage collector.
GCStop :: GCControl

-- | restarts the garbage collector
GCRestart :: GCControl

-- | performs a full garbage-collection cycle.
GCCollect :: GCControl

-- | returns the current amount of memory (in Kbytes) in use by Lua.
GCCount :: GCControl

-- | returns the remainder of dividing the current amount of bytes of
--   memory in use by Lua by 1024.
GCCountb :: GCControl

-- | performs an incremental step of garbage collection, corresponding to
--   the allocation of <tt>stepsize</tt> Kbytes.
GCStep :: CInt -> GCControl

-- | Changes the collector to incremental mode with the given parameters
--   (see &lt;<a>https://www.lua.org/manual/5.4/manual.html#2.5.1</a>
--   §2.5.1&gt;). Returns the previous mode (<tt>LUA_GCGEN</tt> or
--   <tt>LUA_GCINC</tt>). Parameters: pause, stepmul, and stepsize.
GCInc :: CInt -> CInt -> CInt -> GCControl

-- | Changes the collector to generational mode with the given parameters
--   (see &lt;<a>https://www.lua.org/manual/5.4/manual.html#2.5.2</a>
--   §2.5.2&gt;). Returns the previous mode (<tt>LUA_GCGEN</tt> or
--   <tt>LUA_GCINC</tt>).
GCGen :: CInt -> CInt -> GCControl

-- | returns a boolean that tells whether the collector is running (i.e.,
--   not stopped).
GCIsRunning :: GCControl

-- | Converts a GCControl command to its corresponding code.
toGCcode :: GCControl -> GCCode

-- | Returns the data value associated with a GCControl command.
toGCdata :: GCControl -> (CInt, CInt, CInt)

-- | Enumeration used as type tag. See <a>lua_type</a>.
data Type

-- | non-valid stack index
TypeNone :: Type

-- | type of Lua's <tt>nil</tt> value
TypeNil :: Type

-- | type of Lua booleans
TypeBoolean :: Type

-- | type of light userdata
TypeLightUserdata :: Type

-- | type of Lua numbers. See <tt><a>Number</a></tt>
TypeNumber :: Type

-- | type of Lua string values
TypeString :: Type

-- | type of Lua tables
TypeTable :: Type

-- | type of functions, either normal or <tt><a>CFunction</a></tt>
TypeFunction :: Type

-- | type of full user data
TypeUserdata :: Type

-- | type of Lua threads
TypeThread :: Type

-- | Convert a Lua <a>Type</a> to a type code which can be passed to the C
--   API.
fromType :: Type -> TypeCode

-- | Convert numerical code to Lua <a>Type</a>.
toType :: TypeCode -> Type
liftIO :: MonadIO m => IO a -> m a
type CFunction = FunPtr PreCFunction
type PreCFunction = State -> IO NumResults

-- | Haskell function that can be called from Lua. The HsLua equivallent of
--   a <a>PreCFunction</a>.
type HaskellFunction e = LuaE e NumResults
newtype LuaBool
LuaBool :: CInt -> LuaBool

-- | Convert a <tt><a>LuaBool</a></tt> to a Haskell <tt><a>Bool</a></tt>.
fromLuaBool :: LuaBool -> Bool

-- | Convert a Haskell <tt><a>Bool</a></tt> to a <tt><a>LuaBool</a></tt>.
toLuaBool :: Bool -> LuaBool
newtype Integer
Integer :: Int64 -> Integer
newtype Number
Number :: Double -> Number
newtype StackIndex
StackIndex :: CInt -> StackIndex
[fromStackIndex] :: StackIndex -> CInt

-- | Pseudo stack index of the Lua registry.
registryindex :: StackIndex
newtype NumArgs
NumArgs :: CInt -> NumArgs
[fromNumArgs] :: NumArgs -> CInt
newtype NumResults
NumResults :: CInt -> NumResults
[fromNumResults] :: NumResults -> CInt

-- | Option for multiple returns in <tt><a>pcall</a></tt>.
multret :: NumResults

-- | Lua comparison operations.
data RelationalOperator

-- | Correponds to Lua's equality (==) operator.
EQ :: RelationalOperator

-- | Correponds to Lua's strictly-lesser-than (&lt;) operator
LT :: RelationalOperator

-- | Correponds to Lua's lesser-or-equal (&lt;=) operator
LE :: RelationalOperator

-- | Convert relation operator to its C representation.
fromRelationalOperator :: RelationalOperator -> OPCode

-- | Lua status values.
data Status

-- | success
OK :: Status

-- | yielding / suspended coroutine
Yield :: Status

-- | a runtime rror
ErrRun :: Status

-- | syntax error during precompilation
ErrSyntax :: Status

-- | memory allocation (out-of-memory) error.
ErrMem :: Status

-- | error while running the message handler.
ErrErr :: Status

-- | opening or reading a file failed.
ErrFile :: Status

-- | Convert C integer constant to <tt><a>Status</a></tt>.
toStatus :: StatusCode -> Status
data Reference
Reference :: CInt -> Reference
RefNil :: Reference
fromReference :: Reference -> CInt
toReference :: CInt -> Reference

-- | Value signaling that no reference was found.
noref :: Int

-- | Value signaling that no reference was created.
refnil :: Int
nthTop :: CInt -> StackIndex
nthBottom :: CInt -> StackIndex
nth :: CInt -> StackIndex
top :: StackIndex

-- | 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 <tt>newtype</tt> instead of a simple
--   <tt>type Name = ByteString</tt> alias so we can define a UTF-8 based
--   <a>IsString</a> instance. Non-ASCII users would have a bad time
--   otherwise.
newtype Name
Name :: ByteString -> Name
[fromName] :: Name -> ByteString
instance GHC.Internal.Base.Applicative (HsLua.Core.Types.LuaE e)
instance GHC.Internal.Enum.Bounded HsLua.Core.Types.Type
instance GHC.Internal.Enum.Enum HsLua.Core.Types.Type
instance GHC.Classes.Eq HsLua.Core.Types.GCControl
instance GHC.Classes.Eq HsLua.Core.Types.Name
instance GHC.Classes.Eq HsLua.Core.Types.RelationalOperator
instance GHC.Classes.Eq HsLua.Core.Types.Status
instance GHC.Classes.Eq HsLua.Core.Types.Type
instance GHC.Internal.Base.Functor (HsLua.Core.Types.LuaE e)
instance GHC.Internal.Data.String.IsString HsLua.Core.Types.Name
instance Control.Monad.Catch.MonadCatch (HsLua.Core.Types.LuaE e)
instance GHC.Internal.Control.Monad.IO.Class.MonadIO (HsLua.Core.Types.LuaE e)
instance GHC.Internal.Base.Monad (HsLua.Core.Types.LuaE e)
instance Control.Monad.Catch.MonadMask (HsLua.Core.Types.LuaE e)
instance Control.Monad.Reader.Class.MonadReader HsLua.Core.Types.LuaEnvironment (HsLua.Core.Types.LuaE e)
instance Control.Monad.Catch.MonadThrow (HsLua.Core.Types.LuaE e)
instance GHC.Classes.Ord HsLua.Core.Types.GCControl
instance GHC.Classes.Ord HsLua.Core.Types.Name
instance GHC.Classes.Ord HsLua.Core.Types.RelationalOperator
instance GHC.Classes.Ord HsLua.Core.Types.Type
instance GHC.Internal.Read.Read HsLua.Core.Types.Type
instance GHC.Internal.Base.Semigroup HsLua.Core.Types.Name
instance GHC.Internal.Show.Show HsLua.Core.Types.GCControl
instance GHC.Internal.Show.Show HsLua.Core.Types.Name
instance GHC.Internal.Show.Show HsLua.Core.Types.RelationalOperator
instance GHC.Internal.Show.Show HsLua.Core.Types.Status
instance GHC.Internal.Show.Show HsLua.Core.Types.Type


-- | Convenience functions to convert Haskell values into Lua userdata.
module HsLua.Core.Userdata

-- | Creates a new userdata wrapping the given Haskell object. The userdata
--   is pushed to the top of the stack.
newhsuserdatauv :: a -> Int -> LuaE e ()

-- | 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 <a>True</a> if a new metatable was created, and <a>False</a>
--   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.
newudmetatable :: Name -> LuaE e Bool

-- | Retrieves a Haskell object from userdata at the given index. The
--   userdata <i>must</i> have the given name.
fromuserdata :: forall a e. StackIndex -> Name -> LuaE e (Maybe a)

-- | Replaces the Haskell value contained in the userdata value at
--   <tt>index</tt>. Checks that the userdata is of type <tt>name</tt> and
--   returns <a>True</a> on success, or <a>False</a> otherwise.
putuserdata :: StackIndex -> Name -> a -> LuaE e Bool


-- | Unsafe Lua functions.
--   
--   This module exports functions which conflict with those in
--   <a>Core</a>. It is intended to be imported qualified.
module HsLua.Core.Unsafe

-- | Wrapper for <a>lua_next</a>.
--   
--   <b>WARNING</b>: <tt>lua_next</tt> is unsafe in Haskell: This function
--   will cause an unrecoverable crash an error if the given key is neither
--   <tt>nil</tt> nor present in the table. Consider using the safe
--   <tt><a>next</a></tt> function in HsLua.Core instead.
next :: StackIndex -> LuaE e Bool


-- | Bindings to Lua's debug interface.
module HsLua.Core.Debug

-- | Gets information about the <tt>n</tt>-th upvalue of the closure at
--   index <tt>funcindex</tt>. It pushes the upvalue's value onto the stack
--   and returns its name. Returns <a>Nothing</a> (and pushes nothing) when
--   the index <tt>n</tt> is greater than the number of upvalues.
--   
--   See <a>debug.getupvalue</a> for more information about upvalues.
--   
--   <pre>
--   [0, +(0|1), -]
--   </pre>
--   
--   Wraps <a>lua_getupvalue</a>.
getupvalue :: StackIndex -> Int -> LuaE e (Maybe Name)

-- | 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 <a>Nothing</a> (and pops nothing) when the index <tt>n</tt> is
--   greater than the number of upvalues.
--   
--   Parameters <tt>funcindex</tt> and <tt>n</tt> are as in the function
--   <a>getupvalue</a>.
--   
--   <pre>
--   [-(0|1), +0, -]
--   </pre>
--   
--   Wraps <a>lua_setupvalue</a>.
setupvalue :: StackIndex -> Int -> LuaE e (Maybe Name)


-- | Lua exceptions and exception handling.
module HsLua.Core.Error

-- | Default Lua error type. Exceptions raised by Lua-related operations.
newtype Exception
Exception :: String -> Exception
[exceptionMessage] :: Exception -> String

-- | Any type that you wish to use for error handling in HsLua must be an
--   instance of the <tt>LuaError</tt> class.
class Exception e => LuaError e

-- | Converts 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.
popException :: LuaError e => LuaE e 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
--   <tt>tostring()</tt> on the object produces an informative message.
pushException :: LuaError e => e -> LuaE e ()

-- | Creates a new exception with the given message.
luaException :: LuaError e => String -> e

-- | 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 <a>LuaE</a> with a custom error type instead.
type Lua a = LuaE Exception a

-- | Return either the result of a Lua computation or, if an exception was
--   thrown, the error.
try :: Exception e => LuaE e a -> LuaE e (Either e a)

-- | Raises an exception in the Lua monad.
failLua :: LuaError e => String -> LuaE e a

-- | Converts a Lua error at the top of the stack into a Haskell exception
--   and throws it.
throwErrorAsException :: LuaError e => LuaE e a

-- | 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.
throwTypeMismatchError :: LuaError e => ByteString -> StackIndex -> LuaE e a

-- | Change the error type of a computation.
changeErrorType :: forall old new a. LuaE old a -> LuaE new a

-- | Takes a failable HsLua function and transforms it into a monadic
--   <a>LuaE</a> operation. Throws an exception if an error occured.
liftLuaThrow :: LuaError e => (State -> Ptr StatusCode -> IO a) -> LuaE e a

-- | 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
--   <a>popException</a>.
popErrorMessage :: State -> IO ByteString

-- | Creates an error to notify about a Lua type mismatch and pushes it to
--   the stack.
pushTypeMismatchError :: ByteString -> StackIndex -> LuaE e ()
instance HsLua.Core.Error.LuaError e => GHC.Internal.Base.Alternative (HsLua.Core.Types.LuaE e)
instance GHC.Classes.Eq HsLua.Core.Error.Exception
instance GHC.Internal.Exception.Type.Exception HsLua.Core.Error.Exception
instance HsLua.Core.Error.LuaError HsLua.Core.Error.Exception
instance HsLua.Core.Error.LuaError e => GHC.Internal.Control.Monad.Fail.MonadFail (HsLua.Core.Types.LuaE e)
instance GHC.Internal.Show.Show HsLua.Core.Error.Exception


-- | Expose Haskell functions as Lua closures.
module HsLua.Core.Closures

-- | 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
--   <tt>CInt</tt> that represents number of return values left on the
--   stack. See <a>CFunction</a> for more info.
pushPreCFunction :: PreCFunction -> LuaE e ()

-- | Pushes Haskell function as a callable userdata. All values created
--   will be garbage collected. The function should behave similar to a
--   <a>CFunction</a>.
--   
--   Error conditions should be indicated by raising a catchable exception
--   or by returning the result of <tt><a>error</a></tt>.
--   
--   Example:
--   
--   <pre>
--   mod23 :: Lua NumResults
--   mod23 = do
--     mn &lt;- tointeger (nthBottom 1)
--     case mn of
--       Nothing -&gt; pushstring "expected an integer" *&gt; error
--       Just n  -&gt; pushinteger (n `mod` 23)
--   pushHaskellFunction mod23
--   setglobal "mod23"
--   </pre>
pushHaskellFunction :: LuaError e => HaskellFunction e -> LuaE e ()


-- | Helper functions to run <a>LuaE</a> computations.
module HsLua.Core.Run

-- | 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 :: LuaE e a -> IO a

-- | 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.
runEither :: Exception e => LuaE e a -> IO (Either e a)

-- | Run Lua computation with the given Lua state. Exception handling is
--   left to the caller; resulting exceptions are left unhandled.
runWith :: State -> LuaE e a -> IO a

-- | 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.
data GCManagedState

-- | Creates a new Lua state that is under the control of the Haskell
--   garbage collector.
newGCManagedState :: IO GCManagedState

-- | Closes the Lua state and runs all finalizers associated with it. The
--   state _may not_ be used after it has been closed.
closeGCManagedState :: GCManagedState -> IO ()

-- | Runs a Lua action with a state that's managed by GC.
withGCManagedState :: GCManagedState -> LuaE e a -> IO a


-- | Helper functions to call Lua functions with tracebacks.
module HsLua.Core.Trace

-- | Like <tt><a>pcall</a></tt>, but sets an appropriate message handler
--   function, thereby adding a stack traceback if an error occurs.
pcallTrace :: NumArgs -> NumResults -> LuaE e Status

-- | Like <tt><tt>call</tt></tt>, but adds a traceback if an error occurs.
callTrace :: LuaError e => NumArgs -> NumResults -> LuaE e ()

-- | Run the given file as a Lua program, while also adding a traceback to
--   the error message if an error occurs.
dofileTrace :: Maybe FilePath -> LuaE e Status
dostringTrace :: ByteString -> LuaE e Status


-- | Utility functions for HsLua modules.
module HsLua.Core.Package

-- | Load a module, defined by a Haskell action, under the given name.
--   
--   Similar to <tt>luaL_requiref</tt>: If <tt>modname</tt> is not already
--   present in <tt>package.loaded</tt>, calls function <tt>openf</tt> with
--   string <tt>modname</tt> as an argument and sets the call result in
--   <tt>package.loaded[modname]</tt>, as if that function has been called
--   through <a>require</a>.
--   
--   Leaves a copy of the module on the stack.
requirehs :: LuaError e => Name -> (Name -> LuaE e ()) -> LuaE e ()

-- | Registers a preloading function. Takes an module name and the Lua
--   operation which produces the package.
preloadhs :: LuaError e => Name -> LuaE e NumResults -> LuaE e ()


-- | Core Lua API. This module provides thin wrappers around the respective
--   functions of the Lua C API. C functions which can throw an error are
--   wrapped such that the error is converted into an
--   <tt><a>Exception</a></tt>. However, memory allocation errors are not
--   caught and will cause the host program to terminate.
module HsLua.Core

-- | 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 :: LuaE e a -> IO a

-- | Run Lua computation with the given Lua state. Exception handling is
--   left to the caller; resulting exceptions are left unhandled.
runWith :: State -> LuaE e a -> IO a

-- | 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.
runEither :: Exception e => LuaE e a -> IO (Either e a)

-- | 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.
data GCManagedState

-- | Creates a new Lua state that is under the control of the Haskell
--   garbage collector.
newGCManagedState :: IO GCManagedState

-- | Closes the Lua state and runs all finalizers associated with it. The
--   state _may not_ be used after it has been closed.
closeGCManagedState :: GCManagedState -> IO ()

-- | Runs a Lua action with a state that's managed by GC.
withGCManagedState :: GCManagedState -> LuaE e a -> IO a

-- | 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 <tt><a>state</a></tt>.
newtype LuaE e a
Lua :: ReaderT LuaEnvironment IO a -> LuaE e a
[unLua] :: LuaE e a -> ReaderT LuaEnvironment IO a

-- | 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 <a>LuaE</a> with a custom error type instead.
type Lua a = LuaE Exception a

-- | Run the given operation, but crash if any Haskell exceptions occur.
--   
--   This function is identical to <a>runWith</a>; it exists for backwards
--   compatibility.
unsafeRunWith :: State -> LuaE e a -> IO a
liftIO :: MonadIO m => IO a -> m a

-- | Get the Lua state of this Lua computation.
state :: LuaE e State

-- | Environment in which Lua computations are evaluated.
newtype LuaEnvironment
LuaEnvironment :: State -> LuaEnvironment

-- | Lua interpreter state
[luaEnvState] :: LuaEnvironment -> State
type CFunction = FunPtr PreCFunction
type PreCFunction = State -> IO NumResults
newtype Integer
Integer :: Int64 -> Integer
newtype Number
Number :: Double -> Number
newtype StackIndex
StackIndex :: CInt -> StackIndex
[fromStackIndex] :: StackIndex -> CInt
nthTop :: CInt -> StackIndex
nthBottom :: CInt -> StackIndex
nth :: CInt -> StackIndex
top :: StackIndex
newtype NumArgs
NumArgs :: CInt -> NumArgs
[fromNumArgs] :: NumArgs -> CInt
newtype NumResults
NumResults :: CInt -> NumResults
[fromNumResults] :: NumResults -> CInt

-- | 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 <tt>newtype</tt> instead of a simple
--   <tt>type Name = ByteString</tt> alias so we can define a UTF-8 based
--   <a>IsString</a> instance. Non-ASCII users would have a bad time
--   otherwise.
newtype Name
Name :: ByteString -> Name
[fromName] :: Name -> ByteString

-- | Option for multiple returns in <tt><a>pcall</a></tt>.
multret :: NumResults

-- | Pseudo stack index of the Lua registry.
registryindex :: StackIndex

-- | Returns the pseudo-index that represents the <tt>i</tt>-th upvalue of
--   the running function (see
--   &lt;<a>https://www.lua.org/manual/5.4/manual.html#4.2</a> §4.2&gt; of
--   the Lua 5.4 reference manual).
--   
--   See also: <a>lua_upvalueindex</a>.
upvalueindex :: StackIndex -> StackIndex
newtype State
State :: Ptr () -> State

-- | Creates a new Lua state. It calls <tt>lua_newstate</tt> with an
--   allocator based on the standard C <tt>realloc</tt> function and then
--   sets a panic function (see <a>§4.4</a> of the Lua 5.4 Reference
--   Manual) that prints an error message to the standard error output in
--   case of fatal errors.
--   
--   Wraps <a>hsluaL_newstate</a>. See also: <a>luaL_newstate</a>.
newstate :: IO 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. 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 <a>lua_close</a>.
close :: State -> IO ()

-- | Converts the acceptable index <tt>idx</tt> into an equivalent absolute
--   index (that is, one that does not depend on the stack top).
--   
--   Wraps <a>lua_absindex</a>.
absindex :: StackIndex -> LuaE e StackIndex

-- | 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 <a>lua_gettop</a>.
gettop :: LuaE e StackIndex

-- | 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 <a>lua_settop</a>.
settop :: StackIndex -> LuaE e ()

-- | Pushes a copy of the element at the given index onto the stack.
--   
--   Wraps <a>lua_pushvalue</a>.
pushvalue :: StackIndex -> LuaE e ()

-- | Copies the element at index <tt>fromidx</tt> into the valid index
--   <tt>toidx</tt>, replacing the value at that position. Values at other
--   positions are not affected.
--   
--   Wraps <a>lua_copy</a>.
copy :: StackIndex -> StackIndex -> LuaE e ()

-- | 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.
--   
--   Wraps <a>lua_insert</a>.
insert :: StackIndex -> LuaE e ()

-- | Rotates the stack elements between the valid index <tt>idx</tt> and
--   the top of the stack. The elements are rotated <tt>n</tt> positions in
--   the direction of the top, for a positive <tt>n</tt>, or <tt>-n</tt>
--   positions in the direction of the bottom, for a negative <tt>n</tt>.
--   The absolute value of <tt>n</tt> 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.
--   
--   <a>https://www.lua.org/manual/5.4/manual.html#lua_rotate</a>
rotate :: StackIndex -> Int -> LuaE e ()

-- | Pops <tt>n</tt> elements from the stack.
--   
--   See also: <a>lua_pop</a>.
pop :: Int -> LuaE e ()

-- | 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 <a>lua_remove</a>.
remove :: StackIndex -> LuaE e ()

-- | 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 <a>lua_replace</a>.
replace :: StackIndex -> LuaE e ()

-- | Ensures that the stack has space for at least <tt>n</tt> extra slots
--   (that is, that you can safely push up to <tt>n</tt> 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 <a>lua_checkstack</a>.
checkstack :: Int -> LuaE e Bool

-- | Enumeration used as type tag. See <a>lua_type</a>.
data Type

-- | non-valid stack index
TypeNone :: Type

-- | type of Lua's <tt>nil</tt> value
TypeNil :: Type

-- | type of Lua booleans
TypeBoolean :: Type

-- | type of light userdata
TypeLightUserdata :: Type

-- | type of Lua numbers. See <tt><a>Number</a></tt>
TypeNumber :: Type

-- | type of Lua string values
TypeString :: Type

-- | type of Lua tables
TypeTable :: Type

-- | type of functions, either normal or <tt><a>CFunction</a></tt>
TypeFunction :: Type

-- | type of full user data
TypeUserdata :: Type

-- | type of Lua threads
TypeThread :: Type

-- | Returns the type of the value in the given valid index, or
--   <tt><a>TypeNone</a></tt> for a non-valid (but acceptable) index.
--   
--   This function wraps <a>lua_type</a>.
ltype :: StackIndex -> LuaE e Type

-- | Returns the name of the type encoded by the value <tt>tp</tt>, which
--   must be one the values returned by <tt><a>ltype</a></tt>.
--   
--   Wraps <a>lua_typename</a>.
typename :: Type -> LuaE e ByteString

-- | Returns <a>True</a> if the value at the given index is a boolean, and
--   <a>False</a> otherwise.
--   
--   Wraps <a>lua_isboolean</a>.
isboolean :: StackIndex -> LuaE e Bool

-- | Returns <a>True</a> if the value at the given index is a C function,
--   and <a>False</a> otherwise.
--   
--   Wraps <a>lua_iscfunction</a>.
iscfunction :: StackIndex -> LuaE e Bool

-- | Returns <a>True</a> if the value at the given index is a function
--   (either C or Lua), and <a>False</a> otherwise.
--   
--   Wraps <a>lua_isfunction</a>.
isfunction :: StackIndex -> LuaE e Bool

-- | Returns <tt>True</tt> if the value at the given index is an integer
--   (that is, the value is a number and is represented as an integer), and
--   <a>False</a> otherwise.
--   
--   Wraps <a>lua_isinteger</a>.
isinteger :: StackIndex -> LuaE e Bool

-- | Returns <tt>True</tt> if the value at the given index is a light
--   userdata, and <tt>False</tt> otherwise.
--   
--   Wraps <a>lua_islightuserdata</a>.
islightuserdata :: StackIndex -> LuaE e Bool

-- | Returns <a>True</a> if the value at the given index is *nil*, and
--   <a>False</a> otherwise.
--   
--   Wraps <a>lua_isnil</a>.
isnil :: StackIndex -> LuaE e Bool

-- | Returns <a>True</a> if the given index is not valid, and <a>False</a>
--   otherwise.
--   
--   Wraps <a>lua_isnone</a>.
isnone :: StackIndex -> LuaE e Bool

-- | Returns <a>True</a> if the given index is not valid or if the value at
--   the given index is *nil*, and <a>False</a> otherwise.
--   
--   Wraps <a>lua_isnoneornil</a>.
isnoneornil :: StackIndex -> LuaE e Bool

-- | Returns <a>True</a> if the value at the given index is a number or a
--   string convertible to a number, and <a>False</a> otherwise.
--   
--   Wraps <a>lua_isnumber</a>.
isnumber :: StackIndex -> LuaE e Bool

-- | Returns <a>True</a> if the value at the given index is a string or a
--   number (which is always convertible to a string), and <a>False</a>
--   otherwise.
--   
--   Wraps <a>lua_isstring</a>.
isstring :: StackIndex -> LuaE e Bool

-- | Returns <a>True</a> if the value at the given index is a table, and
--   <a>False</a> otherwise.
--   
--   Wraps <a>lua_istable</a>.
istable :: StackIndex -> LuaE e Bool

-- | Returns <a>True</a> if the value at the given index is a thread, and
--   <a>False</a> otherwise.
--   
--   Wraps <a>lua_isthread</a>.
isthread :: StackIndex -> LuaE e Bool

-- | Returns <a>True</a> if the value at the given index is a userdata
--   (either full or light), and <a>False</a> otherwise.
--   
--   Wraps <a>lua_isuserdata</a>.
isuserdata :: StackIndex -> LuaE e Bool

-- | Converts the Lua value at the given index to a haskell boolean value.
--   Like all tests in Lua, <tt>toboolean</tt> returns <tt>True</tt> for
--   any Lua value different from <tt>false</tt> and <tt>nil</tt>;
--   otherwise it returns <tt>False</tt>. (If you want to accept only
--   actual boolean values, use <tt><a>isboolean</a></tt> to test the
--   value's type.)
--   
--   Wraps <a>lua_toboolean</a>.
toboolean :: StackIndex -> LuaE e Bool

-- | Converts a value at the given index to a C function. That value must
--   be a C function; otherwise, returns <tt>Nothing</tt>.
--   
--   Wraps <a>lua_tocfunction</a>.
tocfunction :: StackIndex -> LuaE e (Maybe CFunction)

-- | Converts the Lua value at the given acceptable index to the signed
--   integral type <a>Integer</a>. The Lua value must be an integer, a
--   number or a string convertible to an integer (see <a>§3.4.3</a> of the
--   Lua 5.4 Reference Manual); otherwise, <tt>tointeger</tt> returns
--   <tt>Nothing</tt>.
--   
--   If the number is not an integer, it is truncated in some non-specified
--   way.
--   
--   Wraps <a>lua_tointegerx</a>. See also: <a>lua_tointeger</a>.
tointeger :: StackIndex -> LuaE e (Maybe Integer)

-- | Converts the Lua value at the given index to a <a>Number</a>. The Lua
--   value must be a number or a string convertible to a number; otherwise,
--   <tt>tonumber</tt> returns <tt><a>Nothing</a></tt>.
--   
--   Wraps <a>lua_tonumberx</a>. See also <a>lua_tonumber</a>.
tonumber :: StackIndex -> LuaE e (Maybe Number)

-- | 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 <tt>nullPtr</tt>. 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 <a>lua_topointer</a>.
topointer :: StackIndex -> LuaE e (Ptr ())

-- | Converts the Lua value at the given index to a <a>ByteString</a>. The
--   Lua value must be a string or a number; otherwise, the function
--   returns <a>Nothing</a>. If the value is a number, then <a>tostring</a>
--   also changes the actual value in the stack to a string. (This change
--   confuses <a>next</a> when <a>tostring</a> is applied to keys during a
--   table traversal.)
--   
--   Wraps <a>lua_tolstring</a>.
tostring :: StackIndex -> LuaE e (Maybe ByteString)

-- | Converts the value at the given index to a Lua thread (represented as
--   <a>State</a>). This value must be a thread; otherwise, the function
--   returns <tt>Nothing</tt>.
--   
--   Wraps <a>lua_tothread</a>.
tothread :: StackIndex -> LuaE e (Maybe State)

-- | 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 <tt>Nothing</tt>..
--   
--   Wraps <a>lua_touserdata</a>.
touserdata :: StackIndex -> LuaE e (Maybe (Ptr a))

-- | 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 (<tt>#</tt>) 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 <a>lua_rawlen</a>.
rawlen :: StackIndex -> LuaE e Int

-- | Lua comparison operations.
data RelationalOperator

-- | Correponds to Lua's equality (==) operator.
EQ :: RelationalOperator

-- | Correponds to Lua's strictly-lesser-than (&lt;) operator
LT :: RelationalOperator

-- | Correponds to Lua's lesser-or-equal (&lt;=) operator
LE :: RelationalOperator

-- | Compares two Lua values. Returns <a>True</a> if the value at index
--   <tt>idx1</tt> satisfies <tt>op</tt> when compared with the value at
--   index <tt>idx2</tt>, following the semantics of the corresponding Lua
--   operator (that is, it may call metamethods). Otherwise returns
--   <tt>False</tt>. Also returns <tt>False</tt> if any of the indices is
--   not valid.
--   
--   The value of op must be of type <a>RelationalOperator</a>:
--   
--   EQ: compares for equality (==) LT: compares for less than (&lt;) LE:
--   compares for less or equal (&lt;=)
--   
--   Wraps <a>hslua_compare</a>. See also <a>lua_compare</a>.
compare :: LuaError e => StackIndex -> StackIndex -> RelationalOperator -> LuaE e Bool

-- | Returns <tt>True</tt> if the two values in acceptable indices
--   <tt>index1</tt> and <tt>index2</tt> are equal, following the semantics
--   of the Lua <tt>==</tt> operator (that is, may call metamethods).
--   Otherwise returns <tt>False</tt>. Also returns <tt>False</tt> if any
--   of the indices is non valid. Uses <tt><a>compare</a></tt> internally.
equal :: LuaError e => StackIndex -> StackIndex -> LuaE e Bool

-- | Tests whether the object under the first index is smaller than that
--   under the second. Uses <tt><a>compare</a></tt> internally.
lessthan :: LuaError e => StackIndex -> StackIndex -> LuaE e Bool

-- | Returns <tt>True</tt> if the two values in indices <tt>idx1</tt> and
--   <tt>idx2</tt> are primitively equal (that is, without calling the
--   <tt>__eq</tt> metamethod). Otherwise returns <tt>False</tt>. Also
--   returns <tt>False</tt> if any of the indices are not valid.
--   
--   Wraps <a>lua_rawequal</a>.
rawequal :: StackIndex -> StackIndex -> LuaE e Bool

-- | Pushes a boolean value with the given value onto the stack.
--   
--   This functions wraps <a>lua_pushboolean</a>.
pushboolean :: Bool -> LuaE e ()

-- | 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
--   <tt><a>CFunction</a></tt>)
--   
--   Same as <tt>flip <a>pushcclosure</a> 0</tt>. <a>lua_pushcfunction</a>.
pushcfunction :: CFunction -> LuaE e ()

-- | 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 <a>§3.4</a>); 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 <tt>n</tt> telling how many values
--   should be associated with the function. pushcclosure also pops these
--   values from the stack.
--   
--   The maximum value for <tt>n</tt> is 255.
--   
--   Wraps <a>lua_pushcclosure</a>.
pushcclosure :: CFunction -> NumArgs -> LuaE e ()

-- | Pushes an integer with with the given value onto the stack.
--   
--   Wraps <a>lua_pushinteger</a>.
pushinteger :: Integer -> LuaE e ()

-- | Pushes a light userdata onto the stack.
--   
--   Userdata represent C values in Lua. A light userdata represents a
--   pointer, a <tt>Ptr a</tt> (i.e., <tt>void*</tt> 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 <a>lua_pushlightuserdata</a>.
pushlightuserdata :: Ptr a -> LuaE e ()

-- | Pushes a nil value onto the stack.
--   
--   Wraps <a>lua_pushnil</a>.
pushnil :: LuaE e ()

-- | Pushes a float with the given value onto the stack.
--   
--   Wraps <a>lua_pushnumber</a>.
pushnumber :: Number -> LuaE e ()

-- | 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 <a>lua_pushlstring</a>.
pushstring :: ByteString -> LuaE e ()

-- | Pushes the current thread onto the stack. Returns <tt>True</tt> if
--   this thread is the main thread of its state, <tt>False</tt> otherwise.
--   
--   Wraps <a>lua_pushthread</a>.
pushthread :: LuaE e Bool

-- | Pushes onto the stack the value of the global <tt>name</tt>.
--   
--   Errors on the Lua side are propagated.
--   
--   Wraps <a>hslua_getglobal</a>.
getglobal :: LuaError e => Name -> LuaE e Type

-- | Pushes onto the stack the value <tt>t[k]</tt>, where <tt>t</tt> is the
--   value at the given index and <tt>k</tt> 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 <a>§2.4</a> of Lua's manual).
--   
--   Errors on the Lua side are caught and rethrown.
--   
--   Wraps <a>hslua_gettable</a>. See also: <a>lua_gettable</a>.
gettable :: LuaError e => StackIndex -> LuaE e Type

-- | Pushes onto the stack the value <tt>t[k]</tt>, where <tt>t</tt> is the
--   value at the given stack index. As in Lua, this function may trigger a
--   metamethod for the "index" event (see <a>§2.4</a> of Lua's manual).
--   
--   Errors on the Lua side are propagated.
--   
--   See also <a>lua_getfield</a>.
getfield :: LuaError e => StackIndex -> Name -> LuaE e Type

-- | Similar to <tt><a>gettable</a></tt>, but does a raw access (i.e.,
--   without metamethods).
--   
--   Wraps <a>lua_rawget</a>.
rawget :: LuaError e => StackIndex -> LuaE e Type

-- | Pushes onto the stack the value <tt>t[n]</tt>, where <tt>t</tt> is the
--   table at the given index. The access is raw, that is, it does not
--   invoke the <tt>__index</tt> metamethod.
--   
--   Wraps <a>lua_rawgeti</a>.
rawgeti :: LuaError e => StackIndex -> Integer -> LuaE e Type

-- | 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 <a>lua_createtable</a>.
createtable :: Int -> Int -> LuaE e ()

-- | Creates a new empty table and pushes it onto the stack. It is
--   equivalent to <tt>createtable 0 0</tt>.
--   
--   See also: <a>lua_newtable</a>.
newtable :: LuaE e ()

-- | This function creates and pushes on the stack a new full userdata,
--   with <tt>nuvalue</tt> associated Lua values, called <tt>user
--   values</tt>, plus an associated block of raw memory with <tt>size</tt>
--   bytes. (The user values can be set and read with the functions
--   <a>lua_setiuservalue</a> and <a>lua_getiuservalue</a>.)
--   
--   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 <a>§2.5</a>). Moreover, if the userdata is marked for
--   finalization (see <a>§2.5.3</a>), its address is valid at least until
--   the call to its finalizer.
--   
--   This function wraps <a>lua_newuserdatauv</a>.
newuserdatauv :: Int -> Int -> LuaE e (Ptr ())

-- | If the value at the given index has a metatable, the function pushes
--   that metatable onto the stack and returns <tt>True</tt>. Otherwise,
--   the function returns <tt>False</tt> and pushes nothing on the stack.
--   
--   Wraps <a>lua_getmetatable</a>.
getmetatable :: StackIndex -> LuaE e Bool

-- | Pushes onto the stack the <tt>n</tt>-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 <b>nil</b> and
--   returns <a>LUA_TNONE</a>.
--   
--   Wraps <a>lua_getiuservalue</a>.
getiuservalue :: StackIndex -> Int -> LuaE e Type

-- | Pops a value from the stack and sets it as the new value of global
--   <tt>name</tt>.
--   
--   Errors on the Lua side are caught and rethrown as <a>Exception</a>.
--   
--   Wraps <a>hslua_setglobal</a>. See also: <a>lua_setglobal</a>.
setglobal :: LuaError e => Name -> LuaE e ()

-- | Does the equivalent to <tt>t[k] = v</tt>, where <tt>t</tt> is the
--   value at the given index, <tt>v</tt> is the value at the top of the
--   stack, and <tt>k</tt> 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 <a>§2.4</a> of the Lua 5.4 Reference Manual).
--   
--   Errors on the Lua side are caught and rethrown.
--   
--   Wraps <a>hslua_settable</a>.
settable :: LuaError e => StackIndex -> LuaE e ()

-- | Does the equivalent to <tt>t[k] = v</tt>, where <tt>t</tt> is the
--   value at the given index and <tt>v</tt> 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 <a>§2.4</a> of
--   the Lua 5.4 Reference Manual).
--   
--   Errors on the Lua side are caught and rethrown as a
--   <tt><a>Exception</a></tt>.
--   
--   See also: <a>lua_setfield</a>.
setfield :: LuaError e => StackIndex -> Name -> LuaE e ()

-- | Similar to <tt><a>settable</a></tt>, but does a raw assignment (i.e.,
--   without metamethods).
--   
--   Wraps <a>lua_rawset</a>.
rawset :: LuaError e => StackIndex -> LuaE e ()

-- | Does the equivalent of <tt>t[i] = v</tt>, where <tt>t</tt> is the
--   table at the given index and <tt>v</tt> 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 <tt>__newindex</tt> metamethod.
--   
--   Wraps <a>lua_rawseti</a>.
rawseti :: LuaError e => StackIndex -> Integer -> LuaE e ()

-- | Pops a table from the stack and sets it as the new metatable for the
--   value at the given index.
--   
--   Wraps <a>lua_setmetatable</a>.
setmetatable :: StackIndex -> LuaE e ()

-- | Pops a value from the stack and sets it as the new <tt>n</tt>-th user
--   value associated to the full userdata at the given index. Returns 0 if
--   the userdata does not have that value.
--   
--   Wraps <a>lua_setiuservalue</a>.
setiuservalue :: StackIndex -> Int -> LuaE e Bool

-- | 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 <tt>call</tt>; <tt>nargs</tt> 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
--   <tt>nresults</tt>, unless <tt>nresults</tt> is <tt>multret</tt>. 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 <tt>e</tt>.
--   
--   The following example shows how the host program can do the equivalent
--   to this Lua code:
--   
--   <pre>
--   a = f("how", t.x, 14)
--   </pre>
--   
--   Here it is in Haskell (assuming the OverloadedStrings language
--   extension):
--   
--   <pre>
--   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'
--   </pre>
--   
--   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 <a>lua_call</a>.
call :: LuaError e => NumArgs -> NumResults -> LuaE e ()

-- | Calls a function in protected mode.
--   
--   Both <tt>nargs</tt> and <tt>nresults</tt> have the same meaning as in
--   <tt><a>call</a></tt>. If there are no errors during the call,
--   <tt>pcall</tt> behaves exactly like <tt><a>call</a></tt>. However, if
--   there is any error, <tt>pcall</tt> catches it, pushes a single value
--   on the stack (the error message), and returns the error code. Like
--   <tt><a>call</a></tt>, <tt>pcall</tt> always removes the function and
--   its arguments from the stack.
--   
--   If <tt>msgh</tt> is <tt>Nothing</tt>, then the error object returned
--   on the stack is exactly the original error object. Otherwise, when
--   <tt>msgh</tt> is <tt>Just idx</tt>, the stack index <tt>idx</tt> 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 <tt><a>pcall</a></tt>.
--   
--   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 <tt><a>pcall</a></tt>, since by
--   then the stack has unwound.
--   
--   This function wraps <a>lua_pcall</a>.
pcall :: NumArgs -> NumResults -> Maybe StackIndex -> LuaE e Status

-- | Loads a Lua chunk (without running it). If there are no errors,
--   <tt><a>load</a></tt> pushes the compiled chunk as a Lua function on
--   top of the stack. Otherwise, it pushes an error message.
--   
--   The return values of <tt><a>load</a></tt> are:
--   
--   <ul>
--   <li><tt><a>OK</a></tt>: no errors;</li>
--   <li><tt><a>ErrSyntax</a></tt>: syntax error during
--   pre-compilation;</li>
--   <li><tt><a>ErrMem</a></tt>: memory allocation error;</li>
--   <li><tt><tt>ErrGcmm</tt></tt>: error while running a <tt>__gc</tt>
--   metamethod. (This error has no relation with the chunk being loaded.
--   It is generated by the garbage collector.)</li>
--   </ul>
--   
--   This function only loads a chunk; it does not run it.
--   
--   <tt>load</tt> automatically detects whether the chunk is text or
--   binary, and loads it accordingly (see program luac).
--   
--   The <tt><a>load</a></tt> function uses a user-supplied reader function
--   to read the chunk (see <tt><a>Reader</a></tt>). The data argument is
--   an opaque value passed to the reader function.
--   
--   The <tt>chunkname</tt> argument gives a name to the chunk, which is
--   used for error messages and in debug information (see <a>§4.7</a>).
--   Note that the <tt>chunkname</tt> is used as a C string, so it may not
--   contain null-bytes.
--   
--   This is a wrapper of <a>lua_load</a>.
load :: Reader -> Ptr () -> Name -> LuaE e Status

-- | Loads a ByteString as a Lua chunk.
--   
--   This function returns the same results as <tt><a>load</a></tt>.
--   <tt>name</tt> is the chunk name, used for debug information and error
--   messages. Note that <tt>name</tt> is used as a C string, so it may not
--   contain null-bytes.
--   
--   Wraps <a>luaL_loadbuffer</a>.
loadbuffer :: ByteString -> Name -> LuaE e Status

-- | Loads a file as a Lua chunk. This function uses <tt>lua_load</tt> (see
--   <tt><a>load</a></tt>) to load the chunk in the file named
--   <tt>filename</tt>. If filename is <tt>Nothing</tt>, then it loads from
--   the standard input. The first line in the file is ignored if it starts
--   with a <tt>#</tt>.
--   
--   The string mode works as in function <tt><a>load</a></tt>.
--   
--   This function returns the same results as <tt><a>load</a></tt>, but it
--   has an extra error code <tt><a>ErrFile</a></tt> for file-related
--   errors (e.g., it cannot open or read the file).
--   
--   As <tt><a>load</a></tt>, this function only loads the chunk; it does
--   not run it.
--   
--   See <a>luaL_loadfile</a>.
loadfile :: Maybe FilePath -> LuaE e Status

-- | Loads a string as a Lua chunk. This function uses <tt>lua_load</tt> to
--   load the chunk in the given ByteString. The given string may not
--   contain any NUL characters.
--   
--   This function returns the same results as <tt>lua_load</tt> (see
--   <tt><a>load</a></tt>).
--   
--   Also as <tt><a>load</a></tt>, this function only loads the chunk; it
--   does not run it.
--   
--   See <a>luaL_loadstring</a>.
loadstring :: ByteString -> LuaE e Status

-- | Lua status values.
data Status

-- | success
OK :: Status

-- | yielding / suspended coroutine
Yield :: Status

-- | a runtime rror
ErrRun :: Status

-- | syntax error during precompilation
ErrSyntax :: Status

-- | memory allocation (out-of-memory) error.
ErrMem :: Status

-- | error while running the message handler.
ErrErr :: Status

-- | opening or reading a file failed.
ErrFile :: Status

-- | Returns the status of this Lua thread.
--   
--   The status can be <a>OK</a> for a normal thread, an error value if the
--   thread finished the execution of a <tt>lua_resume</tt> with an error,
--   or <a>Yield</a> if the thread is suspended.
--   
--   You can only call functions in threads with status <a>OK</a>. You can
--   resume threads with status <a>OK</a> (to start a new coroutine) or
--   <a>Yield</a> (to resume a coroutine).
--   
--   Wraps <a>lua_status</a>.
status :: LuaE e Status

-- | Commands to control the garbage collector.
data GCControl

-- | stops the garbage collector.
GCStop :: GCControl

-- | restarts the garbage collector
GCRestart :: GCControl

-- | performs a full garbage-collection cycle.
GCCollect :: GCControl

-- | returns the current amount of memory (in Kbytes) in use by Lua.
GCCount :: GCControl

-- | returns the remainder of dividing the current amount of bytes of
--   memory in use by Lua by 1024.
GCCountb :: GCControl

-- | performs an incremental step of garbage collection, corresponding to
--   the allocation of <tt>stepsize</tt> Kbytes.
GCStep :: CInt -> GCControl

-- | Changes the collector to incremental mode with the given parameters
--   (see &lt;<a>https://www.lua.org/manual/5.4/manual.html#2.5.1</a>
--   §2.5.1&gt;). Returns the previous mode (<tt>LUA_GCGEN</tt> or
--   <tt>LUA_GCINC</tt>). Parameters: pause, stepmul, and stepsize.
GCInc :: CInt -> CInt -> CInt -> GCControl

-- | Changes the collector to generational mode with the given parameters
--   (see &lt;<a>https://www.lua.org/manual/5.4/manual.html#2.5.2</a>
--   §2.5.2&gt;). Returns the previous mode (<tt>LUA_GCGEN</tt> or
--   <tt>LUA_GCINC</tt>).
GCGen :: CInt -> CInt -> GCControl

-- | returns a boolean that tells whether the collector is running (i.e.,
--   not stopped).
GCIsRunning :: GCControl

-- | Controls the garbage collector.
--   
--   This function performs several tasks, according to the given control
--   command. See the documentation for <a>GCControl</a>.
--   
--   Wraps <a>lua_gc</a>.
gc :: GCControl -> LuaE e Int

-- | 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 <tt>next</tt> returns
--   <tt>False</tt> (and pushes nothing).
--   
--   Errors on the Lua side are caught and rethrown as a
--   <tt><a>Exception</a></tt>.
--   
--   This function wraps <a>hslua_next</a>. See also: <a>lua_next</a>.
next :: LuaError e => StackIndex -> LuaE e Bool

-- | Signals to Lua that an error has occurred and that the error object is
--   at the top of the stack.
error :: LuaE e NumResults

-- | Concatenates the <tt>n</tt> values at the top of the stack, pops them,
--   and leaves the result at the top. If <tt>n</tt> is 1, the result is
--   the single value on the stack (that is, the function does nothing); if
--   <tt>n</tt> is 0, the result is the empty string. Concatenation is
--   performed following the usual semantics of Lua (see <a>§3.4.6</a> of
--   the Lua manual).
--   
--   Wraps <a>hslua_concat</a>. See also <a>lua_concat</a>.
concat :: LuaError e => NumArgs -> LuaE e ()

-- | Pushes the global environment onto the stack.
--   
--   Wraps <a>lua_pushglobaltable</a>.
pushglobaltable :: LuaE e ()

-- | Sets the C function <tt>f</tt> as the new value of global
--   <tt>name</tt>.
--   
--   Behaves like "lua_register".
register :: LuaError e => Name -> CFunction -> LuaE e ()

-- | Sets the warning function to be used by Lua to emit warnings (see
--   <a>WarnFunction</a>). The <tt>ud</tt> parameter sets the value
--   <tt>ud</tt> passed to the warning function.
setwarnf :: WarnFunction -> Ptr () -> LuaE e ()

-- | Pushes Lua's <i>base</i> library onto the stack.
--   
--   This function pushes and and calls <a>luaopen_base</a>.
openbase :: LuaError e => LuaE e ()

-- | Pushes Lua's <i>debug</i> library onto the stack.
--   
--   This function pushes and and calls <a>luaopen_io</a>.
opendebug :: LuaError e => LuaE e ()

-- | Pushes Lua's <i>io</i> library onto the stack.
--   
--   This function pushes and and calls <a>luaopen_io</a>.
openio :: LuaError e => LuaE e ()

-- | Opens all standard Lua libraries into the current state and sets each
--   library name as a global value.
--   
--   This function wraps <a>luaL_openlibs</a>.
openlibs :: LuaE e ()

-- | Pushes Lua's <i>math</i> library onto the stack.
--   
--   This function pushes and and calls <a>luaopen_math</a>.
openmath :: LuaError e => LuaE e ()

-- | Pushes Lua's <i>package</i> library onto the stack.
--   
--   This function pushes and and calls <a>luaopen_package</a>.
openpackage :: LuaError e => LuaE e ()

-- | Pushes Lua's <i>os</i> library onto the stack.
--   
--   This function pushes and and calls <a>luaopen_os</a>.
openos :: LuaError e => LuaE e ()

-- | Pushes Lua's <i>string</i> library onto the stack.
--   
--   This function pushes and and calls <a>luaopen_string</a>.
openstring :: LuaError e => LuaE e ()

-- | Pushes Lua's <i>table</i> library onto the stack.
--   
--   This function pushes and and calls <a>luaopen_table</a>.
opentable :: LuaError e => LuaE e ()

-- | Grows the stack size to <tt>top + sz</tt> elements, raising an error
--   if the stack cannot grow to that size. <tt>msg</tt> is an additional
--   text to go into the error message (or the empty string for no
--   additional text).
checkstack' :: LuaError e => Int -> String -> LuaE e ()

-- | Loads and runs the given string.
--   
--   Returns <a>OK</a> on success, or an error if either loading of the
--   string or calling of the thunk failed.
dostring :: ByteString -> LuaE e Status

-- | 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.
dofile :: Maybe FilePath -> LuaE e Status

-- | Pushes onto the stack the field <tt>e</tt> from the metatable of the
--   object at index <tt>obj</tt> 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 <a>TypeNil</a>.
--   
--   Wraps <a>luaL_getmetafield</a>.
getmetafield :: StackIndex -> Name -> LuaE e Type

-- | Pushes onto the stack the metatable associated with name
--   <tt>tname</tt> in the registry (see <a>newmetatable</a>) (<tt>nil</tt>
--   if there is no metatable associated with that name). Returns the type
--   of the pushed value.
--   
--   Wraps <a>luaL_getmetatable</a>.
getmetatable' :: Name -> LuaE e Type

-- | Ensures that the value <tt>t[fname]</tt>, where <tt>t</tt> is the
--   value at index <tt>idx</tt>, 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.
getsubtable :: LuaError e => StackIndex -> Name -> LuaE e Bool

-- | If the registry already has the key tname, returns <tt>False</tt>.
--   Otherwise, creates a new table to be used as a metatable for userdata,
--   adds to this new table the pair <tt>__name = tname</tt>, adds to the
--   registry the pair <tt>[tname] = new table</tt>, and returns
--   <tt>True</tt>. (The entry <tt>__name</tt> is used by some
--   error-reporting functions.)
--   
--   In both cases pushes onto the stack the final value associated with
--   <tt>tname</tt> in the registry.
--   
--   The value of <tt>tname</tt> is used as a C string and hence must not
--   contain null bytes.
--   
--   Wraps <a>luaL_newmetatable</a>.
newmetatable :: Name -> LuaE e Bool

-- | If <tt>modname</tt> is not already present in <tt>package.loaded</tt>.
--   calls function <tt>openf</tt> with string <tt>modname</tt> as an
--   argument and sets the call result in <tt>package.loaded[modname]</tt>,
--   as if that function has been called through <a>require</a>.
--   
--   If <tt>glb</tt> is true, also stores the module into global
--   <tt>modname</tt>.
--   
--   Leaves a copy of the module on the stack.
--   
--   See <tt>requirehs</tt> for a version intended to be used with Haskell
--   actions.
requiref :: LuaError e => Name -> CFunction -> Bool -> LuaE e ()

-- | Converts any Lua value at the given index to a <a>ByteString</a> 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 <tt>__tostring</tt> field, then
--   <tt>tolstring'</tt> calls the corresponding metamethod with the value
--   as argument, and uses the result of the call as its result.
--   
--   Wraps <a>hsluaL_tolstring</a>.
tostring' :: LuaError e => StackIndex -> LuaE e ByteString

-- | 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 <a>luaL_traceback</a>.
traceback :: State -> Maybe ByteString -> Int -> LuaE e ()

-- | Pushes onto the stack a string identifying the current position of the
--   control at level <tt>lvl</tt> in the call stack. Typically this string
--   has the following format:
--   
--   <pre>
--   chunkname:currentline:
--   </pre>
--   
--   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.
where' :: Int -> LuaE e ()
data Reference
Reference :: CInt -> Reference
RefNil :: Reference

-- | Creates and returns a reference, in the table at index <tt>t</tt>, 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 <tt>t</tt>, <tt>ref</tt> ensures the
--   uniqueness of the key it returns. You can retrieve an object referred
--   by reference <tt>r</tt> by calling <tt>rawgeti t r</tt>. Function
--   <tt><a>unref</a></tt> frees a reference and its associated object.
--   
--   If the object at the top of the stack is nil, <tt><a>ref</a></tt>
--   returns the constant <tt><a>refnil</a></tt>. The constant
--   <tt><a>noref</a></tt> is guaranteed to be different from any reference
--   returned by <tt><a>ref</a></tt>.
--   
--   Wraps <a>luaL_ref</a>.
ref :: StackIndex -> LuaE e Reference

-- | Push referenced value from the table at the given index.
getref :: LuaError e => StackIndex -> Reference -> LuaE e Type

-- | Releases reference <tt><a>ref</a></tt> from the table at index
--   <tt>idx</tt> (see <tt><a>ref</a></tt>). The entry is removed from the
--   table, so that the referred object can be collected. The reference
--   <tt><a>ref</a></tt> is also freed to be used again.
--   
--   Wraps <a>luaL_unref</a>. See also: <a>luaL_unref</a>.
unref :: StackIndex -> Reference -> LuaE e ()
fromReference :: Reference -> CInt
toReference :: CInt -> Reference

-- | Value signaling that no reference was found.
noref :: Int

-- | Value signaling that no reference was created.
refnil :: Int

-- | Key to the registry field that holds the table of loaded modules.
loaded :: Name

-- | Key to the registry field that holds the table of loader functions.
preload :: Name

-- | Like <tt><a>pcall</a></tt>, but sets an appropriate message handler
--   function, thereby adding a stack traceback if an error occurs.
pcallTrace :: NumArgs -> NumResults -> LuaE e Status

-- | Like <tt><tt>call</tt></tt>, but adds a traceback if an error occurs.
callTrace :: LuaError e => NumArgs -> NumResults -> LuaE e ()

-- | Run the given file as a Lua program, while also adding a traceback to
--   the error message if an error occurs.
dofileTrace :: Maybe FilePath -> LuaE e Status
dostringTrace :: ByteString -> LuaE e Status

-- | Sets a warning function. This is a simplified version of
--   <tt>lua_setwarnf</tt>. The given function is called with the
--   concatenated warning components as the single argument.
--   
--   Control messages are handled internally and are <i>not</i> passed on
--   the warning hook. As with the default warning function, the control
--   messages <tt>@on</tt> and <tt>@off</tt> 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 <a>hsluaL_setwarnf</a>.
setwarnf' :: LuaError e => (ByteString -> LuaE e ()) -> LuaE e ()

-- | Gets information about the <tt>n</tt>-th upvalue of the closure at
--   index <tt>funcindex</tt>. It pushes the upvalue's value onto the stack
--   and returns its name. Returns <a>Nothing</a> (and pushes nothing) when
--   the index <tt>n</tt> is greater than the number of upvalues.
--   
--   See <a>debug.getupvalue</a> for more information about upvalues.
--   
--   <pre>
--   [0, +(0|1), -]
--   </pre>
--   
--   Wraps <a>lua_getupvalue</a>.
getupvalue :: StackIndex -> Int -> LuaE e (Maybe Name)

-- | 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 <a>Nothing</a> (and pops nothing) when the index <tt>n</tt> is
--   greater than the number of upvalues.
--   
--   Parameters <tt>funcindex</tt> and <tt>n</tt> are as in the function
--   <a>getupvalue</a>.
--   
--   <pre>
--   [-(0|1), +0, -]
--   </pre>
--   
--   Wraps <a>lua_setupvalue</a>.
setupvalue :: StackIndex -> Int -> LuaE e (Maybe Name)

-- | Creates a new userdata wrapping the given Haskell object. The userdata
--   is pushed to the top of the stack.
newhsuserdatauv :: a -> Int -> LuaE e ()

-- | 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 <a>True</a> if a new metatable was created, and <a>False</a>
--   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.
newudmetatable :: Name -> LuaE e Bool

-- | Retrieves a Haskell object from userdata at the given index. The
--   userdata <i>must</i> have the given name.
fromuserdata :: forall a e. StackIndex -> Name -> LuaE e (Maybe a)

-- | Replaces the Haskell value contained in the userdata value at
--   <tt>index</tt>. Checks that the userdata is of type <tt>name</tt> and
--   returns <a>True</a> on success, or <a>False</a> otherwise.
putuserdata :: StackIndex -> Name -> a -> LuaE e Bool

-- | Haskell function that can be called from Lua. The HsLua equivallent of
--   a <a>PreCFunction</a>.
type HaskellFunction e = LuaE e NumResults

-- | Pushes Haskell function as a callable userdata. All values created
--   will be garbage collected. The function should behave similar to a
--   <a>CFunction</a>.
--   
--   Error conditions should be indicated by raising a catchable exception
--   or by returning the result of <tt><a>error</a></tt>.
--   
--   Example:
--   
--   <pre>
--   mod23 :: Lua NumResults
--   mod23 = do
--     mn &lt;- tointeger (nthBottom 1)
--     case mn of
--       Nothing -&gt; pushstring "expected an integer" *&gt; error
--       Just n  -&gt; pushinteger (n `mod` 23)
--   pushHaskellFunction mod23
--   setglobal "mod23"
--   </pre>
pushHaskellFunction :: LuaError e => HaskellFunction e -> LuaE e ()

-- | 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
--   <tt>CInt</tt> that represents number of return values left on the
--   stack. See <a>CFunction</a> for more info.
pushPreCFunction :: PreCFunction -> LuaE e ()

-- | Any type that you wish to use for error handling in HsLua must be an
--   instance of the <tt>LuaError</tt> class.
class Exception e => LuaError e

-- | Converts 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.
popException :: LuaError e => LuaE e 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
--   <tt>tostring()</tt> on the object produces an informative message.
pushException :: LuaError e => e -> LuaE e ()

-- | Creates a new exception with the given message.
luaException :: LuaError e => String -> e

-- | Default Lua error type. Exceptions raised by Lua-related operations.
newtype Exception
Exception :: String -> Exception
[exceptionMessage] :: Exception -> String

-- | Return either the result of a Lua computation or, if an exception was
--   thrown, the error.
try :: Exception e => LuaE e a -> LuaE e (Either e a)

-- | Raises an exception in the Lua monad.
failLua :: LuaError e => String -> LuaE e a

-- | Converts a Lua error at the top of the stack into a Haskell exception
--   and throws it.
throwErrorAsException :: LuaError e => LuaE e a

-- | 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.
throwTypeMismatchError :: LuaError e => ByteString -> StackIndex -> LuaE e a

-- | Change the error type of a computation.
changeErrorType :: forall old new a. LuaE old a -> LuaE new a

-- | 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
--   <a>popException</a>.
popErrorMessage :: State -> IO ByteString

-- | Creates an error to notify about a Lua type mismatch and pushes it to
--   the stack.
pushTypeMismatchError :: ByteString -> StackIndex -> LuaE e ()

-- | Load a module, defined by a Haskell action, under the given name.
--   
--   Similar to <tt>luaL_requiref</tt>: If <tt>modname</tt> is not already
--   present in <tt>package.loaded</tt>, calls function <tt>openf</tt> with
--   string <tt>modname</tt> as an argument and sets the call result in
--   <tt>package.loaded[modname]</tt>, as if that function has been called
--   through <a>require</a>.
--   
--   Leaves a copy of the module on the stack.
requirehs :: LuaError e => Name -> (Name -> LuaE e ()) -> LuaE e ()

-- | Registers a preloading function. Takes an module name and the Lua
--   operation which produces the package.
preloadhs :: LuaError e => Name -> LuaE e NumResults -> LuaE e ()
