hslua-0.9.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 Source #

A value that can be read from the Lua stack.

Minimal complete definition

peek

Methods

peek :: StackIndex -> Lua a Source #

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

Instances

FromLuaStack Bool Source # 
FromLuaStack () Source # 

Methods

peek :: StackIndex -> Lua () Source #

FromLuaStack ByteString Source # 
FromLuaStack ByteString Source # 
FromLuaStack Text Source # 
FromLuaStack LuaNumber Source # 
FromLuaStack LuaInteger Source # 
FromLuaStack CFunction Source # 
FromLuaStack LuaState Source # 
FromLuaStack [Char] Source # 

Methods

peek :: StackIndex -> Lua [Char] Source #

FromLuaStack a => FromLuaStack [a] Source # 

Methods

peek :: StackIndex -> Lua [a] Source #

FromLuaStack (Ptr a) Source # 

Methods

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

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

Methods

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

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

Methods

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

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

Methods

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

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

Methods

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

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

Methods

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

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

Methods

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

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

Methods

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

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

Methods

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

class LuaCallFunc a where Source #

Helper class used to make lua functions useable from haskell

Minimal complete definition

callFunc'

Methods

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

Instances

FromLuaStack a => LuaCallFunc (Lua a) Source # 

Methods

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

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

Methods

callFunc' :: String -> Lua () -> NumArgs -> 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 toHaskellFunction wrapper instead.

Minimal complete definition

toHsFun

Methods

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

Helper function, called by toHaskellFunction

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

push

Methods

push :: a -> Lua () Source #

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

Instances

ToLuaStack Bool Source # 

Methods

push :: Bool -> Lua () Source #

ToLuaStack () Source # 

Methods

push :: () -> Lua () Source #

ToLuaStack ByteString Source # 

Methods

push :: ByteString -> Lua () Source #

ToLuaStack ByteString Source # 

Methods

push :: ByteString -> Lua () Source #

ToLuaStack Text Source # 

Methods

push :: Text -> Lua () Source #

ToLuaStack LuaNumber Source # 

Methods

push :: LuaNumber -> Lua () Source #

ToLuaStack LuaInteger Source # 

Methods

push :: LuaInteger -> Lua () Source #

ToLuaStack CFunction Source # 

Methods

push :: CFunction -> Lua () Source #

ToLuaStack [Char] Source # 

Methods

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

ToLuaStack a => ToLuaStack [a] Source # 

Methods

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

ToLuaStack (Ptr a) Source # 

Methods

push :: Ptr a -> Lua () Source #

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

Methods

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

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

Methods

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

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

Methods

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

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

Methods

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

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

Methods

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

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

Methods

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

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

Methods

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

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

Methods

push :: (a, b, c, d, e, f, g, h) -> Lua () 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:

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.