hslua-1.0.3.2: Bindings to Lua, an embeddable scripting language

Copyright© 2007–2012 Gracjan Polak
2012–2016 Ömer Sinan Ağacan
2017-2019 Albert Krewinkel
LicenseMIT
MaintainerAlbert Krewinkel <tarleb+hslua@zeitkraut.de>
Stabilitybeta
Portabilitynon-portable (depends on GHC)
Safe HaskellNone
LanguageHaskell2010

Foreign.Lua.Userdata

Description

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

Documentation

pushAny :: Data a => a -> Lua () Source #

Push data by wrapping it into a userdata object.

pushAnyWithMetatable Source #

Arguments

:: Lua ()

operation to push the metatable

-> a

object to push to Lua.

-> Lua () 

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.

toAnyWithName Source #

Arguments

:: StackIndex 
-> String

expected metatable name

-> Lua (Maybe a) 

Retrieve data which has been pushed with pushAnyWithMetatable, where *name* must is the value of the __name field of the metatable.

peekAny :: Data a => StackIndex -> Lua a Source #

Retrieve Haskell data which was pushed to Lua as userdata.

ensureUserdataMetatable Source #

Arguments

:: 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.