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


-- | Bindings to Lua, an embeddable scripting language
--   
--   HsLua provides bindings, wrappers, types, and helper functions to
--   bridge Haskell and <a>Lua</a>.
--   
--   This package contains a full Lua interpreter version 5.3.5. If you
--   want to link it with a system-wide Lua installation, use the
--   <tt>system-lua</tt> flag.
--   
--   <a>Example programs</a> are available in a separate repository.
@package hslua
@version 1.0.3.2


-- | The core Lua types, including mappings of Lua types to Haskell.
module Foreign.Lua.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 Lua a
Lua :: ReaderT State IO a -> Lua a
[unLua] :: Lua a -> ReaderT State IO a

-- | An 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 <tt>lua_State *</tt>. See <a>lua_State</a>.
newtype State
State :: Ptr () -> State

-- | The reader function used by <tt><tt>lua_load</tt></tt>. Every time it
--   needs another piece of the chunk, lua_load calls the reader, passing
--   along its data parameter. The reader must return a pointer to a block
--   of memory with a new piece of the chunk and set size to the block
--   size. The block must exist until the reader function is called again.
--   To signal the end of the chunk, the reader must return <tt>NULL</tt>
--   or set size to zero. The reader function may return pieces of any size
--   greater than zero.
--   
--   See <a>lua_Reader</a>.
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) -> Lua 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 -> Lua b

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

-- | Run lua computation with custom lua state. Errors are left unhandled,
--   the caller of this function is responsible to catch lua errors.
runWith :: State -> Lua a -> IO a

-- | Enumeration used by <tt>gc</tt> function.
data GCCONTROL
GCSTOP :: GCCONTROL
GCRESTART :: GCCONTROL
GCCOLLECT :: GCCONTROL
GCCOUNT :: GCCONTROL
GCCOUNTB :: GCCONTROL
GCSTEP :: GCCONTROL
GCSETPAUSE :: GCCONTROL
GCSETSTEPMUL :: GCCONTROL

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

-- | Integer code used to encode the type of a lua value.
newtype TypeCode
TypeCode :: CInt -> TypeCode
[fromTypeCode] :: TypeCode -> CInt

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

-- | Convert numerical code to lua type.
toType :: TypeCode -> Type
liftIO :: MonadIO m => IO a -> m a

-- | 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, <tt><tt>gettop</tt></tt> 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 <tt>gettop</tt>. 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.
--   
--   See <a>lua_CFunction</a>.
type CFunction = FunPtr (State -> IO NumResults)

-- | Boolean value returned by a Lua C API function. This is a
--   <tt><a>CInt</a></tt> and interpreted as <tt><a>False</a></tt> iff the
--   value is <tt>0</tt>, <tt><a>True</a></tt> otherwise.
newtype LuaBool
LuaBool :: CInt -> LuaBool

-- | Lua representation of the value interpreted as false.
false :: LuaBool

-- | Generic Lua representation of a value interpreted as being true.
true :: 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

-- | The type of integers in Lua.
--   
--   By default this type is <tt><a>Int64</a></tt>, but that can be changed
--   to different values in lua. (See <tt>LUA_INT_TYPE</tt> in
--   <tt>luaconf.h</tt>.)
--   
--   See <a>lua_Integer</a>.
newtype Integer
Integer :: Int64 -> Integer

-- | The type of floats in Lua.
--   
--   By default this type is <tt><a>Double</a></tt>, but that can be
--   changed in Lua to a single float or a long double. (See
--   <tt>LUA_FLOAT_TYPE</tt> in <tt>luaconf.h</tt>.)
--   
--   See <a>lua_Number</a>.
newtype Number
Number :: Double -> Number

-- | A stack index
newtype StackIndex
StackIndex :: CInt -> StackIndex
[fromStackIndex] :: StackIndex -> CInt

-- | Stack index of the nth element from the bottom of the stack.
nthFromBottom :: CInt -> StackIndex

-- | Stack index of the nth element from the top of the stack.
nthFromTop :: CInt -> StackIndex

-- | Top of the stack
stackTop :: StackIndex

-- | Bottom of the stack
stackBottom :: StackIndex

-- | The number of arguments expected a function.
newtype NumArgs
NumArgs :: CInt -> NumArgs
[fromNumArgs] :: NumArgs -> CInt

-- | The number of results returned by a function call.
newtype NumResults
NumResults :: CInt -> NumResults
[fromNumResults] :: NumResults -> CInt

-- | 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 -> CInt

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

-- | error while running a <tt>__gc</tt> metamethod.
ErrGcmm :: Status

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

-- | Integer code used to signal the status of a thread or computation. See
--   <tt><a>Status</a></tt>.
newtype StatusCode
StatusCode :: CInt -> StatusCode

-- | Convert C integer constant to <tt><tt>LuaStatus</tt></tt>.
toStatus :: StatusCode -> Status

-- | Reference to a stored value.
data Reference

-- | Reference to a stored value
Reference :: CInt -> Reference

-- | Reference to a nil value
RefNil :: Reference

-- | Convert a reference to its C representation.
fromReference :: Reference -> CInt

-- | Create a reference from its C representation.
toReference :: CInt -> Reference
instance GHC.Show.Show Foreign.Lua.Core.Types.Reference
instance GHC.Classes.Eq Foreign.Lua.Core.Types.Reference
instance GHC.Show.Show Foreign.Lua.Core.Types.NumResults
instance GHC.Classes.Ord Foreign.Lua.Core.Types.NumResults
instance GHC.Num.Num Foreign.Lua.Core.Types.NumResults
instance GHC.Classes.Eq Foreign.Lua.Core.Types.NumResults
instance GHC.Show.Show Foreign.Lua.Core.Types.NumArgs
instance GHC.Classes.Ord Foreign.Lua.Core.Types.NumArgs
instance GHC.Num.Num Foreign.Lua.Core.Types.NumArgs
instance GHC.Classes.Eq Foreign.Lua.Core.Types.NumArgs
instance GHC.Show.Show Foreign.Lua.Core.Types.StackIndex
instance GHC.Classes.Ord Foreign.Lua.Core.Types.StackIndex
instance GHC.Num.Num Foreign.Lua.Core.Types.StackIndex
instance GHC.Classes.Eq Foreign.Lua.Core.Types.StackIndex
instance GHC.Enum.Enum Foreign.Lua.Core.Types.StackIndex
instance GHC.Show.Show Foreign.Lua.Core.Types.GCCONTROL
instance GHC.Classes.Ord Foreign.Lua.Core.Types.GCCONTROL
instance GHC.Classes.Eq Foreign.Lua.Core.Types.GCCONTROL
instance GHC.Enum.Enum Foreign.Lua.Core.Types.GCCONTROL
instance GHC.Classes.Eq Foreign.Lua.Core.Types.StatusCode
instance GHC.Show.Show Foreign.Lua.Core.Types.Status
instance GHC.Classes.Eq Foreign.Lua.Core.Types.Status
instance GHC.Show.Show Foreign.Lua.Core.Types.RelationalOperator
instance GHC.Classes.Ord Foreign.Lua.Core.Types.RelationalOperator
instance GHC.Classes.Eq Foreign.Lua.Core.Types.RelationalOperator
instance GHC.Show.Show Foreign.Lua.Core.Types.TypeCode
instance GHC.Classes.Ord Foreign.Lua.Core.Types.TypeCode
instance GHC.Classes.Eq Foreign.Lua.Core.Types.TypeCode
instance GHC.Show.Show Foreign.Lua.Core.Types.Type
instance GHC.Classes.Ord Foreign.Lua.Core.Types.Type
instance GHC.Classes.Eq Foreign.Lua.Core.Types.Type
instance GHC.Enum.Bounded Foreign.Lua.Core.Types.Type
instance GHC.Show.Show Foreign.Lua.Core.Types.LuaBool
instance Foreign.Storable.Storable Foreign.Lua.Core.Types.LuaBool
instance GHC.Classes.Eq Foreign.Lua.Core.Types.LuaBool
instance GHC.Show.Show Foreign.Lua.Core.Types.Number
instance GHC.Real.RealFrac Foreign.Lua.Core.Types.Number
instance GHC.Float.RealFloat Foreign.Lua.Core.Types.Number
instance GHC.Real.Real Foreign.Lua.Core.Types.Number
instance GHC.Classes.Ord Foreign.Lua.Core.Types.Number
instance GHC.Num.Num Foreign.Lua.Core.Types.Number
instance GHC.Real.Fractional Foreign.Lua.Core.Types.Number
instance GHC.Float.Floating Foreign.Lua.Core.Types.Number
instance GHC.Classes.Eq Foreign.Lua.Core.Types.Number
instance GHC.Show.Show Foreign.Lua.Core.Types.Integer
instance GHC.Real.Real Foreign.Lua.Core.Types.Integer
instance GHC.Classes.Ord Foreign.Lua.Core.Types.Integer
instance GHC.Num.Num Foreign.Lua.Core.Types.Integer
instance GHC.Real.Integral Foreign.Lua.Core.Types.Integer
instance GHC.Classes.Eq Foreign.Lua.Core.Types.Integer
instance GHC.Enum.Enum Foreign.Lua.Core.Types.Integer
instance GHC.Enum.Bounded Foreign.Lua.Core.Types.Integer
instance Control.Monad.Catch.MonadThrow Foreign.Lua.Core.Types.Lua
instance Control.Monad.Reader.Class.MonadReader Foreign.Lua.Core.Types.State Foreign.Lua.Core.Types.Lua
instance Control.Monad.Catch.MonadMask Foreign.Lua.Core.Types.Lua
instance Control.Monad.IO.Class.MonadIO Foreign.Lua.Core.Types.Lua
instance Control.Monad.Catch.MonadCatch Foreign.Lua.Core.Types.Lua
instance GHC.Base.Monad Foreign.Lua.Core.Types.Lua
instance GHC.Base.Functor Foreign.Lua.Core.Types.Lua
instance GHC.Base.Applicative Foreign.Lua.Core.Types.Lua
instance GHC.Generics.Generic Foreign.Lua.Core.Types.State
instance GHC.Classes.Eq Foreign.Lua.Core.Types.State
instance GHC.Enum.Enum Foreign.Lua.Core.Types.Type


-- | Lua constants
module Foreign.Lua.Core.Constants

-- | Alias for C constant <tt>LUA_MULTRET</tt>. See <a>lua_call</a>.
multret :: NumResults

-- | Alias for C constant <tt>LUA_REGISTRYINDEX</tt>. See <a>Lua
--   registry</a>.
registryindex :: StackIndex

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

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


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

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

-- | Catch a Lua <tt><a>Exception</a></tt>.
catchException :: Lua a -> (Exception -> Lua a) -> Lua a

-- | Raise a Lua <tt><a>Exception</a></tt> containing the given error
--   message.
throwException :: String -> Lua a

-- | Catch Lua <tt><a>Exception</a></tt>, alter the message and rethrow.
withExceptionMessage :: (String -> String) -> Lua a -> Lua a

-- | Convert the object at the top of the stack into a string and throw it
--   as an <tt><a>Exception</a></tt>.
throwTopMessage :: Lua a

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

-- | CInt value or an error, using the convention that value below zero
--   indicate an error. Values greater than zero are used verbatim. The
--   phantom type is used for additional type safety and gives the type
--   into which the wrapped CInt should be converted.
newtype Failable a
Failable :: CInt -> Failable a

-- | Convert from Failable to target type, throwing an error if the value
--   indicates a failure.
fromFailable :: (CInt -> a) -> Failable a -> Lua a

-- | Throw a Haskell exception if the computation signaled a failure.
throwOnError :: Failable () -> Lua ()

-- | Convert lua boolean to Haskell Bool, throwing an exception if the
--   return value indicates that an error had happened.
boolFromFailable :: Failable LuaBool -> Lua Bool

-- | Registry field under which the special HsLua error indicator is
--   stored.
hsluaErrorRegistryField :: String
instance GHC.Classes.Eq Foreign.Lua.Core.Error.Exception
instance GHC.Show.Show Foreign.Lua.Core.Error.Exception
instance GHC.Exception.Type.Exception Foreign.Lua.Core.Error.Exception
instance GHC.Base.Alternative Foreign.Lua.Core.Types.Lua


-- | Haskell bindings to lua C API functions.
module Foreign.Lua.Core.RawBindings

-- | See <a>lua_close</a>
lua_close :: State -> IO ()

-- | See <a>lua_absindex</a>
lua_absindex :: State -> StackIndex -> IO StackIndex

-- | See <a>lua_gettop</a>
lua_gettop :: State -> IO StackIndex

-- | See <a>lua_settop</a>
lua_settop :: State -> StackIndex -> IO ()

-- | See <a>lua_pushvalue</a>
lua_pushvalue :: State -> StackIndex -> IO ()

-- | See <a>lua_copy</a>
lua_copy :: State -> StackIndex -> StackIndex -> IO ()

-- | See <a>lua_remove</a>
lua_remove :: State -> StackIndex -> IO ()

-- | See <a>lua_insert</a>
lua_insert :: State -> StackIndex -> IO ()

-- | See <a>lua_replace</a>
lua_replace :: State -> StackIndex -> IO ()

-- | See <a>lua_checkstack</a>
lua_checkstack :: State -> CInt -> IO LuaBool

-- | See <a>lua_isnumber</a>
lua_isnumber :: State -> StackIndex -> IO LuaBool

-- | See <a>lua_isinteger</a>
lua_isinteger :: State -> StackIndex -> IO LuaBool

-- | See <a>lua_isstring</a>
lua_isstring :: State -> StackIndex -> IO LuaBool

-- | See <a>lua_iscfunction</a>
lua_iscfunction :: State -> StackIndex -> IO LuaBool

-- | See <a>lua_isuserdata</a>
lua_isuserdata :: State -> StackIndex -> IO LuaBool

-- | See <a>lua_type</a>
lua_type :: State -> StackIndex -> IO TypeCode

-- | See <a>lua_typename</a>
lua_typename :: State -> TypeCode -> IO CString

-- | Wrapper around <a>-- @lua_compare@</a> which catches any
--   <tt>longjmp</tt>s.
hslua_compare :: State -> StackIndex -> StackIndex -> CInt -> IO (Failable LuaBool)

-- | See <a>lua_rawequal</a>
lua_rawequal :: State -> StackIndex -> StackIndex -> IO LuaBool

-- | See <a>lua_toboolean</a>
lua_toboolean :: State -> StackIndex -> IO LuaBool

-- | See <a>lua_tocfunction</a>
lua_tocfunction :: State -> StackIndex -> IO CFunction

-- | See <a>lua_tointegerx</a>
lua_tointegerx :: State -> StackIndex -> Ptr LuaBool -> IO Integer

-- | See <a>lua_tonumberx</a>
lua_tonumberx :: State -> StackIndex -> Ptr LuaBool -> IO Number

-- | See <a>lua_tolstring</a>
lua_tolstring :: State -> StackIndex -> Ptr CSize -> IO (Ptr CChar)

-- | See <a>lua_topointer</a>
lua_topointer :: State -> StackIndex -> IO (Ptr ())

-- | See <a>lua_tothread</a>
lua_tothread :: State -> StackIndex -> IO State

-- | See <a>lua_touserdata</a>
lua_touserdata :: State -> StackIndex -> IO (Ptr a)

-- | See <a>lua_rawlen</a>
lua_rawlen :: State -> StackIndex -> IO CSize

-- | See <a>lua_pushnil</a>
lua_pushnil :: State -> IO ()

-- | See <a>lua_pushnumber</a>
lua_pushnumber :: State -> Number -> IO ()

-- | See <a>lua_pushinteger</a>
lua_pushinteger :: State -> Integer -> IO ()

-- | See <a>lua_pushlstring</a>
lua_pushlstring :: State -> Ptr CChar -> CSize -> IO ()

-- | See <a>lua_pushcclosure</a>
lua_pushcclosure :: State -> CFunction -> NumArgs -> IO ()

-- | See <a>lua_pushboolean</a>
lua_pushboolean :: State -> LuaBool -> IO ()

-- | See <a>lua_pushlightuserdata</a>
lua_pushlightuserdata :: State -> Ptr a -> IO ()

-- | See <a>lua_pushthread</a>
lua_pushthread :: State -> IO CInt

-- | Wrapper around <a>-- @lua_gettable@</a> which catches any
--   <tt>longjmp</tt>s.
hslua_gettable :: State -> StackIndex -> IO (Failable ())

-- | See <a>lua_rawget</a>
lua_rawget :: State -> StackIndex -> IO ()

-- | See <a>lua_rawgeti</a>
lua_rawgeti :: State -> StackIndex -> Integer -> IO ()

-- | See <a>lua_createtable</a>
lua_createtable :: State -> CInt -> CInt -> IO ()

-- | See <a>lua_newuserdata</a>
lua_newuserdata :: State -> CSize -> IO (Ptr ())

-- | See <a>lua_getmetatable</a>
lua_getmetatable :: State -> StackIndex -> IO LuaBool

-- | Wrapper around <a>-- @lua_getglobal@</a> which catches any
--   <tt>longjmp</tt>s.
hslua_getglobal :: State -> CString -> CSize -> IO (Failable ())

-- | Wrapper around <a>-- @lua_settable@</a> which catches any
--   <tt>longjmp</tt>s.
hslua_settable :: State -> StackIndex -> IO (Failable ())

-- | See <a>lua_rawset</a>
lua_rawset :: State -> StackIndex -> IO ()

-- | See <a>lua_rawseti</a>
lua_rawseti :: State -> StackIndex -> Integer -> IO ()

-- | See <a>lua_setmetatable</a>
lua_setmetatable :: State -> StackIndex -> IO ()

-- | Wrapper around <a>-- @lua_setglobal@</a> which catches any
--   <tt>longjmp</tt>s.
hslua_setglobal :: State -> CString -> CSize -> IO (Failable ())

-- | See <a>lua_pcall</a>
lua_pcall :: State -> NumArgs -> NumResults -> StackIndex -> IO StatusCode

-- | See <a>lua_load</a>
lua_load :: State -> Reader -> Ptr () -> CString -> CString -> IO StatusCode

-- | See <a>lua_status</a>
lua_status :: State -> IO StatusCode

-- | See <a>lua_gc</a>
lua_gc :: State -> CInt -> CInt -> IO CInt

-- | Wrapper around <a>-- @lua_next@</a> which catches any
--   <tt>longjmp</tt>s.
hslua_next :: State -> StackIndex -> IO (Failable LuaBool)

-- | Wrapper around <a>-- @lua_concat@</a> which catches any
--   <tt>longjmp</tt>s.
hslua_concat :: State -> NumArgs -> IO (Failable ())
lua_pushglobaltable :: State -> IO ()

-- | See <a>luaL_openlibs</a>
luaL_openlibs :: State -> IO ()

-- | Point to function opening the base library.
lua_open_base_ptr :: CFunction

-- | Point to function opening the table library.
lua_open_table_ptr :: CFunction

-- | Point to function opening the io library.
lua_open_io_ptr :: CFunction

-- | Point to function opening the os library.
lua_open_os_ptr :: CFunction

-- | Point to function opening the string library.
lua_open_string_ptr :: CFunction

-- | Point to function opening the math library.
lua_open_math_ptr :: CFunction

-- | Point to function opening the debug library.
lua_open_debug_ptr :: CFunction

-- | Point to function opening the package library.
lua_open_package_ptr :: CFunction


-- | Core Lua API. This module provides thin wrappers around the respective
--   functions of the Lua C API. C function 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 Foreign.Lua.Core

-- | 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 Lua a
Lua :: ReaderT State IO a -> Lua a
[unLua] :: Lua a -> ReaderT State IO a

-- | Run lua computation with custom lua state. Errors are left unhandled,
--   the caller of this function is responsible to catch lua errors.
runWith :: State -> Lua a -> IO a
liftIO :: MonadIO m => IO a -> m a

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

-- | 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, <tt><tt>gettop</tt></tt> 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 <tt>gettop</tt>. 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.
--   
--   See <a>lua_CFunction</a>.
type CFunction = FunPtr (State -> IO NumResults)

-- | The type of integers in Lua.
--   
--   By default this type is <tt><a>Int64</a></tt>, but that can be changed
--   to different values in lua. (See <tt>LUA_INT_TYPE</tt> in
--   <tt>luaconf.h</tt>.)
--   
--   See <a>lua_Integer</a>.
newtype Integer
Integer :: Int64 -> Integer

-- | The type of floats in Lua.
--   
--   By default this type is <tt><a>Double</a></tt>, but that can be
--   changed in Lua to a single float or a long double. (See
--   <tt>LUA_FLOAT_TYPE</tt> in <tt>luaconf.h</tt>.)
--   
--   See <a>lua_Number</a>.
newtype Number
Number :: Double -> Number

-- | A stack index
newtype StackIndex
StackIndex :: CInt -> StackIndex
[fromStackIndex] :: StackIndex -> CInt

-- | Stack index of the nth element from the bottom of the stack.
nthFromBottom :: CInt -> StackIndex

-- | Stack index of the nth element from the top of the stack.
nthFromTop :: CInt -> StackIndex

-- | Top of the stack
stackTop :: StackIndex

-- | Bottom of the stack
stackBottom :: StackIndex

-- | The number of arguments expected a function.
newtype NumArgs
NumArgs :: CInt -> NumArgs
[fromNumArgs] :: NumArgs -> CInt

-- | The number of results returned by a function call.
newtype NumResults
NumResults :: CInt -> NumResults
[fromNumResults] :: NumResults -> CInt

-- | Alias for C constant <tt>LUA_MULTRET</tt>. See <a>lua_call</a>.
multret :: NumResults

-- | Alias for C constant <tt>LUA_REGISTRYINDEX</tt>. See <a>Lua
--   registry</a>.
registryindex :: StackIndex

-- | Returns the pseudo-index that represents the <tt>i</tt>-th upvalue of
--   the running function (see <a>§4.4</a> of the Lua 5.3 reference
--   manual).
--   
--   See also: <a>lua_upvalueindex</a>.
upvalueindex :: StackIndex -> StackIndex

-- | An 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 <tt>lua_State *</tt>. See <a>lua_State</a>.
newtype State
State :: Ptr () -> State

-- | Creates a new Lua state. It calls <tt><tt>lua_newstate</tt></tt> with
--   an allocator based on the standard C <tt>realloc</tt> function and
--   then sets a panic function (see <a>§4.6</a> of the Lua 5.3 Reference
--   Manual) that prints an error message to the standard error output in
--   case of fatal errors.
--   
--   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.
--   
--   This is a wrapper function of <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).
absindex :: StackIndex -> Lua 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).
--   
--   See also: <a>lua_gettop</a>.
gettop :: Lua 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.
--   
--   See also: <a>lua_settop</a>.
settop :: StackIndex -> Lua ()

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

-- | 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.
--   
--   See also <a>lua_copy</a> in the lua manual.
copy :: StackIndex -> StackIndex -> Lua ()

-- | 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.
--   
--   See also: <a>lua_insert</a>.
insert :: StackIndex -> Lua ()

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

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

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

-- | 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.
--   
--   This is a wrapper function of <a>lua_checkstack</a>.
checkstack :: Int -> Lua 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

-- | Integer code used to encode the type of a lua value.
newtype TypeCode
TypeCode :: CInt -> TypeCode
[fromTypeCode] :: TypeCode -> CInt

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

-- | Convert numerical code to lua type.
toType :: TypeCode -> 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.
--   
--   See <a>lua_type</a>.
ltype :: StackIndex -> Lua 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>.
--   
--   See also: <a>lua_typename</a>.
typename :: Type -> Lua String

-- | Returns <tt>True</tt> if the value at the given index is a boolean,
--   and <tt>False</tt> otherwise.
--   
--   See also: <a>lua_isboolean</a>.
isboolean :: StackIndex -> Lua Bool

-- | Returns <tt>True</tt> if the value at the given index is a C function,
--   and <tt>False</tt> otherwise.
--   
--   See also: <a>lua_iscfunction</a>.
iscfunction :: StackIndex -> Lua Bool

-- | Returns <tt>True</tt> if the value at the given index is a function
--   (either C or Lua), and <tt>False</tt> otherwise.
--   
--   See also: <a>lua_isfunction</a>.
isfunction :: StackIndex -> Lua 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
--   <tt>False</tt> otherwise.
isinteger :: StackIndex -> Lua Bool

-- | Returns <tt>True</tt> if the value at the given index is a light
--   userdata, and <tt>False</tt> otherwise.
--   
--   See also:
--   &lt;<a>https://www.lua.org/manual/5.3/manual.html#lua_islightuserdata</a>
--   lua_islightuserdata&gt;.
islightuserdata :: StackIndex -> Lua Bool

-- | Returns <tt>True</tt> if the value at the given index is <tt>nil</tt>,
--   and <tt>False</tt> otherwise.
--   
--   See also: <a>lua_isnil</a>.
isnil :: StackIndex -> Lua Bool

-- | Returns <tt>True</tt> if the given index is not valid, and
--   <tt>False</tt> otherwise.
--   
--   See also: <a>lua_isnone</a>.
isnone :: StackIndex -> Lua Bool

-- | Returns <tt>True</tt> if the given index is not valid or if the value
--   at the given index is <tt>nil</tt>, and <tt>False</tt> otherwise.
--   
--   See also: <a>lua_isnoneornil</a>.
isnoneornil :: StackIndex -> Lua Bool

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

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

-- | Returns <tt>True</tt> if the value at the given index is a table, and
--   <tt>False</tt> otherwise.
--   
--   See also: <a>lua_istable</a>.
istable :: StackIndex -> Lua Bool

-- | Returns <tt>True</tt> if the value at the given index is a thread, and
--   <tt>False</tt> otherwise.
--   
--   See also: <a>lua_isthread</a>.
isthread :: StackIndex -> Lua Bool

-- | Returns <tt>True</tt> if the value at the given index is a userdata
--   (either full or light), and <tt>False</tt> otherwise.
--   
--   See also: <a>lua_isuserdata</a>.
isuserdata :: StackIndex -> Lua 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.)
--   
--   See also: <a>lua_toboolean</a>.
toboolean :: StackIndex -> Lua Bool

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

-- | Converts the Lua value at the given acceptable index to the signed
--   integral type <tt><tt>lua_Integer</tt></tt>. 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.3 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.
--   
--   See also: <a>lua_tointeger</a>.
tointeger :: StackIndex -> Lua (Maybe Integer)

-- | Converts the Lua value at the given index to the C type lua_Number.
--   The Lua value must be a number or a string convertible to a number;
--   otherwise, <tt>tonumber</tt> returns <tt><a>Nothing</a></tt>.
--   
--   See <a>lua_tonumber</a>.
tonumber :: StackIndex -> Lua (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.
--   
--   See also: <a>lua_topointer</a>.
topointer :: StackIndex -> Lua (Ptr ())

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

-- | Converts the value at the given index to a Lua thread (represented as
--   lua_State*). This value must be a thread; otherwise, the function
--   returns <tt>Nothing</tt>.
--   
--   See also: <a>lua_tothread</a>.
tothread :: StackIndex -> Lua (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>..
--   
--   See also: <a>lua_touserdata</a>.
touserdata :: StackIndex -> Lua (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.
--   
--   See also: <a>lua_rawlen</a>.
rawlen :: StackIndex -> Lua 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

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

-- | Compares two Lua values. Returns <tt>True</tt> 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 <tt><tt>LuaComparerOp</tt></tt>:
--   
--   OpEQ: compares for equality (==) OpLT: compares for less than (&lt;)
--   OpLE: compares for less or equal (&lt;=)
--   
--   This is a wrapper function of <a>lua_compare</a>.
compare :: StackIndex -> StackIndex -> RelationalOperator -> Lua Bool

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

-- | Tests whether the object under the first index is smaller than that
--   under the second. Uses <tt><a>compare</a></tt> internally.
lessthan :: StackIndex -> StackIndex -> Lua 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.
--   
--   See also: <a>lua_rawequal</a>.
rawequal :: StackIndex -> StackIndex -> Lua Bool

-- | Pushes a boolean value with the given value onto the stack.
--   
--   See also: <a>lua_pushboolean</a>.
pushboolean :: Bool -> Lua ()

-- | 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>)
--   
--   See also: <a>lua_pushcfunction</a>.
pushcfunction :: CFunction -> Lua ()

-- | 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 lua_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. lua_pushcclosure also
--   pops these values from the stack.
--   
--   The maximum value for <tt>n</tt> is 255.
--   
--   See also: <a>lua_pushcclosure</a>.
pushcclosure :: CFunction -> NumArgs -> Lua ()

-- | Pushes an integer with with the given value onto the stack.
--   
--   See also: <a>lua_pushinteger</a>.
pushinteger :: Integer -> Lua ()

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

-- | Pushes a nil value onto the stack.
--   
--   See <a>lua_pushnil</a>.
pushnil :: Lua ()

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

-- | Pushes the zero-terminated string pointed to by s onto the stack. Lua
--   makes (or reuses) an internal copy of the given string, so the memory
--   at s can be freed or reused immediately after the function returns.
--   
--   See also:
--   &lt;<a>https://www.lua.org/manual/5.3/manual.html#lua_pushstring</a>
--   lua_pushstring&gt;.
pushstring :: ByteString -> Lua ()

-- | 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.
--   
--   See also: <a>lua_pushthread</a>.
pushthread :: Lua Bool

-- | Pushes onto the stack the value of the global <tt>name</tt>.
--   
--   Errors on the Lua side are caught and rethrown as
--   <tt><a>Exception</a></tt>.
--   
--   Wrapper of <a>lua_getglobal</a>.
getglobal :: String -> Lua ()

-- | 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 as
--   <tt><a>Exception</a></tt>.
--   
--   See also: <a>lua_gettable</a>.
gettable :: StackIndex -> Lua ()

-- | 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 caught and rethrown as
--   <tt><a>Exception</a></tt>.
--   
--   See also: <a>lua_getfield</a>.
getfield :: StackIndex -> String -> Lua ()

-- | Similar to <tt><a>gettable</a></tt>, but does a raw access (i.e.,
--   without metamethods).
--   
--   See also: <a>lua_rawget</a>.
rawget :: StackIndex -> Lua ()

-- | 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.
--   
--   See also: <a>lua_rawgeti</a>.
rawgeti :: StackIndex -> Integer -> Lua ()

-- | 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.
--   
--   This is a wrapper for function <a>lua_createtable</a>.
createtable :: Int -> Int -> Lua ()

-- | 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 :: Lua ()

-- | This function allocates a new block of memory with the given size,
--   pushes onto the stack a new full userdata with the block address, and
--   returns this address. The host program can freely use this memory.
--   
--   See also: <a>lua_newuserdata</a>.
newuserdata :: Int -> Lua (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.
--   
--   See also: <a>lua_getmetatable</a>.
getmetatable :: StackIndex -> Lua Bool

-- | 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
--   <tt><a>Exception</a></tt>.
--   
--   See also: <a>lua_setglobal</a>.
setglobal :: String -> Lua ()

-- | 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.3 Reference Manual).
--   
--   Errors on the Lua side are caught and rethrown as a
--   <tt><a>Exception</a></tt>.
--   
--   See also: <a>lua_settable</a>.
settable :: StackIndex -> Lua ()

-- | 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.3 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 :: StackIndex -> String -> Lua ()

-- | Similar to <tt><a>settable</a></tt>, but does a raw assignment (i.e.,
--   without metamethods).
--   
--   See also: <a>lua_rawset</a>.
rawset :: StackIndex -> Lua ()

-- | 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.
--   
--   See also: <a>lua_rawseti</a>.
rawseti :: StackIndex -> Integer -> Lua ()

-- | Pops a table from the stack and sets it as the new metatable for the
--   value at the given index.
--   
--   See also:
--   &lt;<a>https://www.lua.org/manual/5.3/manual.html#lua_setmetatable</a>
--   lua_setmetatable&gt;.
setmetatable :: StackIndex -> Lua ()

-- | 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 cause a <tt><a>Exception</a></tt>
--   to be thrown.
--   
--   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 :: NumArgs -> NumResults -> Lua ()

-- | 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.
--   
--   See <a>lua_pcall</a>.
pcall :: NumArgs -> NumResults -> Maybe StackIndex -> Lua 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><a>ErrGcmm</a></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.9</a>).
--   Note that the <tt>chunkname</tt> is used as a C string, so it may not
--   contain null-bytes.
load :: Reader -> Ptr () -> ByteString -> Lua Status

-- | Loads a ByteString as a Lua chunk.
--   
--   This function returns the same results as <tt><tt>load</tt></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.
--   
--   See <a>luaL_loadbuffer</a>.
loadbuffer :: ByteString -> String -> Lua Status

-- | Loads a file as a Lua chunk. This function uses <tt>lua_load</tt> (see
--   <tt><tt>load</tt></tt>) to load the chunk in the file named filename.
--   The first line in the file is ignored if it starts with a <tt>#</tt>.
--   
--   The string mode works as in function <tt><tt>load</tt></tt>.
--   
--   This function returns the same results as <tt><tt>load</tt></tt>, but
--   it has an extra error code <tt><tt>ErrFile</tt></tt> for file-related
--   errors (e.g., it cannot open or read the file).
--   
--   As <tt><tt>load</tt></tt>, this function only loads the chunk; it does
--   not run it.
--   
--   Note that the file is opened by Haskell, not Lua.
--   
--   See <a>luaL_loadfile</a>.
loadfile :: FilePath -> Lua 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><tt>load</tt></tt>).
--   
--   Also as <tt><tt>load</tt></tt>, this function only loads the chunk; it
--   does not run it.
--   
--   See <a>luaL_loadstring</a>.
loadstring :: ByteString -> Lua 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

-- | error while running a <tt>__gc</tt> metamethod.
ErrGcmm :: Status

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

-- | Convert C integer constant to <tt><tt>LuaStatus</tt></tt>.
toStatus :: StatusCode -> Status

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

-- | Enumeration used by <tt>gc</tt> function.
data GCCONTROL
GCSTOP :: GCCONTROL
GCRESTART :: GCCONTROL
GCCOLLECT :: GCCONTROL
GCCOUNT :: GCCONTROL
GCCOUNTB :: GCCONTROL
GCSTEP :: GCCONTROL
GCSETPAUSE :: GCCONTROL
GCSETSTEPMUL :: GCCONTROL

-- | Controls the garbage collector.
--   
--   This function performs several tasks, according to the value of the
--   parameter what:
--   
--   <ul>
--   <li><tt><a>GCSTOP</a></tt>: stops the garbage collector.</li>
--   <li><tt><a>GCRESTART</a></tt>: restarts the garbage collector.</li>
--   <li><tt><a>GCCOLLECT</a></tt>: performs a full garbage-collection
--   cycle.</li>
--   <li><tt><a>GCCOUNT</a></tt>: returns the current amount of memory (in
--   Kbytes) in use by Lua.</li>
--   <li><tt><a>GCCOUNTB</a></tt>: returns the remainder of dividing the
--   current amount of bytes of memory in use by Lua by 1024.</li>
--   <li><tt><a>GCSTEP</a></tt>: performs an incremental step of garbage
--   collection. The step "size" is controlled by data (larger values mean
--   more steps) in a non-specified way. If you want to control the step
--   size you must experimentally tune the value of data. The function
--   returns 1 if the step finished a garbage-collection cycle.</li>
--   <li><tt>'GCSETPAUSE</tt>': sets data as the new value for the pause of
--   the collector (see §2.10). The function returns the previous value of
--   the pause.</li>
--   <li><tt><a>GCSETSTEPMUL</a></tt>: sets data as the new value for the
--   step multiplier of the collector (see §2.10). The function returns the
--   previous value of the step multiplier.</li>
--   </ul>
--   
--   See <a>lua_gc</a>.
gc :: GCCONTROL -> Int -> Lua 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>.
--   
--   See also: <a>lua_next</a>.
next :: StackIndex -> Lua Bool

-- | This is a convenience function to implement error propagation
--   convention described in <a>Error handling in hslua</a>. hslua doesn't
--   implement <tt>lua_error</tt> function from Lua C API because it's
--   never safe to use. (see <a>Error handling in hslua</a> for details)
error :: Lua 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).
--   
--   This is a wrapper function of <a>lua_concat</a>.
concat :: NumArgs -> Lua ()
pushglobaltable :: Lua ()

-- | Sets the C function <tt>f</tt> as the new value of global
--   <tt>name</tt>.
--   
--   See <a>lua_register</a>.
register :: String -> CFunction -> Lua ()

-- | Pushes Lua's <i>base</i> library onto the stack.
--   
--   See <a>luaopen_base</a>.
openbase :: Lua ()

-- | Pushes Lua's <i>debug</i> library onto the stack.
--   
--   See also: <a>luaopen_debug</a>.
opendebug :: Lua ()

-- | Pushes Lua's <i>io</i> library onto the stack.
--   
--   See also: <a>luaopen_io</a>.
openio :: Lua ()

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

-- | Pushes Lua's <i>math</i> library onto the stack.
--   
--   See also: <a>luaopen_math</a>.
openmath :: Lua ()

-- | Pushes Lua's <i>package</i> library onto the stack.
--   
--   See also: <a>luaopen_package</a>.
openpackage :: Lua ()

-- | Pushes Lua's <i>os</i> library onto the stack.
--   
--   See also: <a>luaopen_os</a>.
openos :: Lua ()

-- | Pushes Lua's <i>string</i> library onto the stack.
--   
--   See also: <a>luaopen_string</a>.
openstring :: Lua ()

-- | Pushes Lua's <i>table</i> library onto the stack.
--   
--   See also: <a>luaopen_table</a>.
opentable :: Lua ()

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

-- | Loads and runs the given file. Note that the filepath is interpreted
--   by Haskell, not Lua. The resulting chunk is named using the UTF8
--   encoded filepath.
dofile :: FilePath -> Lua 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 TypeNil.
getmetafield :: StackIndex -> String -> Lua Type

-- | Pushes onto the stack the metatable associated with name
--   <tt>tname</tt> in the registry (see <tt>newmetatable</tt>)
--   (<tt>nil</tt> if there is no metatable associated with that name).
--   Returns the type of the pushed value.
getmetatable' :: String -> Lua 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 :: StackIndex -> String -> Lua 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.
--   
--   See also: <a>luaL_newmetatable</a>.
newmetatable :: String -> Lua Bool

-- | Converts any Lua value at the given index to a
--   <tt><a>ByteString</a></tt> 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.
tostring' :: StackIndex -> Lua ByteString

-- | Creates and pushes a traceback of the stack L1. If a message is given
--   it appended at the beginning of the traceback. The level parameter
--   tells at which level to start the traceback.
traceback :: State -> Maybe String -> Int -> Lua ()

-- | Reference to a stored value.
data Reference

-- | Reference to a stored value
Reference :: CInt -> Reference

-- | Reference to a nil value
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><tt>refnil</tt></tt>. The constant
--   <tt><tt>noref</tt></tt> is guaranteed to be different from any
--   reference returned by <tt><a>ref</a></tt>.
--   
--   See also: <a>luaL_ref</a>.
ref :: StackIndex -> Lua Reference

-- | Push referenced value from the table at the given index.
getref :: StackIndex -> Reference -> Lua ()

-- | 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.
--   
--   See also: <a>luaL_unref</a>.
unref :: StackIndex -> Reference -> Lua ()

-- | Convert a reference to its C representation.
fromReference :: Reference -> CInt

-- | Create a reference from its C representation.
toReference :: CInt -> Reference

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

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

-- | Key, in the registry, for table of loaded modules.
loadedTableRegistryField :: String

-- | Key, in the registry, for table of preloaded loaders.
preloadTableRegistryField :: String

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

-- | Raise a Lua <tt><a>Exception</a></tt> containing the given error
--   message.
throwException :: String -> Lua a

-- | Catch a Lua <tt><a>Exception</a></tt>.
catchException :: Lua a -> (Exception -> Lua a) -> Lua a

-- | Catch Lua <tt><a>Exception</a></tt>, alter the message and rethrow.
withExceptionMessage :: (String -> String) -> Lua a -> Lua a

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

-- | Convert the object at the top of the stack into a string and throw it
--   as an <tt><a>Exception</a></tt>.
throwTopMessage :: Lua a


-- | Sending haskell objects to the lua stack.
module Foreign.Lua.Types.Pushable

-- | A value that can be pushed to the Lua stack.
class Pushable a

-- | Pushes a value onto Lua stack, casting it into meaningfully nearest
--   Lua type.
push :: Pushable a => a -> Lua ()

-- | Push list as numerically indexed table.
pushList :: Pushable a => [a] -> Lua ()
instance Foreign.Lua.Types.Pushable.Pushable ()
instance Foreign.Lua.Types.Pushable.Pushable Foreign.Lua.Core.Types.Integer
instance Foreign.Lua.Types.Pushable.Pushable Foreign.Lua.Core.Types.Number
instance Foreign.Lua.Types.Pushable.Pushable Data.ByteString.Internal.ByteString
instance Foreign.Lua.Types.Pushable.Pushable GHC.Types.Bool
instance Foreign.Lua.Types.Pushable.Pushable Foreign.Lua.Core.Types.CFunction
instance Foreign.Lua.Types.Pushable.Pushable (GHC.Ptr.Ptr a)
instance Foreign.Lua.Types.Pushable.Pushable Data.Text.Internal.Text
instance Foreign.Lua.Types.Pushable.Pushable Data.ByteString.Lazy.Internal.ByteString
instance Foreign.Lua.Types.Pushable.Pushable GHC.Integer.Type.Integer
instance Foreign.Lua.Types.Pushable.Pushable GHC.Types.Int
instance Foreign.Lua.Types.Pushable.Pushable GHC.Types.Float
instance Foreign.Lua.Types.Pushable.Pushable GHC.Types.Double
instance Foreign.Lua.Types.Pushable.Pushable [GHC.Types.Char]
instance Foreign.Lua.Types.Pushable.Pushable a => Foreign.Lua.Types.Pushable.Pushable [a]
instance (Foreign.Lua.Types.Pushable.Pushable a, Foreign.Lua.Types.Pushable.Pushable b) => Foreign.Lua.Types.Pushable.Pushable (Data.Map.Internal.Map a b)
instance Foreign.Lua.Types.Pushable.Pushable a => Foreign.Lua.Types.Pushable.Pushable (Data.Set.Internal.Set a)
instance (Foreign.Lua.Types.Pushable.Pushable a, Foreign.Lua.Types.Pushable.Pushable b) => Foreign.Lua.Types.Pushable.Pushable (a, b)
instance (Foreign.Lua.Types.Pushable.Pushable a, Foreign.Lua.Types.Pushable.Pushable b, Foreign.Lua.Types.Pushable.Pushable c) => Foreign.Lua.Types.Pushable.Pushable (a, b, c)
instance (Foreign.Lua.Types.Pushable.Pushable a, Foreign.Lua.Types.Pushable.Pushable b, Foreign.Lua.Types.Pushable.Pushable c, Foreign.Lua.Types.Pushable.Pushable d) => Foreign.Lua.Types.Pushable.Pushable (a, b, c, d)
instance (Foreign.Lua.Types.Pushable.Pushable a, Foreign.Lua.Types.Pushable.Pushable b, Foreign.Lua.Types.Pushable.Pushable c, Foreign.Lua.Types.Pushable.Pushable d, Foreign.Lua.Types.Pushable.Pushable e) => Foreign.Lua.Types.Pushable.Pushable (a, b, c, d, e)
instance (Foreign.Lua.Types.Pushable.Pushable a, Foreign.Lua.Types.Pushable.Pushable b, Foreign.Lua.Types.Pushable.Pushable c, Foreign.Lua.Types.Pushable.Pushable d, Foreign.Lua.Types.Pushable.Pushable e, Foreign.Lua.Types.Pushable.Pushable f) => Foreign.Lua.Types.Pushable.Pushable (a, b, c, d, e, f)
instance (Foreign.Lua.Types.Pushable.Pushable a, Foreign.Lua.Types.Pushable.Pushable b, Foreign.Lua.Types.Pushable.Pushable c, Foreign.Lua.Types.Pushable.Pushable d, Foreign.Lua.Types.Pushable.Pushable e, Foreign.Lua.Types.Pushable.Pushable f, Foreign.Lua.Types.Pushable.Pushable g) => Foreign.Lua.Types.Pushable.Pushable (a, b, c, d, e, f, g)
instance (Foreign.Lua.Types.Pushable.Pushable a, Foreign.Lua.Types.Pushable.Pushable b, Foreign.Lua.Types.Pushable.Pushable c, Foreign.Lua.Types.Pushable.Pushable d, Foreign.Lua.Types.Pushable.Pushable e, Foreign.Lua.Types.Pushable.Pushable f, Foreign.Lua.Types.Pushable.Pushable g, Foreign.Lua.Types.Pushable.Pushable h) => Foreign.Lua.Types.Pushable.Pushable (a, b, c, d, e, f, g, h)


-- | Sending haskell objects to the lua stack.
module Foreign.Lua.Types.Peekable

-- | A value that can be read from the Lua stack.
class Peekable a

-- | Check if at index <tt>n</tt> there is a convertible Lua value and if
--   so return it. Throws a <tt><a>Exception</a></tt> otherwise.
peek :: Peekable a => StackIndex -> Lua a

-- | Read a table into a list of pairs.
peekKeyValuePairs :: (Peekable a, Peekable b) => StackIndex -> Lua [(a, b)]

-- | Read a table into a list
peekList :: Peekable a => StackIndex -> Lua [a]

-- | Report the expected and actual type of the value under the given index
--   if conversion failed.
reportValueOnFailure :: String -> (StackIndex -> Lua (Maybe a)) -> StackIndex -> Lua a
instance Foreign.Lua.Types.Peekable.Peekable ()
instance Foreign.Lua.Types.Peekable.Peekable Foreign.Lua.Core.Types.Integer
instance Foreign.Lua.Types.Peekable.Peekable Foreign.Lua.Core.Types.Number
instance Foreign.Lua.Types.Peekable.Peekable Data.ByteString.Internal.ByteString
instance Foreign.Lua.Types.Peekable.Peekable GHC.Types.Bool
instance Foreign.Lua.Types.Peekable.Peekable Foreign.Lua.Core.Types.CFunction
instance Foreign.Lua.Types.Peekable.Peekable (GHC.Ptr.Ptr a)
instance Foreign.Lua.Types.Peekable.Peekable Foreign.Lua.Core.Types.State
instance Foreign.Lua.Types.Peekable.Peekable Data.Text.Internal.Text
instance Foreign.Lua.Types.Peekable.Peekable Data.ByteString.Lazy.Internal.ByteString
instance Foreign.Lua.Types.Peekable.Peekable GHC.Integer.Type.Integer
instance Foreign.Lua.Types.Peekable.Peekable GHC.Types.Int
instance Foreign.Lua.Types.Peekable.Peekable GHC.Types.Float
instance Foreign.Lua.Types.Peekable.Peekable GHC.Types.Double
instance Foreign.Lua.Types.Peekable.Peekable [GHC.Types.Char]
instance Foreign.Lua.Types.Peekable.Peekable a => Foreign.Lua.Types.Peekable.Peekable [a]
instance (GHC.Classes.Ord a, Foreign.Lua.Types.Peekable.Peekable a, Foreign.Lua.Types.Peekable.Peekable b) => Foreign.Lua.Types.Peekable.Peekable (Data.Map.Internal.Map a b)
instance (GHC.Classes.Ord a, Foreign.Lua.Types.Peekable.Peekable a) => Foreign.Lua.Types.Peekable.Peekable (Data.Set.Internal.Set a)
instance (Foreign.Lua.Types.Peekable.Peekable a, Foreign.Lua.Types.Peekable.Peekable b) => Foreign.Lua.Types.Peekable.Peekable (a, b)
instance (Foreign.Lua.Types.Peekable.Peekable a, Foreign.Lua.Types.Peekable.Peekable b, Foreign.Lua.Types.Peekable.Peekable c) => Foreign.Lua.Types.Peekable.Peekable (a, b, c)
instance (Foreign.Lua.Types.Peekable.Peekable a, Foreign.Lua.Types.Peekable.Peekable b, Foreign.Lua.Types.Peekable.Peekable c, Foreign.Lua.Types.Peekable.Peekable d) => Foreign.Lua.Types.Peekable.Peekable (a, b, c, d)
instance (Foreign.Lua.Types.Peekable.Peekable a, Foreign.Lua.Types.Peekable.Peekable b, Foreign.Lua.Types.Peekable.Peekable c, Foreign.Lua.Types.Peekable.Peekable d, Foreign.Lua.Types.Peekable.Peekable e) => Foreign.Lua.Types.Peekable.Peekable (a, b, c, d, e)
instance (Foreign.Lua.Types.Peekable.Peekable a, Foreign.Lua.Types.Peekable.Peekable b, Foreign.Lua.Types.Peekable.Peekable c, Foreign.Lua.Types.Peekable.Peekable d, Foreign.Lua.Types.Peekable.Peekable e, Foreign.Lua.Types.Peekable.Peekable f) => Foreign.Lua.Types.Peekable.Peekable (a, b, c, d, e, f)
instance (Foreign.Lua.Types.Peekable.Peekable a, Foreign.Lua.Types.Peekable.Peekable b, Foreign.Lua.Types.Peekable.Peekable c, Foreign.Lua.Types.Peekable.Peekable d, Foreign.Lua.Types.Peekable.Peekable e, Foreign.Lua.Types.Peekable.Peekable f, Foreign.Lua.Types.Peekable.Peekable g) => Foreign.Lua.Types.Peekable.Peekable (a, b, c, d, e, f, g)
instance (Foreign.Lua.Types.Peekable.Peekable a, Foreign.Lua.Types.Peekable.Peekable b, Foreign.Lua.Types.Peekable.Peekable c, Foreign.Lua.Types.Peekable.Peekable d, Foreign.Lua.Types.Peekable.Peekable e, Foreign.Lua.Types.Peekable.Peekable f, Foreign.Lua.Types.Peekable.Peekable g, Foreign.Lua.Types.Peekable.Peekable h) => Foreign.Lua.Types.Peekable.Peekable (a, b, c, d, e, f, g, h)


-- | Convenience functions to convert Haskell values into Lua userdata.
--   
--   The main purpose of this module is to allow fast and simple creation
--   of instances for <tt><tt>Peekable</tt></tt> and
--   <tt><tt>Pushable</tt></tt>. E.g., given a data type Person
--   
--   <pre>
--   data Person = Person { name :: String, age :: Int }
--      deriving (Eq, Show, Typeable, Data)
--   </pre>
--   
--   we can simply do
--   
--   <pre>
--   instance Lua.Peekable Person where
--       safePeek = safePeekAny
--   
--   instance Lua.Pushable Person where
--       push = pushAny
--   </pre>
--   
--   The other functions can be used to exert more control over the
--   userdata wrapping and unwrapping process.
module Foreign.Lua.Userdata

-- | Push data by wrapping it into a userdata object.
pushAny :: Data a => a -> Lua ()

-- | Push data by wrapping it into a userdata object, using the object at
--   the top of the stack after performing the given operation as
--   metatable.
pushAnyWithMetatable :: Lua () -> a -> Lua ()

-- | Retrieve data which has been pushed with <tt><a>pushAny</a></tt>.
toAny :: Data a => StackIndex -> Lua (Maybe a)

-- | Retrieve data which has been pushed with
--   <tt><a>pushAnyWithMetatable</a></tt>, where *name* must is the value
--   of the <tt>__name</tt> field of the metatable.
toAnyWithName :: StackIndex -> String -> Lua (Maybe a)

-- | Retrieve Haskell data which was pushed to Lua as userdata.
peekAny :: Data a => StackIndex -> Lua a

-- | Push the metatable used to define the behavior of the given value in
--   Lua. The table will be created if it doesn't exist yet.
ensureUserdataMetatable :: String -> Lua () -> Lua ()

-- | Return the default name for userdata to be used when wrapping an
--   object as the given type as userdata. The argument is never evaluated.
metatableName :: Data a => a -> String


-- | Types for working with Lua.
module Foreign.Lua.Types


-- | HsLua utility functions.
module Foreign.Lua.Util

-- | Like <tt>getglobal</tt>, but knows about packages and nested tables.
--   E.g.
--   
--   <pre>
--   getglobal' "math.sin"
--   </pre>
--   
--   will return the function <tt>sin</tt> in package <tt>math</tt>.
getglobal' :: String -> Lua ()

-- | Like <tt>setglobal</tt>, but knows about packages and nested tables.
--   E.g.
--   
--   <pre>
--   pushstring "0.9.4"
--   setglobal' "mypackage.version"
--   </pre>
--   
--   All tables and fields, except for the last field, must exist.
setglobal' :: String -> Lua ()

-- | 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 :: Lua 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 :: Lua a -> IO (Either Exception a)

-- | Raise a Lua error, using the given value as the error object.
raiseError :: Pushable a => a -> Lua NumResults

-- | 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.
newtype Optional a
Optional :: Maybe a -> Optional a
[fromOptional] :: Optional a -> Maybe a

-- | Try to convert the value at the given stack index to a Haskell value.
--   Returns <tt>Left</tt> with an error message on failure.
peekEither :: Peekable a => StackIndex -> Lua (Either String a)

-- | Get a value by retrieving a String from Lua, then using
--   <tt><a>readMaybe</a></tt> to convert the String into a Haskell value.
peekRead :: Read a => StackIndex -> Lua a

-- | Get, then pop the value at the top of the stack. The pop operation is
--   executed even if the retrieval operation failed.
popValue :: Peekable a => Lua a
instance Foreign.Lua.Types.Peekable.Peekable a => Foreign.Lua.Types.Peekable.Peekable (Foreign.Lua.Util.Optional a)
instance Foreign.Lua.Types.Pushable.Pushable a => Foreign.Lua.Types.Pushable.Pushable (Foreign.Lua.Util.Optional a)


-- | Call haskell functions from Lua, and vice versa.
module Foreign.Lua.FunctionCalling

-- | A value that can be read from the Lua stack.
class Peekable a

-- | Check if at index <tt>n</tt> there is a convertible Lua value and if
--   so return it. Throws a <tt><a>Exception</a></tt> otherwise.
peek :: Peekable a => StackIndex -> Lua a

-- | Helper class used to make lua functions useable from haskell
class LuaCallFunc a
callFunc' :: LuaCallFunc a => String -> Lua () -> NumArgs -> a

-- | Operations and functions that can be pushed to the Lua stack. This is
--   a helper function not intended to be used directly. Use the
--   <tt><a>toHaskellFunction</a></tt> wrapper instead.
class ToHaskellFunction a

-- | Helper function, called by <tt><a>toHaskellFunction</a></tt>
toHsFun :: ToHaskellFunction a => StackIndex -> a -> Lua NumResults

-- | Haskell function that can be called from Lua.
type HaskellFunction = Lua NumResults

-- | A value that can be pushed to the Lua stack.
class Pushable a

-- | Pushes a value onto Lua stack, casting it into meaningfully nearest
--   Lua type.
push :: Pushable a => a -> Lua ()

-- | Type of raw Haskell functions that can be made into <a>CFunction</a>s.
type PreCFunction = State -> IO NumResults

-- | Convert a Haskell function to Lua function. Any Haskell function can
--   be converted provided that:
--   
--   <ul>
--   <li>all arguments are instances of <tt><a>Peekable</a></tt></li>
--   <li>return type is <tt>Lua a</tt>, where <tt>a</tt> is an instance of
--   <tt><a>Pushable</a></tt></li>
--   </ul>
--   
--   Any <tt><a>Exception</a></tt> will be converted to a string and
--   returned as Lua error.
--   
--   <i>Important</i>: this does <b>not</b> catch exceptions other than
--   <tt><a>Exception</a></tt>; exception handling must be done by the
--   converted 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
--   <tt><tt>MonadCatch</tt></tt> and <tt><a>Pushable</a></tt>:
--   
--   <pre>
--   toHaskellFunction (myFun `catchM` (\e -&gt; raiseError (e :: FooException)))
--   </pre>
toHaskellFunction :: ToHaskellFunction a => a -> HaskellFunction

-- | Call a Lua function. Use as:
--   
--   <pre>
--   v &lt;- callfunc "proc" "abc" (1::Int) (5.0::Double)
--   </pre>
callFunc :: LuaCallFunc a => String -> a

-- | Free function pointer created with <tt>newcfunction</tt>.
freeCFunction :: CFunction -> Lua ()

-- | Create new foreign Lua function. Function created can be called by Lua
--   engine. Remeber to free the pointer with <tt>freecfunction</tt>.
newCFunction :: ToHaskellFunction a => a -> Lua CFunction

-- | Pushes Haskell function as a callable userdata. All values created
--   will be garbage collected. Use as:
--   
--   <pre>
--   pushHaskellFunction myfun
--   setglobal "myfun"
--   </pre>
--   
--   Error conditions should be indicated by raising a Lua
--   <tt><a>Exception</a></tt> or by returning the result of
--   <tt><a>error</a></tt>.
pushHaskellFunction :: ToHaskellFunction a => a -> Lua ()

-- | Imports a Haskell function and registers it at global name.
registerHaskellFunction :: ToHaskellFunction a => String -> a -> Lua ()
instance Foreign.Lua.Types.Peekable.Peekable a => Foreign.Lua.FunctionCalling.LuaCallFunc (Foreign.Lua.Core.Types.Lua a)
instance (Foreign.Lua.Types.Pushable.Pushable a, Foreign.Lua.FunctionCalling.LuaCallFunc b) => Foreign.Lua.FunctionCalling.LuaCallFunc (a -> b)
instance Foreign.Lua.FunctionCalling.ToHaskellFunction Foreign.Lua.FunctionCalling.HaskellFunction
instance Foreign.Lua.Types.Pushable.Pushable a => Foreign.Lua.FunctionCalling.ToHaskellFunction (Foreign.Lua.Core.Types.Lua a)
instance (Foreign.Lua.Types.Peekable.Peekable a, Foreign.Lua.FunctionCalling.ToHaskellFunction b) => Foreign.Lua.FunctionCalling.ToHaskellFunction (a -> b)


-- | Utility functions for HsLua modules.
module Foreign.Lua.Module

-- | Load a module, defined by a Haskell action, under the given name.
--   
--   Similar to <tt>luaL_required</tt>: After checking "loaded" table,
--   calls <tt>pushMod</tt> to push a module to the stack, and registers
--   the result in <tt>package.loaded</tt> table.
--   
--   The <tt>pushMod</tt> function must push exactly one element to the top
--   of the stack. This is not checked, but failure to do so will lead to
--   problems. Lua's <tt>package</tt> module must have been loaded by the
--   time this function is invoked.
--   
--   Leaves a copy of the module on the stack.
requirehs :: String -> Lua () -> Lua ()

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

-- | Add a string-indexed field to the table at the top of the stack.
addfield :: Pushable a => String -> a -> Lua ()

-- | Attach a function to the table at the top of the stack, using the
--   given name.
addfunction :: ToHaskellFunction a => String -> a -> Lua ()

-- | Create a new module (i.e., a Lua table).
create :: Lua ()


-- | Bindings, functions, and utilities enabling the integration of a Lua
--   interpreter into a haskell project.
--   
--   Basic access to the Lua API is provided by
--   '<tt>Foreign.Lua.Core</tt>'.
module Foreign.Lua

-- | A value that can be read from the Lua stack.
class Peekable a

-- | Check if at index <tt>n</tt> there is a convertible Lua value and if
--   so return it. Throws a <tt><a>Exception</a></tt> otherwise.
peek :: Peekable a => StackIndex -> Lua a

-- | Try to convert the value at the given stack index to a Haskell value.
--   Returns <tt>Left</tt> with an error message on failure.
peekEither :: Peekable a => StackIndex -> Lua (Either String a)

-- | Read a table into a list
peekList :: Peekable a => StackIndex -> Lua [a]

-- | Read a table into a list of pairs.
peekKeyValuePairs :: (Peekable a, Peekable b) => StackIndex -> Lua [(a, b)]

-- | Get a value by retrieving a String from Lua, then using
--   <tt><a>readMaybe</a></tt> to convert the String into a Haskell value.
peekRead :: Read a => StackIndex -> Lua a

-- | Retrieve Haskell data which was pushed to Lua as userdata.
peekAny :: Data a => StackIndex -> Lua a

-- | A value that can be pushed to the Lua stack.
class Pushable a

-- | Pushes a value onto Lua stack, casting it into meaningfully nearest
--   Lua type.
push :: Pushable a => a -> Lua ()

-- | Push list as numerically indexed table.
pushList :: Pushable a => [a] -> Lua ()

-- | Push data by wrapping it into a userdata object.
pushAny :: Data a => a -> Lua ()

-- | Type of raw Haskell functions that can be made into <a>CFunction</a>s.
type PreCFunction = State -> IO NumResults

-- | Haskell function that can be called from Lua.
type HaskellFunction = Lua NumResults

-- | Operations and functions that can be pushed to the Lua stack. This is
--   a helper function not intended to be used directly. Use the
--   <tt><a>toHaskellFunction</a></tt> wrapper instead.
class ToHaskellFunction a

-- | Helper function, called by <tt><a>toHaskellFunction</a></tt>
toHsFun :: ToHaskellFunction a => StackIndex -> a -> Lua NumResults

-- | Convert a Haskell function to Lua function. Any Haskell function can
--   be converted provided that:
--   
--   <ul>
--   <li>all arguments are instances of <tt><a>Peekable</a></tt></li>
--   <li>return type is <tt>Lua a</tt>, where <tt>a</tt> is an instance of
--   <tt><a>Pushable</a></tt></li>
--   </ul>
--   
--   Any <tt><a>Exception</a></tt> will be converted to a string and
--   returned as Lua error.
--   
--   <i>Important</i>: this does <b>not</b> catch exceptions other than
--   <tt><a>Exception</a></tt>; exception handling must be done by the
--   converted 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
--   <tt><tt>MonadCatch</tt></tt> and <tt><a>Pushable</a></tt>:
--   
--   <pre>
--   toHaskellFunction (myFun `catchM` (\e -&gt; raiseError (e :: FooException)))
--   </pre>
toHaskellFunction :: ToHaskellFunction a => a -> HaskellFunction

-- | Call a Lua function. Use as:
--   
--   <pre>
--   v &lt;- callfunc "proc" "abc" (1::Int) (5.0::Double)
--   </pre>
callFunc :: LuaCallFunc a => String -> a

-- | Create new foreign Lua function. Function created can be called by Lua
--   engine. Remeber to free the pointer with <tt>freecfunction</tt>.
newCFunction :: ToHaskellFunction a => a -> Lua CFunction

-- | Free function pointer created with <tt>newcfunction</tt>.
freeCFunction :: CFunction -> Lua ()

-- | Pushes Haskell function as a callable userdata. All values created
--   will be garbage collected. Use as:
--   
--   <pre>
--   pushHaskellFunction myfun
--   setglobal "myfun"
--   </pre>
--   
--   Error conditions should be indicated by raising a Lua
--   <tt><a>Exception</a></tt> or by returning the result of
--   <tt><a>error</a></tt>.
pushHaskellFunction :: ToHaskellFunction a => a -> Lua ()

-- | Imports a Haskell function and registers it at global name.
registerHaskellFunction :: ToHaskellFunction a => String -> a -> Lua ()

-- | 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 :: Lua 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 :: Lua a -> IO (Either Exception a)

-- | Like <tt>getglobal</tt>, but knows about packages and nested tables.
--   E.g.
--   
--   <pre>
--   getglobal' "math.sin"
--   </pre>
--   
--   will return the function <tt>sin</tt> in package <tt>math</tt>.
getglobal' :: String -> Lua ()

-- | Like <tt>setglobal</tt>, but knows about packages and nested tables.
--   E.g.
--   
--   <pre>
--   pushstring "0.9.4"
--   setglobal' "mypackage.version"
--   </pre>
--   
--   All tables and fields, except for the last field, must exist.
setglobal' :: String -> Lua ()

-- | Raise a Lua error, using the given value as the error object.
raiseError :: Pushable a => a -> Lua NumResults

-- | 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.
newtype Optional a
Optional :: Maybe a -> Optional a
[fromOptional] :: Optional a -> Maybe a

-- | Get, then pop the value at the top of the stack. The pop operation is
--   executed even if the retrieval operation failed.
popValue :: Peekable a => Lua a

-- | Load a module, defined by a Haskell action, under the given name.
--   
--   Similar to <tt>luaL_required</tt>: After checking "loaded" table,
--   calls <tt>pushMod</tt> to push a module to the stack, and registers
--   the result in <tt>package.loaded</tt> table.
--   
--   The <tt>pushMod</tt> function must push exactly one element to the top
--   of the stack. This is not checked, but failure to do so will lead to
--   problems. Lua's <tt>package</tt> module must have been loaded by the
--   time this function is invoked.
--   
--   Leaves a copy of the module on the stack.
requirehs :: String -> Lua () -> Lua ()

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

-- | Create a new module (i.e., a Lua table).
create :: Lua ()

-- | Add a string-indexed field to the table at the top of the stack.
addfield :: Pushable a => String -> a -> Lua ()

-- | Attach a function to the table at the top of the stack, using the
--   given name.
addfunction :: ToHaskellFunction a => String -> a -> Lua ()
