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

Copyright | © 2020-2022 Albert Krewinkel
License | MIT
Maintainer | Albert Krewinkel <tarleb+hslua@zeitkraut.de>
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 #

Function to retrieve a value from Lua's stack.

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

Runs the peeker function.

data Result a #

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

Monad Result # |
Instance details Defined in HsLua.Marshalling.Peek Methods (>>=) :: Result a -> (a -> Result b) -> Result b # (>>) :: Result a -> Result b -> Result b # return :: a -> Result a #
Functor Result # |
Instance details Defined in HsLua.Marshalling.Peek Methods fmap :: (a -> b) -> Result a -> Result b # (<$) :: a -> Result b -> Result a #
Applicative Result # |
Instance details Defined in HsLua.Marshalling.Peek Methods pure :: a -> Result a # (<*>) :: Result (a -> b) -> Result a -> Result b # liftA2 :: (a -> b -> c) -> Result a -> Result b -> Result c # (*>) :: Result a -> Result b -> Result b # (<*) :: Result a -> Result b -> Result a #
Alternative Result # |
Instance details Defined in HsLua.Marshalling.Peek Methods empty :: Result a # (<|>) :: Result a -> Result a -> Result a # some :: Result a -> Result [a] # many :: Result a -> Result [a] #
Eq a => Eq (Result a) # |
Instance details Defined in HsLua.Marshalling.Peek Methods (==) :: Result a -> Result a -> Bool # (/=) :: Result a -> Result a -> Bool #
Show a => Show (Result a) # |
Instance details Defined in HsLua.Marshalling.Peek Methods showsPrec :: Int -> Result a -> ShowS # show :: Result a -> String # showList :: [Result a] -> ShowS #

isFailure :: Result a -> Bool #

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

failure :: ByteString -> Result a #

Create a peek failure record from an error message.

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

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

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

Add context information to the peek traceback stack.

resultToEither :: Result a -> Either String a #

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 #

Converts an old peek funtion to a `Peeker`.

# Lua peek monad

newtype Peek e a #

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

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

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

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 #

Fails the peek operation.

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

Lifts a Lua operation into the Peek monad.

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

Transform the result using the given function.

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

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

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

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.