-- 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 <a>Peekable</a> value from the stack. Throws an exception
--   of type <tt>e</tt> 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 ()
instance HsLua.Class.Peekable.Peekable Lua.Types.Integer
instance HsLua.Class.Peekable.Peekable Lua.Types.Number
instance HsLua.Class.Peekable.Peekable Data.ByteString.Internal.Type.ByteString
instance HsLua.Class.Peekable.Peekable GHC.Types.Bool
instance HsLua.Class.Peekable.Peekable Lua.Types.CFunction
instance HsLua.Class.Peekable.Peekable (GHC.Ptr.Ptr a)
instance HsLua.Class.Peekable.Peekable Lua.Types.State
instance HsLua.Class.Peekable.Peekable Data.Text.Internal.Text
instance HsLua.Class.Peekable.Peekable Data.ByteString.Lazy.Internal.ByteString
instance HsLua.Class.Peekable.Peekable GHC.Num.Integer.Integer
instance HsLua.Class.Peekable.Peekable GHC.Types.Int
instance HsLua.Class.Peekable.Peekable GHC.Types.Float
instance HsLua.Class.Peekable.Peekable GHC.Types.Double
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 (GHC.Classes.Ord a, HsLua.Class.Peekable.Peekable a) => HsLua.Class.Peekable.Peekable (Data.Set.Internal.Set a)
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)


-- | 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 ()
instance HsLua.Class.Pushable.Pushable Lua.Types.Integer
instance HsLua.Class.Pushable.Pushable Lua.Types.Number
instance HsLua.Class.Pushable.Pushable Data.ByteString.Internal.Type.ByteString
instance HsLua.Class.Pushable.Pushable GHC.Types.Bool
instance HsLua.Class.Pushable.Pushable Lua.Types.CFunction
instance HsLua.Class.Pushable.Pushable (GHC.Ptr.Ptr a)
instance HsLua.Class.Pushable.Pushable Data.Text.Internal.Text
instance HsLua.Class.Pushable.Pushable Data.ByteString.Lazy.Internal.ByteString
instance HsLua.Class.Pushable.Pushable GHC.Num.Integer.Integer
instance HsLua.Class.Pushable.Pushable GHC.Types.Int
instance HsLua.Class.Pushable.Pushable GHC.Types.Float
instance HsLua.Class.Pushable.Pushable GHC.Types.Double
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 a => HsLua.Class.Pushable.Pushable (Data.Set.Internal.Set a)
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)


-- | 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
--   <tt><a>toHaskellFunction</a></tt> wrapper instead.
class LuaError e => Exposable e a

-- | Helper function, called by <tt><a>toHaskellFunction</a></tt>. 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:
--   
--   <ul>
--   <li>all arguments are instances of <tt><a>Peekable</a></tt></li>
--   <li>return type is <tt>LuaE e a</tt>, where <tt>a</tt> is an instance
--   of <tt><a>Pushable</a></tt></li>
--   </ul>
--   
--   Any exception of type <tt>e</tt> will be caught.
--   
--   <i>Important</i>: this does <b>not</b> catch exceptions other than
--   <tt>e</tt>; 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 <a>MonadCatch</a> and
--   <a>Pushable</a>:
--   
--   <pre>
--   toHaskellFunction (myFun `catchM` (\e -&gt; raiseError (e :: FooException)))
--   </pre>
toHaskellFunction :: forall e a. Exposable e a => a -> HaskellFunction e

-- | Pushes the given value as a function to the Lua stack.
--   
--   See <a>toHaskellFunction</a> for details.
pushAsHaskellFunction :: forall e a. 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.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)
instance (HsLua.Class.Peekable.Peekable a, HsLua.Class.Exposable.Exposable e b) => HsLua.Class.Exposable.Exposable e (a -> b)


-- | 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 <a>Left</a> 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:
--   
--   <pre>
--   v &lt;- invoke "proc" "abc" (1::Int) (5.0::Double)
--   </pre>
invoke :: Invokable a => Name -> a
instance (HsLua.Core.Error.LuaError e, HsLua.Class.Peekable.Peekable a) => HsLua.Class.Invokable.Invokable (HsLua.Core.Types.LuaE e a)
instance (HsLua.Class.Pushable.Pushable a, HsLua.Class.Invokable.Invokable b) => HsLua.Class.Invokable.Invokable (a -> b)


-- | Convenience module which re-exports all classes and utility functions
--   provided by the <i>hslua-classes</i> 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 <a>Left</a> 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
--   <tt><a>toHaskellFunction</a></tt> wrapper instead.
class LuaError e => Exposable e a

-- | Helper function, called by <tt><a>toHaskellFunction</a></tt>. 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:
--   
--   <ul>
--   <li>all arguments are instances of <tt><a>Peekable</a></tt></li>
--   <li>return type is <tt>LuaE e a</tt>, where <tt>a</tt> is an instance
--   of <tt><a>Pushable</a></tt></li>
--   </ul>
--   
--   Any exception of type <tt>e</tt> will be caught.
--   
--   <i>Important</i>: this does <b>not</b> catch exceptions other than
--   <tt>e</tt>; 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 <a>MonadCatch</a> and
--   <a>Pushable</a>:
--   
--   <pre>
--   toHaskellFunction (myFun `catchM` (\e -&gt; raiseError (e :: FooException)))
--   </pre>
toHaskellFunction :: forall e a. Exposable e a => a -> HaskellFunction e

-- | Invoke a Lua function. Use as:
--   
--   <pre>
--   v &lt;- invoke "proc" "abc" (1::Int) (5.0::Double)
--   </pre>
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
