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

-- | Type classes for HsLua
--   
--   Type classes for convenient marshalling and calling of Lua functions.
@package hslua-classes
@version 2.3.1

-- | Sending haskell objects to the lua stack.
module HsLua.Class.Peekable

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

-- | Function that retrieves a value from the Lua stack.
safepeek :: (Peekable a, LuaError e) => Peeker e a

-- | Retrieves a Peekable value from the stack. Throws an exception
--   of type e if the given stack index does not a suitable value.
peek :: forall a e. (LuaError e, Peekable a) => StackIndex -> LuaE e a
instance HsLua.Class.Peekable.Peekable GHC.Types.Bool
instance HsLua.Class.Peekable.Peekable Data.ByteString.Lazy.Internal.ByteString
instance HsLua.Class.Peekable.Peekable Data.ByteString.Internal.Type.ByteString
instance HsLua.Class.Peekable.Peekable GHC.Types.Double
instance HsLua.Class.Peekable.Peekable GHC.Types.Float
instance HsLua.Class.Peekable.Peekable Lua.Types.CFunction
instance HsLua.Class.Peekable.Peekable GHC.Types.Int
instance HsLua.Class.Peekable.Peekable GHC.Num.Integer.Integer
instance HsLua.Class.Peekable.Peekable Lua.Types.Integer
instance HsLua.Class.Peekable.Peekable [GHC.Types.Char]
instance HsLua.Class.Peekable.Peekable a => HsLua.Class.Peekable.Peekable [a]
instance (GHC.Classes.Ord a, HsLua.Class.Peekable.Peekable a, HsLua.Class.Peekable.Peekable b) => HsLua.Class.Peekable.Peekable (Data.Map.Internal.Map a b)
instance HsLua.Class.Peekable.Peekable Lua.Types.Number
instance HsLua.Class.Peekable.Peekable (GHC.Internal.Ptr.Ptr a)
instance (GHC.Classes.Ord a, HsLua.Class.Peekable.Peekable a) => HsLua.Class.Peekable.Peekable (Data.Set.Internal.Set a)
instance HsLua.Class.Peekable.Peekable Lua.Types.State
instance HsLua.Class.Peekable.Peekable Data.Text.Internal.Text
instance (HsLua.Class.Peekable.Peekable a, HsLua.Class.Peekable.Peekable b) => HsLua.Class.Peekable.Peekable (a, b)
instance (HsLua.Class.Peekable.Peekable a, HsLua.Class.Peekable.Peekable b, HsLua.Class.Peekable.Peekable c) => HsLua.Class.Peekable.Peekable (a, b, c)
instance (HsLua.Class.Peekable.Peekable a, HsLua.Class.Peekable.Peekable b, HsLua.Class.Peekable.Peekable c, HsLua.Class.Peekable.Peekable d) => HsLua.Class.Peekable.Peekable (a, b, c, d)
instance (HsLua.Class.Peekable.Peekable a, HsLua.Class.Peekable.Peekable b, HsLua.Class.Peekable.Peekable c, HsLua.Class.Peekable.Peekable d, HsLua.Class.Peekable.Peekable e) => HsLua.Class.Peekable.Peekable (a, b, c, d, e)
instance (HsLua.Class.Peekable.Peekable a, HsLua.Class.Peekable.Peekable b, HsLua.Class.Peekable.Peekable c, HsLua.Class.Peekable.Peekable d, HsLua.Class.Peekable.Peekable e, HsLua.Class.Peekable.Peekable f) => HsLua.Class.Peekable.Peekable (a, b, c, d, e, f)
instance (HsLua.Class.Peekable.Peekable a, HsLua.Class.Peekable.Peekable b, HsLua.Class.Peekable.Peekable c, HsLua.Class.Peekable.Peekable d, HsLua.Class.Peekable.Peekable e, HsLua.Class.Peekable.Peekable f, HsLua.Class.Peekable.Peekable g) => HsLua.Class.Peekable.Peekable (a, b, c, d, e, f, g)
instance (HsLua.Class.Peekable.Peekable a, HsLua.Class.Peekable.Peekable b, HsLua.Class.Peekable.Peekable c, HsLua.Class.Peekable.Peekable d, HsLua.Class.Peekable.Peekable e, HsLua.Class.Peekable.Peekable f, HsLua.Class.Peekable.Peekable g, HsLua.Class.Peekable.Peekable h) => HsLua.Class.Peekable.Peekable (a, b, c, d, e, f, g, h)
instance HsLua.Class.Peekable.Peekable ()

-- | Sending haskell objects to the lua stack.
module HsLua.Class.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, LuaError e) => a -> LuaE e ()

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

-- | Call Haskell functions from Lua.
module HsLua.Class.Exposable

-- | Operations and functions that can be pushed to the Lua stack. This is
--   a helper function not intended to be used directly. Use the
--   toHaskellFunction wrapper instead.
class LuaError e => Exposable e a

-- | Helper function, called by toHaskellFunction. Should
--   do a partial application of the argument at the given index to the
--   underlying function. Recurses if necessary, causing further partial
--   applications until the operation is a easily exposable to Lua.
partialApply :: Exposable e a => StackIndex -> a -> Peek e NumResults

-- | Convert a Haskell function to a function type directly exposable to
--   Lua. Any Haskell function can be converted provided that:
--   
--   
--   
- all arguments are instances of Peekable
--   
- return type is LuaE e a, where a is an instance
--   of Pushable
--   
--   
--   Any exception of type e will be caught.
--   
--   Important: this does not catch exceptions other than
--   e; exception handling must be done by the Haskell function.
--   Failure to do so will cause the program to crash.
--   
--   E.g., the following code could be used to handle an Exception of type
--   FooException, if that type is an instance of MonadCatch and
--   Pushable:
--   
--   
--   toHaskellFunction (myFun `catchM` (\e -> raiseError (e :: FooException)))
--   
toHaskellFunction :: Exposable e a => a -> HaskellFunction e

-- | Pushes the given value as a function to the Lua stack.
--   
--   See toHaskellFunction for details.
pushAsHaskellFunction :: Exposable e a => a -> LuaE e ()

-- | Imports a Haskell function and registers it at global name.
registerHaskellFunction :: Exposable e a => Name -> a -> LuaE e ()
instance (HsLua.Class.Peekable.Peekable a, HsLua.Class.Exposable.Exposable e b) => HsLua.Class.Exposable.Exposable e (a -> b)
instance HsLua.Core.Error.LuaError e => HsLua.Class.Exposable.Exposable e (HsLua.Core.Types.HaskellFunction e)
instance (HsLua.Core.Error.LuaError e, HsLua.Class.Pushable.Pushable a) => HsLua.Class.Exposable.Exposable e (HsLua.Core.Types.LuaE e a)
instance (HsLua.Core.Error.LuaError e, HsLua.Class.Pushable.Pushable a) => HsLua.Class.Exposable.Exposable e (HsLua.Marshalling.Peek.Peek e a)

-- | HsLua utility functions.
module HsLua.Class.Util

-- | Raise a Lua error, using the given value as the error object.
raiseError :: (LuaError e, Pushable a) => a -> LuaE e 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 Left with the error on failure.
peekEither :: (LuaError e, Peekable a) => StackIndex -> LuaE e (Either e a)

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

-- | Call Lua functions from Haskell.
module HsLua.Class.Invokable

-- | Helper class used to make Lua functions useable from Haskell.
class Invokable a
addArg :: Invokable a => Name -> (forall e. LuaError e => LuaE e ()) -> NumArgs -> a

-- | Invoke a Lua function. Use as:
--   
--   
--   v <- invoke "proc" "abc" (1::Int) (5.0::Double)
--   
invoke :: Invokable a => Name -> a
instance (HsLua.Class.Pushable.Pushable a, HsLua.Class.Invokable.Invokable b) => HsLua.Class.Invokable.Invokable (a -> b)
instance (HsLua.Core.Error.LuaError e, HsLua.Class.Peekable.Peekable a) => HsLua.Class.Invokable.Invokable (HsLua.Core.Types.LuaE e a)

-- | Convenience module which re-exports all classes and utility functions
--   provided by the hslua-classes package.
module HsLua.Classes

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

-- | Function that retrieves a value from the Lua stack.
safepeek :: (Peekable a, LuaError e) => Peeker e a

-- | Try to convert the value at the given stack index to a Haskell value.
--   Returns Left with the error on failure.
peekEither :: (LuaError e, Peekable a) => StackIndex -> LuaE e (Either e 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, LuaError e) => a -> LuaE e ()

-- | Push list as numerically indexed table.
pushList :: (LuaError e, Pushable a) => [a] -> LuaE e ()

-- | Operations and functions that can be pushed to the Lua stack. This is
--   a helper function not intended to be used directly. Use the
--   toHaskellFunction wrapper instead.
class LuaError e => Exposable e a

-- | Helper function, called by toHaskellFunction. Should
--   do a partial application of the argument at the given index to the
--   underlying function. Recurses if necessary, causing further partial
--   applications until the operation is a easily exposable to Lua.
partialApply :: Exposable e a => StackIndex -> a -> Peek e NumResults

-- | Convert a Haskell function to a function type directly exposable to
--   Lua. Any Haskell function can be converted provided that:
--   
--   
--   
- all arguments are instances of Peekable
--   
- return type is LuaE e a, where a is an instance
--   of Pushable
--   
--   
--   Any exception of type e will be caught.
--   
--   Important: this does not catch exceptions other than
--   e; exception handling must be done by the Haskell function.
--   Failure to do so will cause the program to crash.
--   
--   E.g., the following code could be used to handle an Exception of type
--   FooException, if that type is an instance of MonadCatch and
--   Pushable:
--   
--   
--   toHaskellFunction (myFun `catchM` (\e -> raiseError (e :: FooException)))
--   
toHaskellFunction :: Exposable e a => a -> HaskellFunction e

-- | Invoke a Lua function. Use as:
--   
--   
--   v <- invoke "proc" "abc" (1::Int) (5.0::Double)
--   
invoke :: Invokable a => Name -> a

-- | Imports a Haskell function and registers it at global name.
registerHaskellFunction :: Exposable e a => Name -> a -> LuaE e ()

-- | Raise a Lua error, using the given value as the error object.
raiseError :: (LuaError e, Pushable a) => a -> LuaE e 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 :: (LuaError e, Peekable a) => LuaE e a
