hslua-aeson-2.3.1.1: Allow aeson data types to be used with Lua.

Copyright | © 2017-2024 Albert Krewinkel
License | MIT
Maintainer | Albert Krewinkel <tarleb@hslua.org>
Safe Haskell | None
Language | Haskell2010

HsLua.Aeson

Contents

- Encoding arbitrary objects

Description

Pushes and retrieves aeson `Value`s to and from the Lua stack.

- JSON `null` values are encoded as light userdata containing the `NULL` pointer.
- Objects are converted to string-indexed tables.
- Arrays are converted to sequence tables and are given a metatable. This makes it possible to distinguish between empty arrays and empty objects. The metatable is stored in the registry under key `'HsLua JSON array'`' (see also `jsonarray`).
- JSON numbers are converted to Lua numbers, i.e., `Number`; the exact C type may vary, depending on compile-time Lua configuration.

Synopsis

- peekValue :: LuaError e => Peeker e Value
- pushValue :: LuaError e => Pusher e Value
- peekViaJSON :: (FromJSON a, LuaError e) => Peeker e a
- pushViaJSON :: (ToJSON a, LuaError e) => Pusher e a
- jsonarray :: Name
- peekToAeson :: Peeker e (ToAeson e)
- pushToAeson :: Pusher e (ToAeson e)

# Documentation

peekValue :: LuaError e => Peeker e Value Source #

Retrieves an Aeson `Value` from the Lua stack.

pushValue :: LuaError e => Pusher e Value Source #

Hslua StackValue instance for the Aeson Value data type.

peekViaJSON :: (FromJSON a, LuaError e) => Peeker e a Source #

Retrieves a value from the Lua stack via JSON.

pushViaJSON :: (ToJSON a, LuaError e) => Pusher e a Source #

Pushes a value to the Lua stack as a JSON-like value.

jsonarray :: Name Source #

Name of the registry slot holding the metatable given to array tables. The registry entry can be replaced with a different table if needed.

# Encoding arbitrary objects

peekToAeson :: Peeker e (ToAeson e) Source #

Gets the `ToAeson` function from a Lua userdata object.

pushToAeson :: Pusher e (ToAeson e) Source #

Pushes a function that converts the object at a given index into a `Value`.