Copyright | © 2007–2012 Gracjan Polak 2012–2016 Ömer Sinan Ağacan 2017-2020 Albert Krewinkel |
---|---|
License | MIT |
Maintainer | Albert Krewinkel <tarleb+hslua@zeitkraut.de> |
Stability | beta |
Portability | non-portable (depends on GHC) |
Safe Haskell | None |
Language | Haskell2010 |
Convenience functions to convert Haskell values into Lua userdata.
The main purpose of this module is to allow fast and simple
creation of instances for Peekable
and Pushable
. E.g., given
a data type Person
data Person = Person { name :: String, age :: Int } deriving (Eq, Show, Typeable, Data)
we can simply do
instance Lua.Peekable Person where safePeek = safePeekAny instance Lua.Pushable Person where push = pushAny
The other functions can be used to exert more control over the userdata wrapping and unwrapping process.
Synopsis
- pushAny :: Data a => a -> Lua ()
- pushAnyWithMetatable :: Lua () -> a -> Lua ()
- toAny :: Data a => StackIndex -> Lua (Maybe a)
- toAnyWithName :: StackIndex -> String -> Lua (Maybe a)
- peekAny :: Data a => StackIndex -> Lua a
- ensureUserdataMetatable :: String -> Lua () -> Lua ()
- metatableName :: Data a => a -> String
Documentation
Push data by wrapping it into a userdata object, using the object at the top of the stack after performing the given operation as metatable.
toAny :: Data a => StackIndex -> Lua (Maybe a) Source #
Retrieve data which has been pushed with
.pushAny
:: StackIndex | |
-> String | expected metatable name |
-> Lua (Maybe a) |
Retrieve data which has been pushed with
, where
*name* must is the value of the pushAnyWithMetatable
__name
field of the metatable.
peekAny :: Data a => StackIndex -> Lua a Source #
Retrieve Haskell data which was pushed to Lua as userdata.
ensureUserdataMetatable Source #
:: String | name of the registered metatable which should be used. |
-> Lua () | set additional properties; this operation will be called with the newly created metadata table at the top of the stack. |
-> Lua () |
Push the metatable used to define the behavior of the given value in Lua. The table will be created if it doesn't exist yet.
metatableName :: Data a => a -> String Source #
Return the default name for userdata to be used when wrapping an object as the given type as userdata. The argument is never evaluated.