hslua-core-2.0.0: Bindings to Lua, an embeddable scripting language
Copyright© 2017-2021 Albert Krewinkel
LicenseMIT
MaintainerAlbert Krewinkel <tarleb+hslua@zeitkraut.de>
Safe HaskellNone
LanguageHaskell2010

HsLua.Core.Error

Description

Lua exceptions and exception handling.

Synopsis

Documentation

newtype Exception Source #

Default Lua error type. Exceptions raised by Lua-related operations.

Constructors

Exception 

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.

Methods

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 Lua 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 peekException.

pushTypeMismatchError Source #

Arguments

:: 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.

Orphan instances

LuaError e => MonadFail (LuaE e) Source # 
Instance details

Methods

fail :: String -> LuaE e a #

LuaError e => Alternative (LuaE e) Source # 
Instance details

Methods

empty :: LuaE e a #

(<|>) :: LuaE e a -> LuaE e a -> LuaE e a #

some :: LuaE e a -> LuaE e [a] #

many :: LuaE e a -> LuaE e [a] #