HORIZON HASKELLDocslts/ghc-9.10.xc74966e2026-09-27Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · c74966e · 2026-09-27

Modulehslua-marshalling-2.3.1Haskell2010

HsLua.Marshalling

Functions to push and retrieve data to and from Lua.

  • 3 types
  • 38 values

Receiving values from Lua stack (Lua → Haskell)

7 declarations
datadata Result a
#

Record to keep track of failure contexts while retrieving objects from the Lua stack.

Constructors

Instances10Monad, Functor, MonadFail, Applicative, Foldable, Traversable, …
  • Monad ResultDefined in hslua-marshalling-2.3.1 · HsLua.Marshalling.Peek
  • Functor ResultDefined in hslua-marshalling-2.3.1 · HsLua.Marshalling.Peek
  • MonadFail ResultDefined in hslua-marshalling-2.3.1 · HsLua.Marshalling.Peek
  • Applicative ResultDefined in hslua-marshalling-2.3.1 · HsLua.Marshalling.Peek
  • Foldable ResultDefined in hslua-marshalling-2.3.1 · HsLua.Marshalling.Peek
  • Traversable ResultDefined in hslua-marshalling-2.3.1 · HsLua.Marshalling.Peek
  • Alternative ResultDefined in hslua-marshalling-2.3.1 · HsLua.Marshalling.Peek
  • MonadPlus ResultDefined in hslua-marshalling-2.3.1 · HsLua.Marshalling.Peek
  • Eq a => Eq (Result a)Defined in hslua-marshalling-2.3.1 · HsLua.Marshalling.Peek
  • Show a => Show (Result a)Defined in hslua-marshalling-2.3.1 · HsLua.Marshalling.Peek
valueforce :: LuaError e => Result a -> LuaE e a
#

Force creation of an unwrapped result, throwing an exception if that's not possible.

Primitive types

valuepeekNil :: Peeker e ()
#

Succeeds if the value at the given index is nil.

valuepeekNoneOrNil :: Peeker e ()
#

Succeeds if the given index is not valid or if the value at this index is nil.

Strings

valuepeekStringy :: IsString a => Peeker e a
#

Retrieves a String-like value from an UTF-8 encoded Lua string.

This should not be used to peek ByteString values or other values for which construction via fromString can result in loss of information.

Readable types

valuepeekRead :: Read a => Peeker e a
#

Retrieves a value by getting a String from Lua, then using readMaybe to convert the String into a Haskell value.

Collections

valuepeekList :: LuaError e => Peeker e a -> Peeker e [a]
#

Reads a numerically indexed table t into a list, where the length of the list is equal to rawlen(t). The operation will fail unless all numerical fields between 1 and rawlen(t) can be retrieved.

valuepeekSet :: (LuaError e, Ord a) => Peeker e a -> Peeker e (Set a)
#

Retrieves a Set from an idiomatic Lua representation. A set in Lua is idiomatically represented as a table with the elements as keys. Elements with falsy values are omitted.

Combinators

valuepeekPair :: LuaError e => Peeker e a -> Peeker e b -> Peeker e (a, b)
#

Retrieves a value pair from a table. Expects the values to be stored in a numerically indexed table; does not access metamethods.

valuepeekTriple
  1. :: LuaError e
  2. => Peeker e a
  3. -> Peeker e b
  4. -> Peeker e c
  5. -> Peeker e (a, b, c)
#

Retrieves a value triple from a table. Expects the values to be stored in a numerically indexed table, with no metamethods.

Lua peek monad

newtypenewtype Peek e a
#

Lua operation with an additional failure mode that can stack errors from different contexts; errors are not based on exceptions).

Constructors

Instances6Monad, Functor, MonadFail, Applicative, Alternative, MonadPlus
  • Monad (Peek e)Defined in hslua-marshalling-2.3.1 · HsLua.Marshalling.Peek
  • Functor (Peek e)Defined in hslua-marshalling-2.3.1 · HsLua.Marshalling.Peek
  • MonadFail (Peek e)Defined in hslua-marshalling-2.3.1 · HsLua.Marshalling.Peek
  • Applicative (Peek e)Defined in hslua-marshalling-2.3.1 · HsLua.Marshalling.Peek
  • Alternative (Peek e)Defined in hslua-marshalling-2.3.1 · HsLua.Marshalling.Peek
  • MonadPlus (Peek e)Defined in hslua-marshalling-2.3.1 · HsLua.Marshalling.Peek
valueforcePeek :: LuaError e => Peek e a -> LuaE e a
#

Converts a Peek action into a LuaE action, throwing an exception in case of a peek failure.

valueliftLua :: LuaE e a -> Peek e a
#

Lifts a Lua operation into the Peek monad.

valuelastly :: Peek e a -> LuaE e b -> Peek e a
#

Runs the peek action and Lua action in sequence, even if the peek action fails.

valuecleanup :: Peek e a -> Peek e a
#

Runs the peek action, resetting the stack top afterwards. This can be used with peek actions that might otherwise leave elements on the stack in case of a failure.

Building Peek functions

valuetypeChecked
  1. :: Name

    expected type

  2. -> (StackIndex -> LuaE e Bool)

    pre-condition checker

  3. -> Peeker e a
  4. -> Peeker e a
#

Use test to check whether the value at stack index n has the correct type and use peekfn to convert it to a Haskell value if possible. A successfully received value is wrapped using the Right constructor, while a type mismatch results in Left PeekError with the given error message.

Pushing values to Lua stack (Haskell → Lua)

0 declarations

Utilities

1 declaration
valuepushIterator
  1. :: LuaError e
  2. => (a -> LuaE e NumResults)

    pusher for the values

  3. -> [a]

    list to iterate over lazily

  4. -> LuaE e NumResults
#

Pushes three values to the stack that can be used in a generic for loop to lazily iterate over all values in the list. Keeps the remaining list in a userdata state.

If the values pusher function returns NumResults 0 for a list item, then this item will be skipped and the values for the next item will be pushed.