Copyright | © 2017-2022 Albert Krewinkel |
---|---|
License | MIT |
Maintainer | Albert Krewinkel <tarleb+hslua@zeitkraut.de> |
Safe Haskell | None |
Language | Haskell2010 |
Lua exceptions and exception handling.
Synopsis
- newtype Exception = Exception {}
- class Exception e => LuaError e where
- popException :: LuaE e e
- pushException :: e -> LuaE e ()
- luaException :: String -> e
- type Lua a = LuaE Exception a
- try :: Exception e => LuaE e a -> LuaE e (Either e a)
- failLua :: forall e a. LuaError e => String -> LuaE e a
- throwErrorAsException :: LuaError e => LuaE e a
- throwTypeMismatchError :: forall e a. LuaError e => ByteString -> StackIndex -> LuaE e a
- changeErrorType :: forall old new a. LuaE old a -> LuaE new a
- liftLuaThrow :: forall e a. LuaError e => (State -> Ptr StatusCode -> IO a) -> LuaE e a
- popErrorMessage :: State -> IO ByteString
- pushTypeMismatchError :: ByteString -> StackIndex -> LuaE e ()
Documentation
Default Lua error type. Exceptions raised by Lua-related operations.
Instances
Eq Exception Source # | |
Show Exception Source # | |
Exception Exception Source # | |
Defined in HsLua.Core.Error toException :: Exception -> SomeException # fromException :: SomeException -> Maybe Exception # displayException :: Exception -> String # | |
LuaError Exception Source # | |
Defined in HsLua.Core.Error |
class Exception e => LuaError e where Source #
Any type that you wish to use for error handling in HsLua must be
an instance of the LuaError
class.
popException :: LuaE e e Source #
Converts the error at the top of the stack into an exception and pops the error off the stack.
This function is expected to produce a valid result for any Lua value; neither a Haskell exception nor a Lua error may result when this is called.
pushException :: e -> LuaE e () Source #
Pushes an exception to the top of the Lua stack. The pushed Lua
object is used as an error object, and it is recommended that
calling tostring()
on the object produces an informative message.
luaException :: String -> e Source #
Creates a new exception with the given message.
type Lua a = LuaE Exception a Source #
A Lua operation.
This type is suitable for most users. It uses a default exception for
error handling. Users who need more control over error handling can
use LuaE
with a custom error type instead.
try :: Exception e => LuaE e a -> LuaE e (Either e a) Source #
Return either the result of a Lua computation or, if an exception was thrown, the error.
failLua :: forall e a. LuaError e => String -> LuaE e a Source #
Raises an exception in the Lua monad.
throwErrorAsException :: LuaError e => LuaE e a Source #
Converts a Lua error at the top of the stack into a Haskell exception and throws it.
throwTypeMismatchError :: forall e a. LuaError e => ByteString -> StackIndex -> LuaE e a Source #
Raises an exception that's appropriate when the type of a Lua object at the given index did not match the expected type. The name or description of the expected type is taken as an argument.
changeErrorType :: forall old new a. LuaE old a -> LuaE new a Source #
Change the error type of a computation.
Helpers for hslua C wrapper functions.
liftLuaThrow :: forall e a. LuaError e => (State -> Ptr StatusCode -> IO a) -> LuaE e a Source #
Takes a failable HsLua function and transforms it into a
monadic LuaE
operation. Throws an exception if an error
occured.
popErrorMessage :: State -> IO ByteString Source #
Retrieve and pop the top object as an error message. This is very similar to tostring', but ensures that we don't recurse if getting the message failed.
This helpful as a "last resort" method when implementing
popException
.
pushTypeMismatchError Source #
:: ByteString | name or description of expected type |
-> StackIndex | stack index of mismatching object |
-> LuaE e () |
Creates an error to notify about a Lua type mismatch and pushes it to the stack.