hslua-classes-2.0.0: Type classes for HsLua
Copyright© 2007–2012 Gracjan Polak;
© 2012–2016 Ömer Sinan Ağacan;
© 2017-2021 Albert Krewinkel
LicenseMIT
MaintainerAlbert Krewinkel <tarleb+hslua@zeitkraut.de>
Stabilitybeta
Portabilitynon-portable (depends on GHC)
Safe HaskellNone
LanguageHaskell2010

HsLua.Classes

Description

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

Synopsis

Receiving values from Lua stack (Lua → Haskell)

class Peekable a where Source #

A value that can be read from the Lua stack.

Methods

peek :: PeekError e => StackIndex -> LuaE e a Source #

Check if at index n there is a convertible Lua value and if so return it. Throws a Exception otherwise.

Instances

Instances details
Peekable Bool Source # 
Instance details

Defined in HsLua.Class.Peekable

Methods

peek :: PeekError e => StackIndex -> LuaE e Bool Source #

Peekable Double Source # 
Instance details

Defined in HsLua.Class.Peekable

Peekable Float Source # 
Instance details

Defined in HsLua.Class.Peekable

Methods

peek :: PeekError e => StackIndex -> LuaE e Float Source #

Peekable Int Source # 
Instance details

Defined in HsLua.Class.Peekable

Methods

peek :: PeekError e => StackIndex -> LuaE e Int Source #

Peekable Integer Source # 
Instance details

Defined in HsLua.Class.Peekable

Peekable () Source # 
Instance details

Defined in HsLua.Class.Peekable

Methods

peek :: PeekError e => StackIndex -> LuaE e () Source #

Peekable ByteString Source # 
Instance details

Defined in HsLua.Class.Peekable

Peekable ByteString Source # 
Instance details

Defined in HsLua.Class.Peekable

Peekable Text Source # 
Instance details

Defined in HsLua.Class.Peekable

Methods

peek :: PeekError e => StackIndex -> LuaE e Text Source #

Peekable Number Source # 
Instance details

Defined in HsLua.Class.Peekable

Peekable Integer Source # 
Instance details

Defined in HsLua.Class.Peekable

Peekable CFunction Source # 
Instance details

Defined in HsLua.Class.Peekable

Peekable State Source # 
Instance details

Defined in HsLua.Class.Peekable

Methods

peek :: PeekError e => StackIndex -> LuaE e State Source #

Peekable [Char] Source # 
Instance details

Defined in HsLua.Class.Peekable

Methods

peek :: PeekError e => StackIndex -> LuaE e [Char] Source #

Peekable a => Peekable [a] Source # 
Instance details

Defined in HsLua.Class.Peekable

Methods

peek :: PeekError e => StackIndex -> LuaE e [a] Source #

Peekable (Ptr a) Source # 
Instance details

Defined in HsLua.Class.Peekable

Methods

peek :: PeekError e => StackIndex -> LuaE e (Ptr a) Source #

(Ord a, Peekable a) => Peekable (Set a) Source # 
Instance details

Defined in HsLua.Class.Peekable

Methods

peek :: PeekError e => StackIndex -> LuaE e (Set a) Source #

Peekable a => Peekable (Optional a) Source # 
Instance details

Defined in HsLua.Class.Util

Methods

peek :: PeekError e => StackIndex -> LuaE e (Optional a) Source #

(Peekable a, Peekable b) => Peekable (a, b) Source # 
Instance details

Defined in HsLua.Class.Peekable

Methods

peek :: PeekError e => StackIndex -> LuaE e (a, b) Source #

(Ord a, Peekable a, Peekable b) => Peekable (Map a b) Source # 
Instance details

Defined in HsLua.Class.Peekable

Methods

peek :: PeekError e => StackIndex -> LuaE e (Map a b) Source #

(Peekable a, Peekable b, Peekable c) => Peekable (a, b, c) Source # 
Instance details

Defined in HsLua.Class.Peekable

Methods

peek :: PeekError e => StackIndex -> LuaE 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

peek :: PeekError e => StackIndex -> LuaE 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

peek :: PeekError e0 => StackIndex -> LuaE 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

peek :: PeekError e0 => StackIndex -> LuaE 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

peek :: PeekError e0 => StackIndex -> LuaE 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

peek :: PeekError e0 => StackIndex -> LuaE e0 (a, b, c, d, e, f, g, h) Source #

peekEither :: (PeekError 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.

peekList :: (PeekError e, Peekable a) => StackIndex -> LuaE e [a] Source #

Read a table into a list

peekKeyValuePairs :: (Peekable a, Peekable b, PeekError e) => StackIndex -> LuaE e [(a, b)] Source #

Read a table into a list of pairs.

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 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 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 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 Text Source # 
Instance details

Defined in HsLua.Class.Pushable

Methods

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

Pushable Number Source # 
Instance details

Defined in HsLua.Class.Pushable

Methods

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

Pushable Integer Source # 
Instance details

Defined in HsLua.Class.Pushable

Methods

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

Pushable CFunction Source # 
Instance details

Defined in HsLua.Class.Pushable

Methods

push :: LuaError e => CFunction -> 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 (Ptr a) Source # 
Instance details

Defined in HsLua.Class.Pushable

Methods

push :: LuaError e => Ptr a -> 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 a => Pushable (Optional a) Source # 
Instance details

Defined in HsLua.Class.Util

Methods

push :: LuaError e => Optional a -> 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 (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 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 PeekError 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 -> LuaE 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
PeekError e => Exposable e (HaskellFunction e) Source # 
Instance details

Defined in HsLua.Class.Exposable

(Peekable a, Exposable e b) => Exposable e (a -> b) Source # 
Instance details

Defined in HsLua.Class.Exposable

Methods

partialApply :: StackIndex -> (a -> b) -> LuaE e NumResults Source #

(PeekError e, Pushable a) => Exposable e (LuaE e a) Source # 
Instance details

Defined in HsLua.Class.Exposable

toHaskellFunction :: forall e a. 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 Lua a, where a is an instance of Pushable

Any Exception will be converted to a string and returned as Lua error.

Important: this does not catch exceptions other than Exception; exception handling must be done by the converted 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 :: forall e a. Invokable e 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 :: (PeekError 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

Instances

Instances details
Peekable a => Peekable (Optional a) Source # 
Instance details

Defined in HsLua.Class.Util

Methods

peek :: PeekError e => StackIndex -> LuaE 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 :: (PeekError 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.