hslua-packaging-2.0.0: Utilities to build Lua modules.
Copyright© 2020-2021 Albert Krewinkel
LicenseMIT
MaintainerAlbert Krewinkel <tarleb+hslua@zeitkraut.de>
Stabilityalpha
PortabilityPortable
Safe HaskellNone
LanguageHaskell2010

HsLua.Packaging.Function

Description

Marshaling and documenting Haskell functions.

Synopsis

Documentation

data DocumentedFunction e Source #

Haskell equivallent to CFunction, i.e., function callable from Lua.

Creating documented functions

defun :: Name -> a -> HsFnPrecursor e a Source #

Begin wrapping a monadic Lua function such that it can be turned into a documented function exposable to Lua.

lambda :: a -> HsFnPrecursor e a Source #

Just like defun, but uses an empty name for the documented function. Should be used when defining methods or operators.

applyParameter :: HsFnPrecursor e (a -> b) -> Parameter e a -> HsFnPrecursor e b Source #

Partially apply a parameter.

returnResult :: HsFnPrecursor e (LuaE e a) -> FunctionResult e a -> DocumentedFunction e Source #

Like returnResult, but returns only a single result.

returnResultsOnStack :: HsFnPrecursor e (LuaE e NumResults) -> Text -> DocumentedFunction e Source #

Take a HaskellFunction precursor and convert it into a full HaskellFunction, using the given FunctionResults to return the result to Lua.

liftPure :: (a -> b) -> a -> LuaE e b Source #

Turns a pure function into a monadic Lua function.

The resulting function is strict.

liftPure2 :: (a -> b -> c) -> a -> b -> LuaE e c Source #

Turns a binary function into a Lua function.

The resulting function is strict in both its arguments.

liftPure3 :: (a -> b -> c -> d) -> a -> b -> c -> LuaE e d Source #

Turns a ternary function into a Lua function.

The resulting function is strict in all of its arguments.

liftPure4 :: (a -> b -> c -> d -> e) -> a -> b -> c -> d -> LuaE err e Source #

Turns a quarternary function into a Lua function.

The resulting function is strict in all of its arguments.

liftPure5 :: (a -> b -> c -> d -> e -> f) -> a -> b -> c -> d -> e -> LuaE err f Source #

Turns a quinary function into a Lua function.

The resulting function is strict in all of its arguments.

Types

data Parameter e a Source #

Function parameter.

Constructors

Parameter 

data FunctionResult e a Source #

Result of a call to a Haskell function.

type FunctionResults e a = [FunctionResult e a] Source #

List of function results in the order in which they are returned in Lua.

Operators

(###) :: (a -> HsFnPrecursor e a) -> a -> HsFnPrecursor e a infixl 8 Source #

Like ($), but left associative.

(<#>) :: HsFnPrecursor e (a -> b) -> Parameter e a -> HsFnPrecursor e b infixl 8 Source #

Inline version of applyParameter.

(=#>) :: HsFnPrecursor e (LuaE e a) -> FunctionResults e a -> DocumentedFunction e infixl 8 Source #

Inline version of returnResults.

(=?>) :: HsFnPrecursor e (LuaE e NumResults) -> Text -> DocumentedFunction e infixl 8 Source #

Return a flexible number of results that have been pushed by the function action.

(#?) :: DocumentedFunction e -> Text -> DocumentedFunction e infixl 8 Source #

Inline version of updateFunctionDescription.

Modifying functions

setName :: Name -> DocumentedFunction e -> DocumentedFunction e Source #

Renames a documented function.

since :: DocumentedFunction e -> Version -> DocumentedFunction e infixl 8 Source #

Sets the library version at which the function was introduced in its current form.

Pushing to Lua

pushDocumentedFunction :: LuaError e => DocumentedFunction e -> LuaE e () Source #

Pushes a documented Haskell function to the Lua stack, making it usable as a normal function in Lua. At the same time, the function docs are registered in the documentation table.

Accessing documentation in Lua

docsField :: Name Source #

Name of the registry field holding the documentation table. The documentation table is indexed by the documented objects, like module tables and functions, and contains documentation strings as values.

The table is an ephemeron table, i.e., an entry gets garbage collected if the key is no longer reachable.

pushDocumentation :: LuaError e => StackIndex -> LuaE e NumResults Source #

Pushes the documentation of the object at the given index to the stack, or just *nil* if no documentation is available.

Convenience functions

parameter Source #

Arguments

:: Peeker e a

method to retrieve value from Lua

-> Text

expected Lua type

-> Text

parameter name

-> Text

parameter description

-> Parameter e a 

Creates a parameter.

optionalParameter Source #

Arguments

:: Peeker e a

method to retrieve the value from Lua

-> Text

expected Lua type

-> Text

parameter name

-> Text

parameter description

-> Parameter e (Maybe a) 

Creates an optional parameter.

functionResult Source #

Arguments

:: Pusher e a

method to push the Haskell result to Lua

-> Text

Lua type of result

-> Text

result description

-> FunctionResults e a 

Creates a function result.

Internal

toHsFnPrecursor :: StackIndex -> Name -> a -> HsFnPrecursor e a Source #

Create a HaskellFunction precursor from a monadic function, selecting the stack index after which the first function parameter will be placed.