hslua-1.1.0: Bindings to Lua, an embeddable scripting language
Copyright© 2007–2012 Gracjan Polak
2012–2016 Ömer Sinan Ağacan
2017-2020 Albert Krewinkel
LicenseMIT
MaintainerAlbert Krewinkel <tarleb+hslua@zeitkraut.de>
Stabilitybeta
PortabilityFlexibleInstances, ForeignFunctionInterface, ScopedTypeVariables
Safe HaskellNone
LanguageHaskell2010

Foreign.Lua.FunctionCalling

Description

Call haskell functions from Lua, and vice versa.

Synopsis

Documentation

class Peekable a where #

A value that can be read from the Lua stack.

Methods

peek :: StackIndex -> Lua a #

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

Defined in Foreign.Lua.Types.Peekable

Methods

peek :: StackIndex -> Lua Bool #

Peekable Double # 
Instance details

Defined in Foreign.Lua.Types.Peekable

Methods

peek :: StackIndex -> Lua Double #

Peekable Float # 
Instance details

Defined in Foreign.Lua.Types.Peekable

Methods

peek :: StackIndex -> Lua Float #

Peekable Int # 
Instance details

Defined in Foreign.Lua.Types.Peekable

Methods

peek :: StackIndex -> Lua Int #

Peekable Integer # 
Instance details

Defined in Foreign.Lua.Types.Peekable

Methods

peek :: StackIndex -> Lua Integer #

Peekable () # 
Instance details

Defined in Foreign.Lua.Types.Peekable

Methods

peek :: StackIndex -> Lua () #

Peekable Number # 
Instance details

Defined in Foreign.Lua.Types.Peekable

Methods

peek :: StackIndex -> Lua Number #

Peekable Integer # 
Instance details

Defined in Foreign.Lua.Types.Peekable

Methods

peek :: StackIndex -> Lua Integer #

Peekable CFunction # 
Instance details

Defined in Foreign.Lua.Types.Peekable

Peekable State # 
Instance details

Defined in Foreign.Lua.Types.Peekable

Methods

peek :: StackIndex -> Lua State #

Peekable ByteString # 
Instance details

Defined in Foreign.Lua.Types.Peekable

Methods

peek :: StackIndex -> Lua ByteString #

Peekable Text # 
Instance details

Defined in Foreign.Lua.Types.Peekable

Methods

peek :: StackIndex -> Lua Text #

Peekable ByteString # 
Instance details

Defined in Foreign.Lua.Types.Peekable

Methods

peek :: StackIndex -> Lua ByteString #

Peekable [Char] # 
Instance details

Defined in Foreign.Lua.Types.Peekable

Methods

peek :: StackIndex -> Lua [Char] #

Peekable a => Peekable [a] # 
Instance details

Defined in Foreign.Lua.Types.Peekable

Methods

peek :: StackIndex -> Lua [a] #

Peekable (Ptr a) # 
Instance details

Defined in Foreign.Lua.Types.Peekable

Methods

peek :: StackIndex -> Lua (Ptr a) #

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

Defined in Foreign.Lua.Types.Peekable

Methods

peek :: StackIndex -> Lua (Set a) #

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

Defined in Foreign.Lua.Util

Methods

peek :: StackIndex -> Lua (Optional a) #

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

Defined in Foreign.Lua.Types.Peekable

Methods

peek :: StackIndex -> Lua (a, b) #

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

Defined in Foreign.Lua.Types.Peekable

Methods

peek :: StackIndex -> Lua (Map a b) #

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

Defined in Foreign.Lua.Types.Peekable

Methods

peek :: StackIndex -> Lua (a, b, c) #

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

Defined in Foreign.Lua.Types.Peekable

Methods

peek :: StackIndex -> Lua (a, b, c, d) #

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

Defined in Foreign.Lua.Types.Peekable

Methods

peek :: StackIndex -> Lua (a, b, c, d, e) #

(Peekable a, Peekable b, Peekable c, Peekable d, Peekable e, Peekable f) => Peekable (a, b, c, d, e, f) # 
Instance details

Defined in Foreign.Lua.Types.Peekable

Methods

peek :: StackIndex -> Lua (a, b, c, d, e, f) #

(Peekable a, Peekable b, Peekable c, Peekable d, Peekable e, Peekable f, Peekable g) => Peekable (a, b, c, d, e, f, g) # 
Instance details

Defined in Foreign.Lua.Types.Peekable

Methods

peek :: StackIndex -> Lua (a, b, c, d, e, f, g) #

(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) # 
Instance details

Defined in Foreign.Lua.Types.Peekable

Methods

peek :: StackIndex -> Lua (a, b, c, d, e, f, g, h) #

class LuaCallFunc a where #

Helper class used to make lua functions useable from haskell

Methods

callFunc' :: String -> Lua () -> NumArgs -> a #

Instances

Instances details
Peekable a => LuaCallFunc (Lua a) # 
Instance details

Defined in Foreign.Lua.FunctionCalling

Methods

callFunc' :: String -> Lua () -> NumArgs -> Lua a #

(Pushable a, LuaCallFunc b) => LuaCallFunc (a -> b) # 
Instance details

Defined in Foreign.Lua.FunctionCalling

Methods

callFunc' :: String -> Lua () -> NumArgs -> a -> b #

class ToHaskellFunction a where #

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

toHsFun :: StackIndex -> a -> Lua NumResults #

Helper function, called by toHaskellFunction

Instances

Instances details
ToHaskellFunction HaskellFunction # 
Instance details

Defined in Foreign.Lua.FunctionCalling

Pushable a => ToHaskellFunction (Lua a) # 
Instance details

Defined in Foreign.Lua.FunctionCalling

Methods

toHsFun :: StackIndex -> Lua a -> Lua NumResults #

(Peekable a, ToHaskellFunction b) => ToHaskellFunction (a -> b) # 
Instance details

Defined in Foreign.Lua.FunctionCalling

Methods

toHsFun :: StackIndex -> (a -> b) -> Lua NumResults #

type HaskellFunction = Lua NumResults #

Haskell function that can be called from Lua.

class Pushable a where #

A value that can be pushed to the Lua stack.

Methods

push :: a -> Lua () #

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

Instances

Instances details
Pushable Bool # 
Instance details

Defined in Foreign.Lua.Types.Pushable

Methods

push :: Bool -> Lua () #

Pushable Double # 
Instance details

Defined in Foreign.Lua.Types.Pushable

Methods

push :: Double -> Lua () #

Pushable Float # 
Instance details

Defined in Foreign.Lua.Types.Pushable

Methods

push :: Float -> Lua () #

Pushable Int # 
Instance details

Defined in Foreign.Lua.Types.Pushable

Methods

push :: Int -> Lua () #

Pushable Integer # 
Instance details

Defined in Foreign.Lua.Types.Pushable

Methods

push :: Integer -> Lua () #

Pushable () # 
Instance details

Defined in Foreign.Lua.Types.Pushable

Methods

push :: () -> Lua () #

Pushable Number # 
Instance details

Defined in Foreign.Lua.Types.Pushable

Methods

push :: Number -> Lua () #

Pushable Integer # 
Instance details

Defined in Foreign.Lua.Types.Pushable

Methods

push :: Integer -> Lua () #

Pushable CFunction # 
Instance details

Defined in Foreign.Lua.Types.Pushable

Methods

push :: CFunction -> Lua () #

Pushable ByteString # 
Instance details

Defined in Foreign.Lua.Types.Pushable

Methods

push :: ByteString -> Lua () #

Pushable Text # 
Instance details

Defined in Foreign.Lua.Types.Pushable

Methods

push :: Text -> Lua () #

Pushable ByteString # 
Instance details

Defined in Foreign.Lua.Types.Pushable

Methods

push :: ByteString -> Lua () #

Pushable [Char] # 
Instance details

Defined in Foreign.Lua.Types.Pushable

Methods

push :: [Char] -> Lua () #

Pushable a => Pushable [a] # 
Instance details

Defined in Foreign.Lua.Types.Pushable

Methods

push :: [a] -> Lua () #

Pushable (Ptr a) # 
Instance details

Defined in Foreign.Lua.Types.Pushable

Methods

push :: Ptr a -> Lua () #

Pushable a => Pushable (Set a) # 
Instance details

Defined in Foreign.Lua.Types.Pushable

Methods

push :: Set a -> Lua () #

Pushable a => Pushable (Optional a) # 
Instance details

Defined in Foreign.Lua.Util

Methods

push :: Optional a -> Lua () #

(Pushable a, Pushable b) => Pushable (a, b) # 
Instance details

Defined in Foreign.Lua.Types.Pushable

Methods

push :: (a, b) -> Lua () #

(Pushable a, Pushable b) => Pushable (Map a b) # 
Instance details

Defined in Foreign.Lua.Types.Pushable

Methods

push :: Map a b -> Lua () #

(Pushable a, Pushable b, Pushable c) => Pushable (a, b, c) # 
Instance details

Defined in Foreign.Lua.Types.Pushable

Methods

push :: (a, b, c) -> Lua () #

(Pushable a, Pushable b, Pushable c, Pushable d) => Pushable (a, b, c, d) # 
Instance details

Defined in Foreign.Lua.Types.Pushable

Methods

push :: (a, b, c, d) -> Lua () #

(Pushable a, Pushable b, Pushable c, Pushable d, Pushable e) => Pushable (a, b, c, d, e) # 
Instance details

Defined in Foreign.Lua.Types.Pushable

Methods

push :: (a, b, c, d, e) -> Lua () #

(Pushable a, Pushable b, Pushable c, Pushable d, Pushable e, Pushable f) => Pushable (a, b, c, d, e, f) # 
Instance details

Defined in Foreign.Lua.Types.Pushable

Methods

push :: (a, b, c, d, e, f) -> Lua () #

(Pushable a, Pushable b, Pushable c, Pushable d, Pushable e, Pushable f, Pushable g) => Pushable (a, b, c, d, e, f, g) # 
Instance details

Defined in Foreign.Lua.Types.Pushable

Methods

push :: (a, b, c, d, e, f, g) -> Lua () #

(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) # 
Instance details

Defined in Foreign.Lua.Types.Pushable

Methods

push :: (a, b, c, d, e, f, g, h) -> Lua () #

type PreCFunction = State -> IO NumResults #

Type of raw Haskell functions that can be made into CFunctions.

toHaskellFunction :: ToHaskellFunction a => a -> HaskellFunction #

Convert a Haskell function to Lua function. 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)))

callFunc :: LuaCallFunc a => String -> a #

Call a Lua function. Use as:

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

freeCFunction :: CFunction -> Lua () #

Free function pointer created with newcfunction.

newCFunction :: ToHaskellFunction a => a -> Lua CFunction #

Create new foreign Lua function. Function created can be called by the Lua engine. Remeber to free the pointer with freecfunction.

pushHaskellFunction :: ToHaskellFunction a => a -> Lua () #

Pushes Haskell function as a callable userdata. All values created will be garbage collected. Use as:

pushHaskellFunction myfun
setglobal "myfun"

Error conditions should be indicated by raising a Lua Exception or by returning the result of error.

pushPreCFunction :: PreCFunction -> Lua () #

Converts a pre C function to a Lua function and pushes it to the stack.

Pre C functions collect parameters from the stack and return a CInt that represents number of return values left on the stack.

registerHaskellFunction :: ToHaskellFunction a => String -> a -> Lua () #

Imports a Haskell function and registers it at global name.