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
PortabilityFlexibleInstances, ForeignFunctionInterface, ScopedTypeVariables
Safe HaskellNone
LanguageHaskell2010

HsLua.Class.Exposable

Description

Call Haskell functions from Lua.

Synopsis

Documentation

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)))

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

Imports a Haskell function and registers it at global name.