hslua-classes-2.3.1: Type classes for HsLua

Copyright | © 2007–2012 Gracjan Polak; © 2012–2016 Ömer Sinan Ağacan; © 2017-2024 Albert Krewinkel
License | MIT
Maintainer | Albert Krewinkel <tarleb@hslua.org>
Stability | beta
Portability | non-portable (depends on GHC)
Safe Haskell | None
Language | Haskell2010

HsLua.Classes

Contents

- Receiving values from Lua stack (Lua → Haskell)
- Pushing values to Lua stack (Haskell → Lua)
- Calling Functions
- Utility functions and types
  - Retrieving values

Description

Convenience module which re-exports all classes and utility functions provided by the hslua-classes package.

Synopsis

- class Peekable a where
  - safepeek :: LuaError e => Peeker e a
- peekEither :: (LuaError e, Peekable a) => StackIndex -> LuaE e (Either e a)
- class Pushable a where
  - push :: LuaError e => a -> LuaE e ()
- pushList :: (LuaError e, Pushable a) => [a] -> LuaE e ()
- class LuaError e => Exposable e a where
  - partialApply :: StackIndex -> a -> Peek e NumResults
- toHaskellFunction :: Exposable e a => a -> HaskellFunction e
- invoke :: Invokable a => Name -> a
- registerHaskellFunction :: Exposable e a => Name -> a -> LuaE e ()
- raiseError :: (LuaError e, Pushable a) => a -> LuaE e NumResults
- newtype Optional a = Optional {
  - fromOptional :: Maybe a
  }
- popValue :: (LuaError e, Peekable a) => LuaE e a

# Receiving values from Lua stack (Lua → Haskell)

class Peekable a where Source #

A value that can be read from the Lua stack.

Methods

safepeek :: LuaError e => Peeker e a Source #

Function that retrieves a value from the Lua stack.

#### Instances

Instances details

Peekable ByteString Source # |
Instance details Defined in HsLua.Class.Peekable Methods safepeek :: LuaError e => Peeker e ByteString Source #
Peekable ByteString Source # |
Instance details Defined in HsLua.Class.Peekable Methods safepeek :: LuaError e => Peeker e ByteString Source #
Peekable CFunction Source # |
Instance details Defined in HsLua.Class.Peekable Methods safepeek :: LuaError e => Peeker e CFunction Source #
Peekable Integer Source # |
Instance details Defined in HsLua.Class.Peekable Methods safepeek :: LuaError e => Peeker e Integer Source #
Peekable Number Source # |
Instance details Defined in HsLua.Class.Peekable Methods safepeek :: LuaError e => Peeker e Number Source #
Peekable State Source # |
Instance details Defined in HsLua.Class.Peekable Methods safepeek :: LuaError e => Peeker e State Source #
Peekable Text Source # |
Instance details Defined in HsLua.Class.Peekable Methods safepeek :: LuaError e => Peeker e Text Source #
Peekable Integer Source # |
Instance details Defined in HsLua.Class.Peekable Methods safepeek :: LuaError e => Peeker e Integer Source #
Peekable () Source # |
Instance details Defined in HsLua.Class.Peekable Methods safepeek :: LuaError e => Peeker e () Source #
Peekable Bool Source # |
Instance details Defined in HsLua.Class.Peekable Methods safepeek :: LuaError e => Peeker e Bool Source #
Peekable Double Source # |
Instance details Defined in HsLua.Class.Peekable Methods safepeek :: LuaError e => Peeker e Double Source #
Peekable Float Source # |
Instance details Defined in HsLua.Class.Peekable Methods safepeek :: LuaError e => Peeker e Float Source #
Peekable Int Source # |
Instance details Defined in HsLua.Class.Peekable Methods safepeek :: LuaError e => Peeker e Int Source #
(Ord a, Peekable a) => Peekable (Set a) Source # |
Instance details Defined in HsLua.Class.Peekable Methods safepeek :: LuaError e => Peeker e (Set a) Source #
Peekable (Ptr a) Source # |
Instance details Defined in HsLua.Class.Peekable Methods safepeek :: LuaError e => Peeker e (Ptr a) Source #
Peekable a => Peekable (Optional a) Source # |
Instance details Defined in HsLua.Class.Util Methods safepeek :: LuaError e => Peeker e (Optional a) Source #
Peekable [Char] Source # |
Instance details Defined in HsLua.Class.Peekable Methods safepeek :: LuaError e => Peeker e [Char] Source #
Peekable a => Peekable [a] Source # |
Instance details Defined in HsLua.Class.Peekable Methods safepeek :: LuaError e => Peeker e [a] Source #
(Ord a, Peekable a, Peekable b) => Peekable (Map a b) Source # |
Instance details Defined in HsLua.Class.Peekable Methods safepeek :: LuaError e => Peeker e (Map a b) Source #
(Peekable a, Peekable b) => Peekable (a, b) Source # |
Instance details Defined in HsLua.Class.Peekable Methods safepeek :: LuaError e => Peeker e (a, b) Source #
(Peekable a, Peekable b, Peekable c) => Peekable (a, b, c) Source # |
Instance details Defined in HsLua.Class.Peekable Methods safepeek :: LuaError e => Peeker e (a, b, c) Source #
(Peekable a, Peekable b, Peekable c, Peekable d) => Peekable (a, b, c, d) Source # |
Instance details Defined in HsLua.Class.Peekable Methods safepeek :: LuaError e => Peeker e (a, b, c, d) Source #
(Peekable a, Peekable b, Peekable c, Peekable d, Peekable e) => Peekable (a, b, c, d, e) Source # |
Instance details Defined in HsLua.Class.Peekable Methods safepeek :: LuaError e0 => Peeker e0 (a, b, c, d, e) Source #
(Peekable a, Peekable b, Peekable c, Peekable d, Peekable e, Peekable f) => Peekable (a, b, c, d, e, f) Source # |
Instance details Defined in HsLua.Class.Peekable Methods safepeek :: LuaError e0 => Peeker e0 (a, b, c, d, e, f) Source #
(Peekable a, Peekable b, Peekable c, Peekable d, Peekable e, Peekable f, Peekable g) => Peekable (a, b, c, d, e, f, g) Source # |
Instance details Defined in HsLua.Class.Peekable Methods safepeek :: LuaError e0 => Peeker e0 (a, b, c, d, e, f, g) Source #
(Peekable a, Peekable b, Peekable c, Peekable d, Peekable e, Peekable f, Peekable g, Peekable h) => Peekable (a, b, c, d, e, f, g, h) Source # |
Instance details Defined in HsLua.Class.Peekable Methods safepeek :: LuaError e0 => Peeker e0 (a, b, c, d, e, f, g, h) Source #

peekEither :: (LuaError e, Peekable a) => StackIndex -> LuaE e (Either e a) Source #

Try to convert the value at the given stack index to a Haskell value. Returns `Left` with the error on failure.

# Pushing values to Lua stack (Haskell → Lua)

class Pushable a where Source #

A value that can be pushed to the Lua stack.

Methods

push :: LuaError e => a -> LuaE e () Source #

Pushes a value onto Lua stack, casting it into meaningfully nearest Lua type.

#### Instances

Instances details

Pushable ByteString Source # |
Instance details Defined in HsLua.Class.Pushable Methods push :: LuaError e => ByteString -> LuaE e () Source #
Pushable ByteString Source # |
Instance details Defined in HsLua.Class.Pushable Methods push :: LuaError e => ByteString -> LuaE e () Source #
Pushable CFunction Source # |
Instance details Defined in HsLua.Class.Pushable Methods push :: LuaError e => CFunction -> LuaE e () Source #
Pushable Integer Source # |
Instance details Defined in HsLua.Class.Pushable Methods push :: LuaError e => Integer -> LuaE e () Source #
Pushable Number Source # |
Instance details Defined in HsLua.Class.Pushable Methods push :: LuaError e => Number -> LuaE e () Source #
Pushable Text Source # |
Instance details Defined in HsLua.Class.Pushable Methods push :: LuaError e => Text -> LuaE e () Source #
Pushable Integer Source # |
Instance details Defined in HsLua.Class.Pushable Methods push :: LuaError e => Integer -> LuaE e () Source #
Pushable () Source # |
Instance details Defined in HsLua.Class.Pushable Methods push :: LuaError e => () -> LuaE e () Source #
Pushable Bool Source # |
Instance details Defined in HsLua.Class.Pushable Methods push :: LuaError e => Bool -> LuaE e () Source #
Pushable Double Source # |
Instance details Defined in HsLua.Class.Pushable Methods push :: LuaError e => Double -> LuaE e () Source #
Pushable Float Source # |
Instance details Defined in HsLua.Class.Pushable Methods push :: LuaError e => Float -> LuaE e () Source #
Pushable Int Source # |
Instance details Defined in HsLua.Class.Pushable Methods push :: LuaError e => Int -> LuaE e () Source #
Pushable a => Pushable (Set a) Source # |
Instance details Defined in HsLua.Class.Pushable Methods push :: LuaError e => Set a -> LuaE e () Source #
Pushable (Ptr a) Source # |
Instance details Defined in HsLua.Class.Pushable Methods push :: LuaError e => Ptr a -> LuaE e () Source #
Pushable a => Pushable (Optional a) Source # |
Instance details Defined in HsLua.Class.Util Methods push :: LuaError e => Optional a -> LuaE e () Source #
Pushable [Char] Source # |
Instance details Defined in HsLua.Class.Pushable Methods push :: LuaError e => [Char] -> LuaE e () Source #
Pushable a => Pushable [a] Source # |
Instance details Defined in HsLua.Class.Pushable Methods push :: LuaError e => [a] -> LuaE e () Source #
(Pushable a, Pushable b) => Pushable (Map a b) Source # |
Instance details Defined in HsLua.Class.Pushable Methods push :: LuaError e => Map a b -> LuaE e () Source #
(Pushable a, Pushable b) => Pushable (a, b) Source # |
Instance details Defined in HsLua.Class.Pushable Methods push :: LuaError e => (a, b) -> LuaE e () Source #
(Pushable a, Pushable b, Pushable c) => Pushable (a, b, c) Source # |
Instance details Defined in HsLua.Class.Pushable Methods push :: LuaError e => (a, b, c) -> LuaE e () Source #
(Pushable a, Pushable b, Pushable c, Pushable d) => Pushable (a, b, c, d) Source # |
Instance details Defined in HsLua.Class.Pushable Methods push :: LuaError e => (a, b, c, d) -> LuaE e () Source #
(Pushable a, Pushable b, Pushable c, Pushable d, Pushable e) => Pushable (a, b, c, d, e) Source # |
Instance details Defined in HsLua.Class.Pushable Methods push :: LuaError e0 => (a, b, c, d, e) -> LuaE e0 () Source #
(Pushable a, Pushable b, Pushable c, Pushable d, Pushable e, Pushable f) => Pushable (a, b, c, d, e, f) Source # |
Instance details Defined in HsLua.Class.Pushable Methods push :: LuaError e0 => (a, b, c, d, e, f) -> LuaE e0 () Source #
(Pushable a, Pushable b, Pushable c, Pushable d, Pushable e, Pushable f, Pushable g) => Pushable (a, b, c, d, e, f, g) Source # |
Instance details Defined in HsLua.Class.Pushable Methods push :: LuaError e0 => (a, b, c, d, e, f, g) -> LuaE e0 () Source #
(Pushable a, Pushable b, Pushable c, Pushable d, Pushable e, Pushable f, Pushable g, Pushable h) => Pushable (a, b, c, d, e, f, g, h) Source # |
Instance details Defined in HsLua.Class.Pushable Methods push :: LuaError e0 => (a, b, c, d, e, f, g, h) -> LuaE e0 () Source #

pushList :: (LuaError e, Pushable a) => [a] -> LuaE e () Source #

Push list as numerically indexed table.

# Calling Functions

class LuaError e => Exposable e a where Source #

Operations and functions that can be pushed to the Lua stack. This is a helper function not intended to be used directly. Use the ``toHaskellFunction`` wrapper instead.

Methods

partialApply :: StackIndex -> a -> Peek e NumResults Source #

Helper function, called by ``toHaskellFunction``. 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.

#### Instances

Instances details

LuaError e => Exposable e (HaskellFunction e) Source # |
Instance details Defined in HsLua.Class.Exposable Methods partialApply :: StackIndex -> HaskellFunction e -> Peek e NumResults Source #
(LuaError e, Pushable a) => Exposable e (LuaE e a) Source # |
Instance details Defined in HsLua.Class.Exposable Methods partialApply :: StackIndex -> LuaE e a -> Peek e NumResults Source #
(LuaError e, Pushable a) => Exposable e (Peek e a) Source # |
Instance details Defined in HsLua.Class.Exposable Methods partialApply :: StackIndex -> Peek e a -> Peek e NumResults Source #
(Peekable a, Exposable e b) => Exposable e (a -> b) Source # |
Instance details Defined in HsLua.Class.Exposable Methods partialApply :: StackIndex -> (a -> b) -> Peek e NumResults Source #

toHaskellFunction :: Exposable e a => a -> HaskellFunction e Source #

Convert a Haskell function to a function type directly exposable to Lua. Any Haskell function can be converted provided that:

- all arguments are instances of ``Peekable``
- return type is `LuaE e a`, where `a` is an instance of ``Pushable``

Any exception of type `e` will be caught.

Important: this does not catch exceptions other than `e`; 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 `MonadCatch` and `Pushable`:

    toHaskellFunction (myFun `catchM` (\e -> raiseError (e :: FooException)))

invoke :: Invokable a => Name -> a Source #

Invoke a Lua function. Use as:

    v <- invoke "proc" "abc" (1::Int) (5.0::Double)

registerHaskellFunction :: Exposable e a => Name -> a -> LuaE e () Source #

Imports a Haskell function and registers it at global name.

# Utility functions and types

raiseError :: (LuaError e, Pushable a) => a -> LuaE e NumResults Source #

Raise a Lua error, using the given value as the error object.

newtype Optional a Source #

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.

Constructors

Optional |

Fields

- fromOptional :: Maybe a

#### Instances

Instances details

Peekable a => Peekable (Optional a) Source # |
Instance details Defined in HsLua.Class.Util Methods safepeek :: LuaError e => Peeker e (Optional a) Source #
Pushable a => Pushable (Optional a) Source # |
Instance details Defined in HsLua.Class.Util Methods push :: LuaError e => Optional a -> LuaE e () Source #

## Retrieving values

popValue :: (LuaError e, Peekable a) => LuaE e a Source #

Get, then pop the value at the top of the stack. The pop operation is executed even if the retrieval operation failed.