hslua-0.9.5.2: A Lua language interpreter embedding in Haskell

Copyright© 2007–2012 Gracjan Polak
2012–2016 Ömer Sinan Ağacan
2017 Albert Krewinkel
LicenseMIT
MaintainerAlbert Krewinkel <tarleb+hslua@zeitkraut.de>
Stabilitybeta
PortabilityFlexibleInstances, ForeignFunctionInterface, ScopedTypeVariables
Safe HaskellNone
LanguageHaskell98

Foreign.Lua.FunctionCalling

Description

Call haskell functions from Lua, and vice versa.

Synopsis

Documentation

class FromLuaStack a where #

A value that can be read from the Lua stack.

Minimal complete definition

peek

Methods

peek :: StackIndex -> Lua a #

Check if at index n there is a convertible Lua value and if so return it. Throws a LuaException otherwise.

Instances

FromLuaStack Bool # 

Methods

peek :: StackIndex -> Lua Bool #

FromLuaStack () # 

Methods

peek :: StackIndex -> Lua () #

FromLuaStack ByteString # 
FromLuaStack ByteString # 
FromLuaStack Text # 

Methods

peek :: StackIndex -> Lua Text #

FromLuaStack LuaNumber # 
FromLuaStack LuaInteger # 
FromLuaStack CFunction # 
FromLuaStack LuaState # 
FromLuaStack [Char] # 

Methods

peek :: StackIndex -> Lua [Char] #

FromLuaStack a => FromLuaStack [a] # 

Methods

peek :: StackIndex -> Lua [a] #

FromLuaStack (Ptr a) # 

Methods

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

FromLuaStack a => FromLuaStack (OrNil a) # 

Methods

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

FromLuaStack a => FromLuaStack (Optional a) # 

Methods

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

(FromLuaStack a, FromLuaStack b) => FromLuaStack (a, b) # 

Methods

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

(Ord a, FromLuaStack a, FromLuaStack b) => FromLuaStack (Map a b) # 

Methods

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

(FromLuaStack a, FromLuaStack b, FromLuaStack c) => FromLuaStack (a, b, c) # 

Methods

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

(FromLuaStack a, FromLuaStack b, FromLuaStack c, FromLuaStack d) => FromLuaStack (a, b, c, d) # 

Methods

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

(FromLuaStack a, FromLuaStack b, FromLuaStack c, FromLuaStack d, FromLuaStack e) => FromLuaStack (a, b, c, d, e) # 

Methods

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

(FromLuaStack a, FromLuaStack b, FromLuaStack c, FromLuaStack d, FromLuaStack e, FromLuaStack f) => FromLuaStack (a, b, c, d, e, f) # 

Methods

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

(FromLuaStack a, FromLuaStack b, FromLuaStack c, FromLuaStack d, FromLuaStack e, FromLuaStack f, FromLuaStack g) => FromLuaStack (a, b, c, d, e, f, g) # 

Methods

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

(FromLuaStack a, FromLuaStack b, FromLuaStack c, FromLuaStack d, FromLuaStack e, FromLuaStack f, FromLuaStack g, FromLuaStack h) => FromLuaStack (a, b, c, d, e, f, g, h) # 

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

Minimal complete definition

callFunc'

Methods

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

Instances

FromLuaStack a => LuaCallFunc (Lua a) # 

Methods

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

(ToLuaStack a, LuaCallFunc b) => LuaCallFunc (a -> b) # 

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.

Minimal complete definition

toHsFun

Methods

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

Helper function, called by toHaskellFunction

type HaskellFunction = Lua NumResults #

Haskell function that can be called from Lua.

class ToLuaStack a where #

A value that can be pushed to the Lua stack.

Minimal complete definition

push

Methods

push :: a -> Lua () #

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

Instances

ToLuaStack Bool # 

Methods

push :: Bool -> Lua () #

ToLuaStack () # 

Methods

push :: () -> Lua () #

ToLuaStack ByteString # 

Methods

push :: ByteString -> Lua () #

ToLuaStack ByteString # 

Methods

push :: ByteString -> Lua () #

ToLuaStack Text # 

Methods

push :: Text -> Lua () #

ToLuaStack LuaNumber # 

Methods

push :: LuaNumber -> Lua () #

ToLuaStack LuaInteger # 

Methods

push :: LuaInteger -> Lua () #

ToLuaStack CFunction # 

Methods

push :: CFunction -> Lua () #

ToLuaStack [Char] # 

Methods

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

ToLuaStack a => ToLuaStack [a] # 

Methods

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

ToLuaStack (Ptr a) # 

Methods

push :: Ptr a -> Lua () #

ToLuaStack a => ToLuaStack (OrNil a) # 

Methods

push :: OrNil a -> Lua () #

ToLuaStack a => ToLuaStack (Optional a) # 

Methods

push :: Optional a -> Lua () #

(ToLuaStack a, ToLuaStack b) => ToLuaStack (a, b) # 

Methods

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

(ToLuaStack a, ToLuaStack b) => ToLuaStack (Map a b) # 

Methods

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

(ToLuaStack a, ToLuaStack b, ToLuaStack c) => ToLuaStack (a, b, c) # 

Methods

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

(ToLuaStack a, ToLuaStack b, ToLuaStack c, ToLuaStack d) => ToLuaStack (a, b, c, d) # 

Methods

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

(ToLuaStack a, ToLuaStack b, ToLuaStack c, ToLuaStack d, ToLuaStack e) => ToLuaStack (a, b, c, d, e) # 

Methods

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

(ToLuaStack a, ToLuaStack b, ToLuaStack c, ToLuaStack d, ToLuaStack e, ToLuaStack f) => ToLuaStack (a, b, c, d, e, f) # 

Methods

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

(ToLuaStack a, ToLuaStack b, ToLuaStack c, ToLuaStack d, ToLuaStack e, ToLuaStack f, ToLuaStack g) => ToLuaStack (a, b, c, d, e, f, g) # 

Methods

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

(ToLuaStack a, ToLuaStack b, ToLuaStack c, ToLuaStack d, ToLuaStack e, ToLuaStack f, ToLuaStack g, ToLuaStack h) => ToLuaStack (a, b, c, d, e, f, g, h) # 

Methods

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

type PreCFunction = LuaState -> 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:

Any Haskell exception will be converted to a string and returned as Lua error.

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

Pushes Haskell function as a callable userdata. 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 () #

Imports a Haskell function and registers it at global name.