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 |
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.
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
class LuaCallFunc a where Source #
Helper class used to make lua functions useable from haskell
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
toHsFun :: StackIndex -> a -> Lua NumResults Source #
Helper function, called by toHaskellFunction
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.
Pushes a value onto Lua stack, casting it into meaningfully nearest Lua type.
type PreCFunction = LuaState -> 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:
- all arguments are instances of
FromLuaStack
- return type is
Lua a
, wherea
is 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.