hslua-typing-0.2.0: Type specifiers for Lua.

Copyright | © 2023-2026 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
- (#|#) :: 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

# Documentation

data TypeSpec Source #

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 Source # | For backwards compatibility and convenience, strings can be used as TypeSpec values.
Instance details Defined in HsLua.Typing Methods fromString :: String -> TypeSpec Source #
Generic TypeSpec Source # |

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.2.0-7LEJ2UkWk4x4h8ZMG4HftD" '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 Source #

to :: Rep TypeSpec x -> TypeSpec Source #

Show TypeSpec Source # |
Instance details Defined in HsLua.Typing Methods showsPrec :: Int -> TypeSpec -> ShowS Source # show :: TypeSpec -> String Source # showList :: [TypeSpec] -> ShowS Source #
Eq TypeSpec Source # |
Instance details Defined in HsLua.Typing Methods (==) :: TypeSpec -> TypeSpec -> Bool Source # (/=) :: TypeSpec -> TypeSpec -> Bool Source #
Ord TypeSpec Source # |
Instance details Defined in HsLua.Typing Methods compare :: TypeSpec -> TypeSpec -> Ordering Source # (<) :: TypeSpec -> TypeSpec -> Bool Source # (<=) :: TypeSpec -> TypeSpec -> Bool Source # (>) :: TypeSpec -> TypeSpec -> Bool Source # (>=) :: TypeSpec -> TypeSpec -> Bool Source # max :: TypeSpec -> TypeSpec -> TypeSpec Source # min :: TypeSpec -> TypeSpec -> TypeSpec Source #
type Rep TypeSpec Source # |

Instance details

Defined in HsLua.Typing

type Rep TypeSpec = D1 ('MetaData "TypeSpec" "HsLua.Typing" "hslua-typing-0.2.0-7LEJ2UkWk4x4h8ZMG4HftD" '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))))

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

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

typeSpecToString :: TypeSpec -> String Source #

Generate a string representation of the type specifier.

typeSpecFromString :: String -> TypeSpec Source #

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 Source #

Unconstraint type; any Lua value.

voidType :: TypeSpec Source #

A type for which there cannot be any value.

## Built-in types

booleanType :: TypeSpec Source #

The built-in `boolean` Lua type.

functionType :: TypeSpec Source #

The built-in `function` Lua type.

integerType :: TypeSpec Source #

A Lua integer type.

lightUserdataType :: TypeSpec Source #

The built-in `light userdata` Lua type.

nilType :: TypeSpec Source #

The built-in `nil` Lua type.

numberType :: TypeSpec Source #

The built-in `number` Lua type.

stringType :: TypeSpec Source #

The built-in `string` Lua type.

tableType :: TypeSpec Source #

The built-in `table` Lua type.

threadType :: TypeSpec Source #

The built-in `thread` Lua type.

userdataType :: TypeSpec Source #

The built-in `userdata` Lua type.

## Type constructors

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

Creates a record type.

seqType :: TypeSpec -> TypeSpec Source #

Creates a sequence type.

# Marshalling

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

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

peekTypeSpec :: LuaError e => Peeker e TypeSpec Source #

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