Function to retrieve a value from Lua's stack.
Modulehslua-marshalling-2.3.1Haskell2010
HsLua.Marshalling
Functions to push and retrieve data to and from Lua.
- 3 types
- 38 values
- Packagehslua-marshalling-2.3.1
- Exports41
- LanguageHaskell2010
- LicenceMIT
- SourceMarshalling.hs
Receiving values from Lua stack (Lua → Haskell)
7 declarationsRuns the peeker function.
Record to keep track of failure contexts while retrieving objects from the Lua stack.
Constructors
Success !aFailure ByteString [Name]Error message and stack of contexts
Instances10Monad, Functor, MonadFail, Applicative, Foldable, Traversable, …
Monad ResultDefined in hslua-marshalling-2.3.1 · HsLua.Marshalling.PeekFunctor ResultDefined in hslua-marshalling-2.3.1 · HsLua.Marshalling.PeekMonadFail ResultDefined in hslua-marshalling-2.3.1 · HsLua.Marshalling.PeekApplicative ResultDefined in hslua-marshalling-2.3.1 · HsLua.Marshalling.PeekFoldable ResultDefined in hslua-marshalling-2.3.1 · HsLua.Marshalling.PeekTraversable ResultDefined in hslua-marshalling-2.3.1 · HsLua.Marshalling.PeekAlternative ResultDefined in hslua-marshalling-2.3.1 · HsLua.Marshalling.PeekMonadPlus ResultDefined in hslua-marshalling-2.3.1 · HsLua.Marshalling.PeekEq a => Eq (Result a)Defined in hslua-marshalling-2.3.1 · HsLua.Marshalling.PeekShow a => Show (Result a)Defined in hslua-marshalling-2.3.1 · HsLua.Marshalling.Peek
Force creation of an unwrapped result, throwing an exception if that's not possible.
Add context information to the peek traceback stack.
Create a peek failure record from an error message.
Converts a Result into an Either, where Left holds the reportable
string in case of an failure.
Primitive types
Succeeds if the value at the given index is nil.
Succeeds if the given index is not valid or if the value at this
index is nil.
Retrieves a Bool as a Lua boolean.
Retrieves an Integral value from the Lua stack.
Strings
Retrieves a ByteString as a raw string.
Retrieves a lazy ByteString as a raw string.
Retrieves a String from an UTF-8 encoded Lua string.
Retrieves a Text value as an UTF-8 encoded string.
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.
Retrieves a Lua string as Name.
Readable types
Retrieves a value by getting a String from Lua, then using readMaybe to convert the String into a Haskell value.
Collections
Read a table into a list of pairs.
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.
Retrieves a key-value Lua table as Map.
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
Try all peekers and return the result of the first to succeed.
Get value at key from a table.
Retrieves a value pair from a table. Expects the values to be stored in a numerically indexed table; does not access metamethods.
Retrieves a value triple from a table. Expects the values to be stored in a numerically indexed table, with no metamethods.
Returns empty if the value at the given index is nil;
otherwise returns the result of peeker p.
Returns empty if the value at the given index is none;
otherwise returns the result of peeker p.
Returns empty if the value at the given index is none or
nil; otherwise returns the result of peeker p.
Lua peek monad
Lua operation with an additional failure mode that can stack errors from different contexts; errors are not based on exceptions).
Instances6Monad, Functor, MonadFail, Applicative, Alternative, MonadPlus
Monad (Peek e)Defined in hslua-marshalling-2.3.1 · HsLua.Marshalling.PeekFunctor (Peek e)Defined in hslua-marshalling-2.3.1 · HsLua.Marshalling.PeekMonadFail (Peek e)Defined in hslua-marshalling-2.3.1 · HsLua.Marshalling.PeekApplicative (Peek e)Defined in hslua-marshalling-2.3.1 · HsLua.Marshalling.PeekAlternative (Peek e)Defined in hslua-marshalling-2.3.1 · HsLua.Marshalling.PeekMonadPlus (Peek e)Defined in hslua-marshalling-2.3.1 · HsLua.Marshalling.Peek
Converts a Peek action into a LuaE action, throwing an exception in case of a peek failure.
Lifts a Lua operation into the Peek monad.
Transform the result using the given function.
Fails the peek operation.
Runs the peek action and Lua action in sequence, even if the peek action fails.
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
typeChecked 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.
typeMismatchMessage :: Nameexpected type
-> StackIndexindex of offending value
-> Peek e ByteString
Generate a type mismatch error.
Report the expected and actual type of the value under the given index if conversion failed.
Pushing values to Lua stack (Haskell → Lua)
0 declarationsmodule HsLua.Marshalling.Push
Utilities
1 declarationpushIterator :: LuaError e=> (a -> LuaE e NumResults)pusher for the values
-> [a]list to iterate over lazily
-> 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.