{-# LANGUAGE OverloadedStrings #-}
module HsLua.Packaging.UDType
( DocumentedType
, DocumentedTypeWithList
, deftype
, deftype'
, method
, property
, property'
, possibleProperty
, possibleProperty'
, readonly
, readonly'
, alias
, operation
, peekUD
, pushUD
, initType
, udparam
, udresult
, udDocs
, 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.Typing (pushTypeSpec)
import qualified Data.Map as Map
type DocumentedType e a = UDType e (DocumentedFunction e) a
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 = forall e fn a.
Pusher e fn
-> Name -> [(Operation, fn)] -> [Member e fn a] -> UDType e fn a
deftypeGeneric forall e. LuaError e => DocumentedFunction e -> LuaE e ()
pushDocumentedFunction
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' = forall e fn a itemtype.
Pusher e fn
-> Name
-> [(Operation, fn)]
-> [Member e fn a]
-> Maybe (ListSpec e a itemtype)
-> UDTypeWithList e fn a itemtype
deftypeGeneric' forall e. LuaError e => DocumentedFunction e -> LuaE e ()
pushDocumentedFunction
method :: DocumentedFunction e
-> Member e (DocumentedFunction e) a
method :: forall e a.
DocumentedFunction e -> Member e (DocumentedFunction e) a
method DocumentedFunction e
f = forall fn e a. Name -> fn -> Member e fn a
methodGeneric (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 forall a b. (a -> b) -> a -> b
$ forall e. Name -> DocumentedFunction e -> DocumentedFunction e
setName (Operation -> Name
metamethodName Operation
op) DocumentedFunction e
f
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 = forall e a. Peeker e a -> TypeSpec -> Text -> Text -> Parameter e a
parameter (forall e fn a itemtype.
LuaError e =>
UDTypeWithList e fn a itemtype -> Peeker e a
peekUDGeneric DocumentedTypeWithList e a itemtype
ty) (forall e fn a itemtype. UDTypeWithList e fn a itemtype -> 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 = forall e a. Pusher e a -> TypeSpec -> Text -> FunctionResults e a
functionResult (forall e a itemtype.
LuaError e =>
DocumentedTypeWithList e a itemtype -> a -> LuaE e ()
pushUD DocumentedTypeWithList e a itemtype
ty) (forall e fn a itemtype. UDTypeWithList e fn a itemtype -> 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 = forall e fn a itemtype.
LuaError e =>
(UDTypeWithList e fn a itemtype -> LuaE e ())
-> UDTypeWithList e fn a itemtype -> a -> LuaE e ()
pushUDGeneric forall e a itemtype.
LuaError e =>
DocumentedTypeWithList e a itemtype -> LuaE e ()
pushUDTypeDocs
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 = forall e fn a itemtype.
LuaError e =>
UDTypeWithList e fn a itemtype -> Peeker e a
peekUDGeneric
initType :: LuaError e
=> DocumentedTypeWithList e a itemtype
-> LuaE e Name
initType :: forall e a itemtype.
LuaError e =>
DocumentedTypeWithList e a itemtype -> LuaE e Name
initType = forall e fn a itemtype.
LuaError e =>
(UDTypeWithList e fn a itemtype -> LuaE e ())
-> UDTypeWithList e fn a itemtype -> LuaE e Name
initTypeGeneric forall e a itemtype.
LuaError e =>
DocumentedTypeWithList e a itemtype -> LuaE e ()
pushUDTypeDocs
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
forall e. Name -> LuaE e ()
pushName Name
"docs"
forall e a.
LuaError e =>
[(Name, a -> LuaE e ())] -> a -> LuaE e ()
pushAsTable
[ (Name
"name", forall e. Name -> LuaE e ()
pushName forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall e fn a itemtype. UDTypeWithList e fn a itemtype -> Name
udName)
, (Name
"properties", forall e a. LuaError e => Map Name (Property e a) -> LuaE e ()
pushPropertyDocs forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall e fn a itemtype.
UDTypeWithList e fn a itemtype -> Map Name (Property e a)
udProperties)
] DocumentedTypeWithList e a itemtype
ty
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 = forall e a b.
LuaError e =>
Pusher e a -> Pusher e b -> Pusher e [(a, b)]
pushKeyValuePairs forall e. Name -> LuaE e ()
pushName forall {e} {a}. Property e a -> LuaE e ()
pushPropDocs forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall k a. Map k a -> [(k, a)]
Map.toList
where
pushPropDocs :: Property e a -> LuaE e ()
pushPropDocs = forall e a.
LuaError e =>
[(Name, a -> LuaE e ())] -> a -> LuaE e ()
pushAsTable
[ (Name
"description", forall e. Pusher e Text
pushText forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall e a. Property e a -> Text
propertyDescription)
, (Name
"type", forall e. LuaError e => TypeSpec -> LuaE e ()
pushTypeSpec forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall e a. Property e a -> TypeSpec
propertyType)
]