| Copyright | © 2007–2012 Gracjan Polak 2012–2016 Ömer Sinan Ağacan 2017 Albert Krewinkel |
|---|---|
| License | MIT |
| Maintainer | Albert Krewinkel <tarleb+hslua@zeitkraut.de> |
| Stability | beta |
| Portability | FlexibleInstances, ForeignFunctionInterface, ScopedTypeVariables |
| Safe Haskell | None |
| Language | Haskell98 |
Foreign.Lua.FunctionCalling
Description
Call haskell functions from Lua, and vice versa.
- class FromLuaStack a where
- class LuaCallFunc a where
- class ToHaskellFunction a where
- type HaskellFunction = Lua NumResults
- class ToLuaStack a where
- type PreCFunction = LuaState -> 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 FromLuaStack a where Source #
A value that can be read from the Lua stack.
Minimal complete definition
Methods
peek :: StackIndex -> Lua a Source #
Check if at index n there is a convertible Lua value and if so return
it. Throws a otherwise.LuaException
Instances
| FromLuaStack Bool Source # | |
| FromLuaStack Int Source # | |
| FromLuaStack () Source # | |
| FromLuaStack ByteString Source # | |
| FromLuaStack Text Source # | |
| FromLuaStack LuaNumber Source # | |
| FromLuaStack LuaInteger Source # | |
| FromLuaStack CFunction Source # | |
| FromLuaStack LuaState Source # | |
| FromLuaStack [Char] Source # | |
| FromLuaStack a => FromLuaStack [a] Source # | |
| FromLuaStack (Ptr a) Source # | |
| (Ord a, FromLuaStack a, FromLuaStack b) => FromLuaStack (Map a b) Source # | |
class LuaCallFunc a where Source #
Helper class used to make lua functions useable from haskell
Minimal complete definition
Instances
| FromLuaStack a => LuaCallFunc (Lua a) Source # | |
| (ToLuaStack 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
Minimal complete definition
Methods
toHsFun :: StackIndex -> a -> Lua NumResults Source #
Helper function, called by toHaskellFunction
Instances
| ToHaskellFunction HaskellFunction Source # | |
| ToLuaStack a => ToHaskellFunction (Lua a) Source # | |
| (FromLuaStack a, ToHaskellFunction b) => ToHaskellFunction (a -> b) Source # | |
type HaskellFunction = Lua NumResults Source #
Haskell function that can be called from Lua.
class ToLuaStack a where Source #
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
| ToLuaStack Bool Source # | |
| ToLuaStack Int Source # | |
| ToLuaStack () Source # | |
| ToLuaStack ByteString Source # | |
| ToLuaStack Text Source # | |
| ToLuaStack LuaNumber Source # | |
| ToLuaStack LuaInteger Source # | |
| ToLuaStack CFunction Source # | |
| ToLuaStack [Char] Source # | |
| ToLuaStack a => ToLuaStack [a] Source # | |
| ToLuaStack (Ptr a) Source # | |
| (ToLuaStack a, ToLuaStack b) => ToLuaStack (Map a b) Source # | |
type PreCFunction = LuaState -> IO NumResults Source #
Type of raw haskell functions that can be made into CFunctions.
toHaskellFunction :: ToHaskellFunction a => a -> HaskellFunction Source #
Convert a Haskell function to Lua function. Any Haskell function can be converted provided that:
- all arguments are instances of
FromLuaStack - return type is
Lua a, whereais an instance ofToLuaStack
Any Haskell exception will be converted to a string and returned as Lua error.
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 #
Pushes Haskell function converted to a Lua function. All values created will be garbage collected. Use as:
pushHaskellFunction myfun setglobal "myfun"
You are not allowed to use lua_error anywhere, but
use an error code of (-1) to the same effect. Push
error message as the sole return value.
registerHaskellFunction :: ToHaskellFunction a => String -> a -> Lua () Source #
Imports a Haskell function and registers it at global name.