{-# LANGUAGE OverloadedStrings #-}
module HsLua.Packaging.UDType
( DocumentedType
, DocumentedTypeWithList
, deftype
, deftype'
, method
, property
, property'
, possibleProperty
, possibleProperty'
, readonly
, readonly'
, alias
, operation
, peekUD
, pushUD
, initType
, udparam
, udresult
, udTypeSpec
, Member
, Operation (..)
, Property
, Possible (..)
) where
import Data.Map (Map)
import Data.Text (Text)
import HsLua.Core
import HsLua.Marshalling
import HsLua.ObjectOrientation
import HsLua.ObjectOrientation.Operation (metamethodName)
import HsLua.Packaging.Function
import HsLua.Packaging.Types (DocumentedType, setName)
import HsLua.Typing (pushTypeSpec)
import qualified Data.Map as Map
type DocumentedTypeWithList e a itemtype =
UDTypeWithList e (DocumentedFunction e) a itemtype
deftype :: LuaError e
=> Name
-> [(Operation, DocumentedFunction e)]
-> [Member e (DocumentedFunction e) a]
-> DocumentedType e a
deftype :: forall e a.
LuaError e =>
Name
-> [(Operation, DocumentedFunction e)]
-> [Member e (DocumentedFunction e) a]
-> DocumentedType e a
deftype Name
name [(Operation, DocumentedFunction e)]
ops [Member e (DocumentedFunction e) a]
methods = UDTypeGeneric e (DocumentedFunction e) a
-> UDTypeGeneric e (DocumentedFunction e) a
forall e a.
LuaError e =>
UDTypeGeneric e (DocumentedFunction e) a
-> UDTypeGeneric e (DocumentedFunction e) a
addDocHooks (UDTypeGeneric e (DocumentedFunction e) a
-> UDTypeGeneric e (DocumentedFunction e) a)
-> UDTypeGeneric e (DocumentedFunction e) a
-> UDTypeGeneric e (DocumentedFunction e) a
forall a b. (a -> b) -> a -> b
$
Pusher e (DocumentedFunction e)
-> Name
-> [(Operation, DocumentedFunction e)]
-> [Member e (DocumentedFunction e) a]
-> UDTypeHooks e (DocumentedFunction e) a
-> UDTypeGeneric e (DocumentedFunction e) a
forall e fn a.
Pusher e fn
-> Name
-> [(Operation, fn)]
-> [Member e fn a]
-> UDTypeHooks e fn a
-> UDTypeGeneric e fn a
deftypeGeneric' Pusher e (DocumentedFunction e)
forall e. LuaError e => DocumentedFunction e -> LuaE e ()
pushDocumentedFunction Name
name [(Operation, DocumentedFunction e)]
ops [Member e (DocumentedFunction e) a]
methods UDTypeHooks e (DocumentedFunction e) a
forall e fn a. UDTypeHooks e fn a
emptyHooks
deftype' :: LuaError e
=> Name
-> [(Operation, DocumentedFunction e)]
-> [Member e (DocumentedFunction e) a]
-> Maybe (ListSpec e a itemtype)
-> DocumentedTypeWithList e a itemtype
deftype' :: forall e a itemtype.
LuaError e =>
Name
-> [(Operation, DocumentedFunction e)]
-> [Member e (DocumentedFunction e) a]
-> Maybe (ListSpec e a itemtype)
-> DocumentedTypeWithList e a itemtype
deftype' Name
name [(Operation, DocumentedFunction e)]
ops [Member e (DocumentedFunction e) a]
methods Maybe (ListSpec e a itemtype)
mlistSpec = UDTypeGeneric e (DocumentedFunction e) a
-> UDTypeGeneric e (DocumentedFunction e) a
forall e a.
LuaError e =>
UDTypeGeneric e (DocumentedFunction e) a
-> UDTypeGeneric e (DocumentedFunction e) a
addDocHooks (UDTypeGeneric e (DocumentedFunction e) a
-> UDTypeGeneric e (DocumentedFunction e) a)
-> (UDTypeHooks e (DocumentedFunction e) a
-> UDTypeGeneric e (DocumentedFunction e) a)
-> UDTypeHooks e (DocumentedFunction e) a
-> UDTypeGeneric e (DocumentedFunction e) a
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
Pusher e (DocumentedFunction e)
-> Name
-> [(Operation, DocumentedFunction e)]
-> [Member e (DocumentedFunction e) a]
-> UDTypeHooks e (DocumentedFunction e) a
-> UDTypeGeneric e (DocumentedFunction e) a
forall e fn a.
Pusher e fn
-> Name
-> [(Operation, fn)]
-> [Member e fn a]
-> UDTypeHooks e fn a
-> UDTypeGeneric e fn a
deftypeGeneric' Pusher e (DocumentedFunction e)
forall e. LuaError e => DocumentedFunction e -> LuaE e ()
pushDocumentedFunction Name
name [(Operation, DocumentedFunction e)]
ops [Member e (DocumentedFunction e) a]
methods (UDTypeHooks e (DocumentedFunction e) a
-> UDTypeGeneric e (DocumentedFunction e) a)
-> UDTypeHooks e (DocumentedFunction e) a
-> UDTypeGeneric e (DocumentedFunction e) a
forall a b. (a -> b) -> a -> b
$
UDTypeHooks e (DocumentedFunction e) a
-> (ListSpec e a itemtype
-> UDTypeHooks e (DocumentedFunction e) a)
-> Maybe (ListSpec e a itemtype)
-> UDTypeHooks e (DocumentedFunction e) a
forall b a. b -> (a -> b) -> Maybe a -> b
maybe UDTypeHooks e (DocumentedFunction e) a
forall e fn a. UDTypeHooks e fn a
emptyHooks ListSpec e a itemtype -> UDTypeHooks e (DocumentedFunction e) a
forall e a itemtype fn.
LuaError e =>
ListSpec e a itemtype -> UDTypeHooks e fn a
listExtension Maybe (ListSpec e a itemtype)
mlistSpec
method :: DocumentedFunction e
-> Member e (DocumentedFunction e) a
method :: forall e a.
DocumentedFunction e -> Member e (DocumentedFunction e) a
method DocumentedFunction e
f = Name -> DocumentedFunction e -> Member e (DocumentedFunction e) a
forall fn e a. Name -> fn -> Member e fn a
methodGeneric (DocumentedFunction e -> Name
forall e. DocumentedFunction e -> Name
functionName DocumentedFunction e
f) DocumentedFunction e
f
operation :: Operation
-> DocumentedFunction e
-> (Operation, DocumentedFunction e)
operation :: forall e.
Operation
-> DocumentedFunction e -> (Operation, DocumentedFunction e)
operation Operation
op DocumentedFunction e
f = (,) Operation
op (DocumentedFunction e -> (Operation, DocumentedFunction e))
-> DocumentedFunction e -> (Operation, DocumentedFunction e)
forall a b. (a -> b) -> a -> b
$ DocumentedFunction e
f DocumentedFunction e -> Name -> DocumentedFunction e
forall a. HasName a => a -> Name -> a
`setName` Operation -> Name
metamethodName Operation
op
udparam :: LuaError e
=> DocumentedTypeWithList e a itemtype
-> Text
-> Text
-> Parameter e a
udparam :: forall e a itemtype.
LuaError e =>
DocumentedTypeWithList e a itemtype
-> Text -> Text -> Parameter e a
udparam DocumentedTypeWithList e a itemtype
ty = Peeker e a -> TypeSpec -> Text -> Text -> Parameter e a
forall e a. Peeker e a -> TypeSpec -> Text -> Text -> Parameter e a
parameter (DocumentedTypeWithList e a itemtype -> Peeker e a
forall e fn a. LuaError e => UDTypeGeneric e fn a -> Peeker e a
peekUDGeneric DocumentedTypeWithList e a itemtype
ty) (DocumentedTypeWithList e a itemtype -> TypeSpec
forall e fn a. UDTypeGeneric e fn a -> TypeSpec
udTypeSpec DocumentedTypeWithList e a itemtype
ty)
udresult :: LuaError e
=> DocumentedTypeWithList e a itemtype
-> Text
-> FunctionResults e a
udresult :: forall e a itemtype.
LuaError e =>
DocumentedTypeWithList e a itemtype -> Text -> FunctionResults e a
udresult DocumentedTypeWithList e a itemtype
ty = Pusher e a -> TypeSpec -> Text -> FunctionResults e a
forall e a. Pusher e a -> TypeSpec -> Text -> FunctionResults e a
functionResult (DocumentedTypeWithList e a itemtype -> Pusher e a
forall e a itemtype.
LuaError e =>
DocumentedTypeWithList e a itemtype -> a -> LuaE e ()
pushUD DocumentedTypeWithList e a itemtype
ty) (DocumentedTypeWithList e a itemtype -> TypeSpec
forall e fn a. UDTypeGeneric e fn a -> TypeSpec
udTypeSpec DocumentedTypeWithList e a itemtype
ty)
pushUD :: LuaError e => DocumentedTypeWithList e a itemtype -> a -> LuaE e ()
pushUD :: forall e a itemtype.
LuaError e =>
DocumentedTypeWithList e a itemtype -> a -> LuaE e ()
pushUD = UDTypeGeneric e (DocumentedFunction e) a -> a -> LuaE e ()
forall e fn a. LuaError e => UDTypeGeneric e fn a -> a -> LuaE e ()
pushUDGeneric
peekUD :: LuaError e => DocumentedTypeWithList e a itemtype -> Peeker e a
peekUD :: forall e a itemtype.
LuaError e =>
DocumentedTypeWithList e a itemtype -> Peeker e a
peekUD = UDTypeGeneric e (DocumentedFunction e) a -> Peeker e a
forall e fn a. LuaError e => UDTypeGeneric e fn a -> Peeker e a
peekUDGeneric
addDocHooks
:: LuaError e
=> UDTypeGeneric e (DocumentedFunction e) a
-> UDTypeGeneric e (DocumentedFunction e) a
addDocHooks :: forall e a.
LuaError e =>
UDTypeGeneric e (DocumentedFunction e) a
-> UDTypeGeneric e (DocumentedFunction e) a
addDocHooks UDTypeGeneric e (DocumentedFunction e) a
ty =
let hooks :: UDTypeHooks e (DocumentedFunction e) a
hooks = UDTypeGeneric e (DocumentedFunction e) a
-> UDTypeHooks e (DocumentedFunction e) a
forall e fn a. UDTypeGeneric e fn a -> UDTypeHooks e fn a
udHooks UDTypeGeneric e (DocumentedFunction e) a
ty
in UDTypeGeneric e (DocumentedFunction e) a
ty
{ udHooks = hooks
{ hookMetatableSetup = do
hookMetatableSetup hooks
pushUDTypeDocs ty
}
}
pushUDTypeDocs :: LuaError e
=> DocumentedTypeWithList e a itemtype
-> LuaE e ()
pushUDTypeDocs :: forall e a itemtype.
LuaError e =>
DocumentedTypeWithList e a itemtype -> LuaE e ()
pushUDTypeDocs DocumentedTypeWithList e a itemtype
ty = do
Name -> LuaE e ()
forall e. Name -> LuaE e ()
pushName Name
"docs"
[(Name, DocumentedTypeWithList e a itemtype -> LuaE e ())]
-> DocumentedTypeWithList e a itemtype -> LuaE e ()
forall e a.
LuaError e =>
[(Name, a -> LuaE e ())] -> a -> LuaE e ()
pushAsTable
[ (Name
"name", Name -> LuaE e ()
forall e. Name -> LuaE e ()
pushName (Name -> LuaE e ())
-> (DocumentedTypeWithList e a itemtype -> Name)
-> DocumentedTypeWithList e a itemtype
-> LuaE e ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. DocumentedTypeWithList e a itemtype -> Name
forall e fn a. UDTypeGeneric e fn a -> Name
udName)
, (Name
"properties", Map Name (Property e a) -> LuaE e ()
forall e a. LuaError e => Map Name (Property e a) -> LuaE e ()
pushPropertyDocs (Map Name (Property e a) -> LuaE e ())
-> (DocumentedTypeWithList e a itemtype -> Map Name (Property e a))
-> DocumentedTypeWithList e a itemtype
-> LuaE e ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. DocumentedTypeWithList e a itemtype -> Map Name (Property e a)
forall e fn a. UDTypeGeneric e fn a -> Map Name (Property e a)
udProperties)
] DocumentedTypeWithList e a itemtype
ty
StackIndex -> LuaE e ()
forall e. LuaError e => StackIndex -> LuaE e ()
rawset (CInt -> StackIndex
nth CInt
3)
pushPropertyDocs :: LuaError e
=> Map Name (Property e a)
-> LuaE e ()
pushPropertyDocs :: forall e a. LuaError e => Map Name (Property e a) -> LuaE e ()
pushPropertyDocs = Pusher e Name
-> Pusher e (Property e a) -> Pusher e [(Name, Property e a)]
forall e a b.
LuaError e =>
Pusher e a -> Pusher e b -> Pusher e [(a, b)]
pushKeyValuePairs Pusher e Name
forall e. Name -> LuaE e ()
pushName Pusher e (Property e a)
forall {e} {a}. Property e a -> LuaE e ()
pushPropDocs Pusher e [(Name, Property e a)]
-> (Map Name (Property e a) -> [(Name, Property e a)])
-> Map Name (Property e a)
-> LuaE e ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Map Name (Property e a) -> [(Name, Property e a)]
forall k a. Map k a -> [(k, a)]
Map.toList
where
pushPropDocs :: Property e a -> LuaE e ()
pushPropDocs = [(Name, Property e a -> LuaE e ())] -> Property e a -> LuaE e ()
forall e a.
LuaError e =>
[(Name, a -> LuaE e ())] -> a -> LuaE e ()
pushAsTable
[ (Name
"description", Pusher e Text
forall e. Pusher e Text
pushText Pusher e Text
-> (Property e a -> Text) -> Property e a -> LuaE e ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Property e a -> Text
forall e a. Property e a -> Text
propertyDescription)
, (Name
"type", TypeSpec -> LuaE e ()
forall e. LuaError e => TypeSpec -> LuaE e ()
pushTypeSpec (TypeSpec -> LuaE e ())
-> (Property e a -> TypeSpec) -> Property e a -> LuaE e ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Property e a -> TypeSpec
forall e a. Property e a -> TypeSpec
propertyType)
]