HsLua.Typing

hslua-typing-0.1.1: Type specifiers for Lua.

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

HsLua.Typing

Contents

- Types
  - Built-in types
  - Type constructors
- Marshalling

Description

The module provides Haskell types and values that can be used to describe and declare the types of Lua values.

Synopsis

- data TypeSpec
  - = BasicType Type
  - | NamedType Name
  - | SeqType TypeSpec
  - | SumType [TypeSpec]
  - | RecType (Map Name TypeSpec)
  - | FunType [TypeSpec] [TypeSpec]
  - | AnyType
- data TypeDocs = TypeDocs {
  - typeDescription :: Text
  - typeSpec :: TypeSpec
  - typeRegistry :: Maybe Name
  }
- (#|#) :: TypeSpec -> TypeSpec -> TypeSpec
- typeSpecToString :: TypeSpec -> String
- typeSpecFromString :: String -> TypeSpec
- anyType :: TypeSpec
- voidType :: TypeSpec
- booleanType :: TypeSpec
- functionType :: TypeSpec
- integerType :: TypeSpec
- lightUserdataType :: TypeSpec
- nilType :: TypeSpec
- numberType :: TypeSpec
- stringType :: TypeSpec
- tableType :: TypeSpec
- threadType :: TypeSpec
- userdataType :: TypeSpec
- recType :: [(Name, TypeSpec)] -> TypeSpec
- seqType :: TypeSpec -> TypeSpec
- pushTypeSpec :: LuaError e => TypeSpec -> LuaE e ()
- peekTypeSpec :: LuaError e => Peeker e TypeSpec
- pushTypeDoc :: LuaError e => Pusher e TypeDocs
- peekTypeDoc :: LuaError e => Peeker e TypeDocs

# Documentation

data TypeSpec #

Type specification for Lua values.

Constructors

BasicType Type | Built-in type
NamedType Name | A type that's been given a name.
SeqType TypeSpec | Sequence of the given type.
SumType [TypeSpec] | Union type; a sum type.
RecType (Map Name TypeSpec) | Record type (type product).
FunType [TypeSpec] [TypeSpec] | Function type.
AnyType | Unconstrained type.

#### Instances

Instances details

IsString TypeSpec # | For backwards compatibility and convenience, strings can be used as TypeSpec values.
Instance details Defined in HsLua.Typing Methods fromString :: String -> TypeSpec #
Generic TypeSpec # |
Instance details Defined in HsLua.Typing Associated Types
type Rep TypeSpec |
Instance details Defined in HsLua.Typing type Rep TypeSpec = D1 ('MetaData "TypeSpec" "HsLua.Typing" "hslua-typing-0.1.1-5a1fQvybSkBxQjQzI9Gk5" 'False) ((C1 ('MetaCons "BasicType" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Type)) :+: (C1 ('MetaCons "NamedType" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Name)) :+: C1 ('MetaCons "SeqType" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 TypeSpec)))) :+: ((C1 ('MetaCons "SumType" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 [TypeSpec])) :+: C1 ('MetaCons "RecType" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Map Name TypeSpec)))) :+: (C1 ('MetaCons "FunType" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 [TypeSpec]) :*: S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 [TypeSpec])) :+: C1 ('MetaCons "AnyType" 'PrefixI 'False) (U1 :: Type -> Type))))
Methods from :: TypeSpec -> Rep TypeSpec x # to :: Rep TypeSpec x -> TypeSpec #
Show TypeSpec # |
Instance details Defined in HsLua.Typing Methods showsPrec :: Int -> TypeSpec -> ShowS # show :: TypeSpec -> String # showList :: [TypeSpec] -> ShowS #
Eq TypeSpec # |
Instance details Defined in HsLua.Typing Methods (==) :: TypeSpec -> TypeSpec -> Bool # (/=) :: TypeSpec -> TypeSpec -> Bool #
Ord TypeSpec # |
Instance details Defined in HsLua.Typing Methods compare :: TypeSpec -> TypeSpec -> Ordering # (<) :: TypeSpec -> TypeSpec -> Bool # (<=) :: TypeSpec -> TypeSpec -> Bool # (>) :: TypeSpec -> TypeSpec -> Bool # (>=) :: TypeSpec -> TypeSpec -> Bool # max :: TypeSpec -> TypeSpec -> TypeSpec # min :: TypeSpec -> TypeSpec -> TypeSpec #
type Rep TypeSpec # |
Instance details Defined in HsLua.Typing type Rep TypeSpec = D1 ('MetaData "TypeSpec" "HsLua.Typing" "hslua-typing-0.1.1-5a1fQvybSkBxQjQzI9Gk5" 'False) ((C1 ('MetaCons "BasicType" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Type)) :+: (C1 ('MetaCons "NamedType" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Name)) :+: C1 ('MetaCons "SeqType" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 TypeSpec)))) :+: ((C1 ('MetaCons "SumType" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 [TypeSpec])) :+: C1 ('MetaCons "RecType" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Map Name TypeSpec)))) :+: (C1 ('MetaCons "FunType" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 [TypeSpec]) :*: S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 [TypeSpec])) :+: C1 ('MetaCons "AnyType" 'PrefixI 'False) (U1 :: Type -> Type))))

data TypeDocs #

Documented custom type.

Constructors

TypeDocs |
Fields typeDescription :: Text typeSpec :: TypeSpec typeRegistry :: Maybe Name

#### Instances

Instances details

Generic TypeDocs # |
Instance details Defined in HsLua.Typing Associated Types
type Rep TypeDocs |
Instance details Defined in HsLua.Typing type Rep TypeDocs = D1 ('MetaData "TypeDocs" "HsLua.Typing" "hslua-typing-0.1.1-5a1fQvybSkBxQjQzI9Gk5" 'False) (C1 ('MetaCons "TypeDocs" 'PrefixI 'True) (S1 ('MetaSel ('Just "typeDescription") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Text) :*: (S1 ('MetaSel ('Just "typeSpec") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 TypeSpec) :*: S1 ('MetaSel ('Just "typeRegistry") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Maybe Name)))))
Methods from :: TypeDocs -> Rep TypeDocs x # to :: Rep TypeDocs x -> TypeDocs #
Show TypeDocs # |
Instance details Defined in HsLua.Typing Methods showsPrec :: Int -> TypeDocs -> ShowS # show :: TypeDocs -> String # showList :: [TypeDocs] -> ShowS #
Eq TypeDocs # |
Instance details Defined in HsLua.Typing Methods (==) :: TypeDocs -> TypeDocs -> Bool # (/=) :: TypeDocs -> TypeDocs -> Bool #
Ord TypeDocs # |
Instance details Defined in HsLua.Typing Methods compare :: TypeDocs -> TypeDocs -> Ordering # (<) :: TypeDocs -> TypeDocs -> Bool # (<=) :: TypeDocs -> TypeDocs -> Bool # (>) :: TypeDocs -> TypeDocs -> Bool # (>=) :: TypeDocs -> TypeDocs -> Bool # max :: TypeDocs -> TypeDocs -> TypeDocs # min :: TypeDocs -> TypeDocs -> TypeDocs #
type Rep TypeDocs # |
Instance details Defined in HsLua.Typing type Rep TypeDocs = D1 ('MetaData "TypeDocs" "HsLua.Typing" "hslua-typing-0.1.1-5a1fQvybSkBxQjQzI9Gk5" 'False) (C1 ('MetaCons "TypeDocs" 'PrefixI 'True) (S1 ('MetaSel ('Just "typeDescription") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Text) :*: (S1 ('MetaSel ('Just "typeSpec") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 TypeSpec) :*: S1 ('MetaSel ('Just "typeRegistry") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Maybe Name)))))

(#|#) :: TypeSpec -> TypeSpec -> TypeSpec #

Returns the sum of two type specifiers, declaring that a Lua value can have either type.

typeSpecToString :: TypeSpec -> String #

Generate a string representation of the type specifier.

typeSpecFromString :: String -> TypeSpec #

Creates a `TypeSpec` value from a string.

The implementation currently handles basic types, sequences, and alternatives. A string that cannot be parsed is returned as a `Named` type with the full string as the name.

# Types

anyType :: TypeSpec #

Unconstraint type; any Lua value.

voidType :: TypeSpec #

A type for which there cannot be any value.

## Built-in types

booleanType :: TypeSpec #

The built-in `boolean` Lua type.

functionType :: TypeSpec #

The built-in `function` Lua type.

integerType :: TypeSpec #

A Lua integer type.

lightUserdataType :: TypeSpec #

The built-in `light userdata` Lua type.

nilType :: TypeSpec #

The built-in `nil` Lua type.

numberType :: TypeSpec #

The built-in `number` Lua type.

stringType :: TypeSpec #

The built-in `string` Lua type.

tableType :: TypeSpec #

The built-in `table` Lua type.

threadType :: TypeSpec #

The built-in `thread` Lua type.

userdataType :: TypeSpec #

The built-in `userdata` Lua type.

## Type constructors

recType :: [(Name, TypeSpec)] -> TypeSpec #

Creates a record type.

seqType :: TypeSpec -> TypeSpec #

Creates a sequence type.

# Marshalling

pushTypeSpec :: LuaError e => TypeSpec -> LuaE e () #

Pushes a table representation of a `TypeSpec` to the stack.

peekTypeSpec :: LuaError e => Peeker e TypeSpec #

Retrieves a `TypeSpec` from a table on the stack.

pushTypeDoc :: LuaError e => Pusher e TypeDocs #

Pushes documentation for a custom type.

peekTypeDoc :: LuaError e => Peeker e TypeDocs #

Retrieves a custom type specifier.