hslua-core-2.3.2: Bindings to Lua, an embeddable scripting language

Copyright | © 2007–2012 Gracjan Polak; © 2012–2016 Ömer Sinan Ağacan; © 2017-2024 Albert Krewinkel
License | MIT
Maintainer | Albert Krewinkel <tarleb@hslua.org>
Stability | beta
Portability | non-portable (depends on GHC)
Safe Haskell | None
Language | Haskell2010

HsLua.Core.Userdata

Description

Convenience functions to convert Haskell values into Lua userdata.

Synopsis

- newhsuserdatauv :: a -> Int -> LuaE e ()
- newudmetatable :: Name -> LuaE e Bool
- fromuserdata :: forall a e. StackIndex -> Name -> LuaE e (Maybe a)
- putuserdata :: StackIndex -> Name -> a -> LuaE e Bool

# Documentation

newhsuserdatauv #

Arguments

:: a | Haskell object
-> Int | number of extra userdata values
-> LuaE e () |

Creates a new userdata wrapping the given Haskell object. The userdata is pushed to the top of the stack.

newudmetatable :: Name -> LuaE e Bool #

Creates and registers a new metatable for a userdata-wrapped Haskell value; checks whether a metatable of that name has been registered yet and uses the registered table if possible.

Returns `True` if a new metatable was created, and `False` otherwise.

Using a metatable created by this functions ensures that the pointer to the Haskell value will be freed when the userdata object is garbage collected in Lua.

The name may not contain a nul character.

fromuserdata #

Arguments

:: forall a e. StackIndex | stack index of userdata
-> Name | expected name of userdata object
-> LuaE e (Maybe a) |

Retrieves a Haskell object from userdata at the given index. The userdata must have the given name.

putuserdata #

Arguments

:: StackIndex | index
-> Name | name
-> a | new value
-> LuaE e Bool |

Replaces the Haskell value contained in the userdata value at `index`. Checks that the userdata is of type `name` and returns `True` on success, or `False` otherwise.