A userdata type, capturing the behavior of Lua objects that wrap Haskell values. The type name must be unique; once the type has been used to push or retrieve a value, the behavior can no longer be modified through this type.
Modulehslua-objectorientation-2.3.1Haskell2010
HsLua.ObjectOrientation
This module provides types and functions to use Haskell values as userdata objects in Lua. These objects wrap a Haskell value and provide methods and properties to interact with the Haskell value.
The terminology in this module refers to the userdata values as /UD objects, and to their type as UD type/.
- 9 types
- 15 values
- Packagehslua-objectorientation-2.3.1
- Exports24
- LanguageHaskell2010
- LicenceMIT
- SourceObjectOrientation.hs
A userdata type, capturing the behavior of Lua objects that wrap Haskell values. The type name must be unique; once the type has been used to push or retrieve a value, the behavior can no longer be modified through this type.
This type includes methods to define how the object should behave as
a read-only list of type itemtype.
Constructors
UDTypeWithListudName :: NameudOperations :: [(Operation, fn)]udProperties :: Map Name (Property e a)udMethods :: Map Name fnudAliases :: Map AliasIndex AliasudListSpec :: Maybe (ListSpec e a itemtype)udFnPusher :: fn -> LuaE e ()
Defining types
2 declarationsdeftypeGeneric Defines a new type, defining the behavior of objects in Lua. Note that the type name must be unique.
deftypeGeneric' Defines a new type that could also be treated as a list; defines the behavior of objects in Lua. Note that the type name must be unique.
Methods
Use a documented function as an object method.
Properties
property Declares a new read- and writable property.
property' Declares a new read- and writable typed property.
possibleProperty Declares a new read- and writable property which is not always available.
possibleProperty' Declares a new read- and writable property which is not always available.
readonly Creates a read-only object property. Attempts to set the value will cause an error.
readonly' Creates a read-only object property. Attempts to set the value will cause an error.
Aliases
alias :: AliasIndexproperty alias
-> Textdescription
-> [AliasIndex]sequence of nested properties
-> Member e fn a
Define an alias for another, possibly nested, property.
Marshaling
3 declarationsRetrieves a userdata value of the given type.
pushUDGeneric :: LuaError e=> (UDTypeWithList e fn a itemtype -> LuaE e ())push docs
-> UDTypeWithList e fn a itemtypeuserdata type
-> avalue to push
-> LuaE e ()
Pushes a userdata value of the given type.
Ensures that the type has been fully initialized, i.e., that all metatables have been created and stored in the registry. Returns the name of the initialized type.
The hook can be used to perform additional setup operations. The
function is called as the last step after the type metatable has been
initialized: the fully initialized metatable will be at the top of
the stack at that point. Note that the hook will not be called if
the type's metatable already existed before this function was
invoked.
Type docs
2 declarationsReturns documentation for this type.
Type specifier for a UDType
Helper types for building
7 declarationsA type member, either a method or a variable.
A read- and writable property on a UD object.
Constructors
PropertypropertyGet :: a -> LuaE e NumResultspropertySet :: Maybe (StackIndex -> a -> LuaE e a)propertyDescription :: TextpropertyType :: TypeSpec
Lua metadata operation types.
Constructors
Addthe addition (
+) operation. If any operand for an addition is not a number (nor a string coercible to a number), Lua will try to call a metamethod. First, Lua will check the first operand (even if it is valid). If that operand does not define a metamethod for__add, then Lua will check the second operand. If Lua can find a metamethod, it calls the metamethod with the two operands as arguments, and the result of the call (adjusted to one value) is the result of the operation. Otherwise, it raises an error.Subthe subtraction (
-) operation. Behavior similar to the addition operation.Multhe multiplication (
*) operation. Behavior similar to the addition operation.Divthe division (
/) operation. Behavior similar to the addition operation.Modthe modulo (
%) operation. Behavior similar to the addition operation.Powthe exponentiation (
^) operation. Behavior similar to the addition operation.Unmthe negation (unary
-) operation. Behavior similar to the addition operation.Idivthe floor division (
//) operation. Behavior similar to the addition operation.Bandthe bitwise AND (
&) operation. Behavior similar to the addition operation, except that Lua will try a metamethod if any operand is neither an integer nor a value coercible to an integer (see §3.4.3).Borthe bitwise OR (
|) operation. Behavior similar to the bitwise AND operation.Bxorthe bitwise exclusive OR (binary
~) operation. Behavior similar to the bitwise AND operation.Bnotthe bitwise NOT (unary
~) operation. Behavior similar to the bitwise AND operation.Shlthe bitwise left shift (
<<) operation. Behavior similar to the bitwise AND operation.Shrthe bitwise right shift (
>>) operation. Behavior similar to the bitwise AND operation.Concatthe concatenation (
..) operation. Behavior similar to the addition operation, except that Lua will try a metamethod if any operand is neither a string nor a number (which is always coercible to a string).Lenthe length (
#) operation. If the object is not a string, Lua will try its metamethod. If there is a metamethod, Lua calls it with the object as argument, and the result of the call (always adjusted to one value) is the result of the operation. If there is no metamethod but the object is a table, then Lua uses the table length operation (see §3.4.7). Otherwise, Lua raises an error.Eqthe equal (
==) operation. Behavior similar to the addition operation, except that Lua will try a metamethod only when the values being compared are either both tables or both full userdata and they are not primitively equal. The result of the call is always converted to a boolean.Ltthe less than (
<) operation. Behavior similar to the addition operation, except that Lua will try a metamethod only when the values being compared are neither both numbers nor both strings. The result of the call is always converted to a boolean.Lethe less equal (
<=) operation. Unlike other operations, the less-equal operation can use two different events. First, Lua looks for the__lemetamethod in both operands, like in the less than operation. If it cannot find such a metamethod, then it will try the__ltmetamethod, assuming that a <= b is equivalent to not (b < a). As with the other comparison operators, the result is always a boolean. (This use of the__ltevent can be removed in future versions; it is also slower than a real __le metamethod.)IndexThe indexing access operation
table[key]. This event happens when table is not a table or when key is not present in table. The metamethod is looked up in table.NewindexThe indexing assignment
table[key] = value. Like the index event, this event happens when table is not a table or when key is not present in table. The metamethod is looked up in table.CallThe call operation
func(args). This event happens when Lua tries to call a non-function value (that is, func is not a function). The metamethod is looked up in func. If present, the metamethod is called with func as its first argument, followed by the arguments of the original call (args). All results of the call are the result of the operation. (This is the only metamethod that allows multiple results.)TostringThe operation used to create a string representation of the object.
Pairsthe operation of iterating over the object's key-value pairs.
CustomOperation Namea custom operation, with the metamethod name as parameter.
type ListSpec e a itemtype = ((Pusher e itemtype, a -> [itemtype]), (Peeker e itemtype, a -> [itemtype] -> a))Pair of pairs, describing how a type can be used as a Lua list. The first pair describes how to push the list items, and how the list is extracted from the type; the second pair contains a method to retrieve list items, and defines how the list is used to create an updated value.
Alias for a different property of this or of a nested object.
Index types allowed in aliases (strings and integers)
Constructors
Instances3Eq, Ord, IsString
Eq AliasIndexDefined in hslua-objectorientation-2.3.1 · HsLua.ObjectOrientationOrd AliasIndexDefined in hslua-objectorientation-2.3.1 · HsLua.ObjectOrientationIsString AliasIndexDefined in hslua-objectorientation-2.3.1 · HsLua.ObjectOrientation