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 |
Call haskell functions from Lua, and vice versa.
Synopsis
- class Peekable a where
- peek :: StackIndex -> Lua a
- class LuaCallFunc a where
- class ToHaskellFunction a where
- toHsFun :: StackIndex -> a -> Lua NumResults
- 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
class Peekable a where Source #
A value that can be read from the Lua stack.
peek :: StackIndex -> Lua a Source #
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 Source #
Helper class used to make lua functions useable from haskell
Instances
Peekable a => LuaCallFunc (Lua a) Source # | |
(Pushable a, LuaCallFunc b) => LuaCallFunc (a -> b) Source # | |
class ToHaskellFunction 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
wrapper instead.toHaskellFunction
toHsFun :: StackIndex -> a -> Lua NumResults Source #
Helper function, called by toHaskellFunction
Instances
ToHaskellFunction HaskellFunction Source # | |
Defined in Foreign.Lua.FunctionCalling toHsFun :: StackIndex -> HaskellFunction -> Lua NumResults Source # | |
Pushable a => ToHaskellFunction (Lua a) Source # | |
Defined in Foreign.Lua.FunctionCalling toHsFun :: StackIndex -> Lua a -> Lua NumResults Source # | |
(Peekable a, ToHaskellFunction b) => ToHaskellFunction (a -> b) Source # | |
Defined in Foreign.Lua.FunctionCalling toHsFun :: StackIndex -> (a -> b) -> Lua NumResults Source # |
type HaskellFunction = Lua NumResults Source #
Haskell function that can be called from Lua.
class Pushable a where Source #
A value that can be pushed to the Lua stack.
Pushes a value onto Lua stack, casting it into meaningfully nearest Lua type.
Instances
type PreCFunction = State -> IO NumResults Source #
Type of raw Haskell functions that can be made into CFunction
s.
toHaskellFunction :: ToHaskellFunction a => a -> HaskellFunction Source #
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 Source #
Call a Lua function. Use as:
v <- callfunc "proc" "abc" (1::Int) (5.0::Double)
freeCFunction :: CFunction -> Lua () Source #
Free function pointer created with newcfunction
.
newCFunction :: ToHaskellFunction a => a -> Lua CFunction Source #
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 () Source #
registerHaskellFunction :: ToHaskellFunction a => String -> a -> Lua () Source #
Imports a Haskell function and registers it at global name.