Copyright | © 2007–2012 Gracjan Polak 2012–2016 Ömer Sinan Ağacan 2017-2019 Albert Krewinkel |
---|---|
License | MIT |
Maintainer | Albert Krewinkel <tarleb+hslua@zeitkraut.de> |
Stability | beta |
Portability | FlexibleInstances, ForeignFunctionInterface, ScopedTypeVariables |
Safe Haskell | None |
Language | Haskell2010 |
Foreign.Lua.FunctionCalling
Description
Call haskell functions from Lua, and vice versa.
Synopsis
- class Peekable a where
- class LuaCallFunc a where
- class ToHaskellFunction a where
- type HaskellFunction = Lua NumResults
- class Pushable a where
- type PreCFunction = State -> IO NumResults
- toHaskellFunction :: ToHaskellFunction a => a -> HaskellFunction
- callFunc :: LuaCallFunc a => String -> a
- freeCFunction :: CFunction -> Lua ()
- newCFunction :: ToHaskellFunction a => a -> Lua CFunction
- pushHaskellFunction :: ToHaskellFunction a => a -> Lua ()
- registerHaskellFunction :: ToHaskellFunction a => String -> a -> Lua ()
Documentation
A value that can be read from the Lua stack.
Minimal complete definition
Methods
peek :: StackIndex -> Lua a #
Check if at index n
there is a convertible Lua value and if so return
it. Throws a
otherwise.Exception
Instances
class LuaCallFunc a where #
Helper class used to make lua functions useable from haskell
Minimal complete definition
Instances
Peekable a => LuaCallFunc (Lua a) # | |
(Pushable a, LuaCallFunc b) => LuaCallFunc (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
wrapper instead.toHaskellFunction
Minimal complete definition
Instances
ToHaskellFunction HaskellFunction # | |
Defined in Foreign.Lua.FunctionCalling Methods toHsFun :: StackIndex -> HaskellFunction -> Lua NumResults # | |
Pushable a => ToHaskellFunction (Lua a) # | |
Defined in Foreign.Lua.FunctionCalling Methods toHsFun :: StackIndex -> Lua a -> Lua NumResults # | |
(Peekable a, ToHaskellFunction b) => ToHaskellFunction (a -> b) # | |
Defined in Foreign.Lua.FunctionCalling Methods toHsFun :: StackIndex -> (a -> b) -> Lua NumResults # |
type HaskellFunction = Lua NumResults #
Haskell function that can be called from Lua.
A value that can be pushed to the Lua stack.
Minimal complete definition
Methods
Pushes a value onto Lua stack, casting it into meaningfully nearest Lua type.
Instances
type PreCFunction = State -> IO NumResults #
Type of raw Haskell functions that can be made into CFunction
s.
toHaskellFunction :: ToHaskellFunction a => a -> HaskellFunction #
Convert a Haskell function to Lua function. Any Haskell function can be converted provided that:
Any
will be converted to a string and returned
as Lua error.Exception
Important: this does not catch exceptions other than
; exception handling must be done by the converted
Haskell function. Failure to do so will cause the program to crash.Exception
E.g., the following code could be used to handle an Exception of type
FooException, if that type is an instance of
and
MonadCatch
: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 Lua engine. Remeber to free the pointer with freecfunction
.
pushHaskellFunction :: ToHaskellFunction a => a -> Lua () #
registerHaskellFunction :: ToHaskellFunction a => String -> a -> Lua () #
Imports a Haskell function and registers it at global name.