hslua-marshalling-2.3.1: Marshalling of values between Haskell and Lua.

Copyright | © 2020-2024 Albert Krewinkel
License | MIT
Maintainer | Albert Krewinkel <tarleb@hslua.org>
Stability | beta
Portability | Portable
Safe Haskell | None
Language | Haskell2010

HsLua.Marshalling.Peek

Contents

- Lua peek monad

Description

Types for unmarshalling of values from Lua.

Synopsis

- type Peeker e a = StackIndex -> Peek e a
- runPeeker :: Peeker e a -> StackIndex -> LuaE e (Result a)
- data Result a
  - = Success !a
  - | Failure ByteString [Name]
- isFailure :: Result a -> Bool
- failure :: ByteString -> Result a
- force :: LuaError e => Result a -> LuaE e a
- retrieving :: Name -> Peek e a -> Peek e a
- resultToEither :: Result a -> Either String a
- toPeeker :: LuaError e => (StackIndex -> LuaE e a) -> Peeker e a
- newtype Peek e a = Peek {
  - runPeek :: LuaE e (Result a)
  }
- forcePeek :: LuaError e => Peek e a -> LuaE e a
- failPeek :: forall a e. ByteString -> Peek e a
- liftLua :: LuaE e a -> Peek e a
- withContext :: Name -> Peek e a -> Peek e a
- lastly :: Peek e a -> LuaE e b -> Peek e a
- cleanup :: Peek e a -> Peek e a

# Documentation

type Peeker e a = StackIndex -> Peek e a Source #

Function to retrieve a value from Lua's stack.

runPeeker :: Peeker e a -> StackIndex -> LuaE e (Result a) Source #

Runs the peeker function.

data Result a Source #

Record to keep track of failure contexts while retrieving objects from the Lua stack.

Constructors

Success !a |
Failure ByteString [Name] | Error message and stack of contexts

#### Instances

Instances details

Alternative Result Source # |
Instance details Defined in HsLua.Marshalling.Peek Methods empty :: Result a Source # (<|>) :: Result a -> Result a -> Result a Source # some :: Result a -> Result [a] Source # many :: Result a -> Result [a] Source #
Applicative Result Source # |
Instance details Defined in HsLua.Marshalling.Peek Methods pure :: a -> Result a Source # (<*>) :: Result (a -> b) -> Result a -> Result b Source # liftA2 :: (a -> b -> c) -> Result a -> Result b -> Result c Source # (*>) :: Result a -> Result b -> Result b Source # (<*) :: Result a -> Result b -> Result a Source #
Functor Result Source # |
Instance details Defined in HsLua.Marshalling.Peek Methods fmap :: (a -> b) -> Result a -> Result b Source # (<$) :: a -> Result b -> Result a Source #
Monad Result Source # |
Instance details Defined in HsLua.Marshalling.Peek Methods (>>=) :: Result a -> (a -> Result b) -> Result b Source # (>>) :: Result a -> Result b -> Result b Source # return :: a -> Result a Source #
MonadPlus Result Source # |
Instance details Defined in HsLua.Marshalling.Peek Methods mzero :: Result a Source # mplus :: Result a -> Result a -> Result a Source #
MonadFail Result Source # |
Instance details Defined in HsLua.Marshalling.Peek Methods fail :: String -> Result a Source #
Foldable Result Source # |

Instance details

Defined in HsLua.Marshalling.Peek

Methods

fold :: Monoid m => Result m -> m Source #

foldMap :: Monoid m => (a -> m) -> Result a -> m Source #

foldMap' :: Monoid m => (a -> m) -> Result a -> m Source #

foldr :: (a -> b -> b) -> b -> Result a -> b Source #

foldr' :: (a -> b -> b) -> b -> Result a -> b Source #

foldl :: (b -> a -> b) -> b -> Result a -> b Source #

foldl' :: (b -> a -> b) -> b -> Result a -> b Source #

foldr1 :: (a -> a -> a) -> Result a -> a Source #

foldl1 :: (a -> a -> a) -> Result a -> a Source #

toList :: Result a -> [a] Source #

null :: Result a -> Bool Source #

length :: Result a -> Int Source #

elem :: Eq a => a -> Result a -> Bool Source #

maximum :: Ord a => Result a -> a Source #

minimum :: Ord a => Result a -> a Source #

sum :: Num a => Result a -> a Source #

product :: Num a => Result a -> a Source #

Traversable Result Source # |
Instance details Defined in HsLua.Marshalling.Peek Methods traverse :: Applicative f => (a -> f b) -> Result a -> f (Result b) Source # sequenceA :: Applicative f => Result (f a) -> f (Result a) Source # mapM :: Monad m => (a -> m b) -> Result a -> m (Result b) Source # sequence :: Monad m => Result (m a) -> m (Result a) Source #
Show a => Show (Result a) Source # |
Instance details Defined in HsLua.Marshalling.Peek Methods showsPrec :: Int -> Result a -> ShowS Source # show :: Result a -> String Source # showList :: [Result a] -> ShowS Source #
Eq a => Eq (Result a) Source # |
Instance details Defined in HsLua.Marshalling.Peek Methods (==) :: Result a -> Result a -> Bool Source # (/=) :: Result a -> Result a -> Bool Source #

isFailure :: Result a -> Bool Source #

Returns `True` iff the peek result is a Failure.

failure :: ByteString -> Result a Source #

Create a peek failure record from an error message.

force :: LuaError e => Result a -> LuaE e a Source #

Force creation of an unwrapped result, throwing an exception if that's not possible.

retrieving :: Name -> Peek e a -> Peek e a Source #

Add context information to the peek traceback stack.

resultToEither :: Result a -> Either String a Source #

Converts a Result into an Either, where `Left` holds the reportable string in case of an failure.

toPeeker :: LuaError e => (StackIndex -> LuaE e a) -> Peeker e a Source #

Converts an old peek funtion to a `Peeker`.

# Lua peek monad

newtype Peek e a Source #

Lua operation with an additional failure mode that can stack errors from different contexts; errors are not based on exceptions).

Constructors

Peek |

Fields

- runPeek :: LuaE e (Result a)

#### Instances

Instances details

Alternative (Peek e) Source # |
Instance details Defined in HsLua.Marshalling.Peek Methods empty :: Peek e a Source # (<|>) :: Peek e a -> Peek e a -> Peek e a Source # some :: Peek e a -> Peek e [a] Source # many :: Peek e a -> Peek e [a] Source #
Applicative (Peek e) Source # |
Instance details Defined in HsLua.Marshalling.Peek Methods pure :: a -> Peek e a Source # (<*>) :: Peek e (a -> b) -> Peek e a -> Peek e b Source # liftA2 :: (a -> b -> c) -> Peek e a -> Peek e b -> Peek e c Source # (*>) :: Peek e a -> Peek e b -> Peek e b Source # (<*) :: Peek e a -> Peek e b -> Peek e a Source #
Functor (Peek e) Source # |
Instance details Defined in HsLua.Marshalling.Peek Methods fmap :: (a -> b) -> Peek e a -> Peek e b Source # (<$) :: a -> Peek e b -> Peek e a Source #
Monad (Peek e) Source # |
Instance details Defined in HsLua.Marshalling.Peek Methods (>>=) :: Peek e a -> (a -> Peek e b) -> Peek e b Source # (>>) :: Peek e a -> Peek e b -> Peek e b Source # return :: a -> Peek e a Source #
MonadPlus (Peek e) Source # |
Instance details Defined in HsLua.Marshalling.Peek Methods mzero :: Peek e a Source # mplus :: Peek e a -> Peek e a -> Peek e a Source #
MonadFail (Peek e) Source # |
Instance details Defined in HsLua.Marshalling.Peek Methods fail :: String -> Peek e a Source #

forcePeek :: LuaError e => Peek e a -> LuaE e a Source #

Converts a Peek action into a LuaE action, throwing an exception in case of a peek failure.

failPeek :: forall a e. ByteString -> Peek e a Source #

Fails the peek operation.

liftLua :: LuaE e a -> Peek e a Source #

Lifts a Lua operation into the Peek monad.

withContext :: Name -> Peek e a -> Peek e a Source #

Transform the result using the given function.

lastly :: Peek e a -> LuaE e b -> Peek e a Source #

Runs the peek action and Lua action in sequence, even if the peek action fails.

cleanup :: Peek e a -> Peek e a Source #

Runs the peek action, resetting the stack top afterwards. This can be used with peek actions that might otherwise leave elements on the stack in case of a failure.