5858import Data.Text (Text )
5959import Foreign.Lua (Lua , NumResults (.. ), Optional ,
6060 Peekable , Pushable , StackIndex )
61- import Text.DocLayout (Doc )
61+ import Text.DocLayout ((<+>) , Doc )
6262
6363import qualified Data.Text as T
6464import qualified Foreign.Lua as Lua
@@ -249,16 +249,17 @@ pushDoc :: Doc Text -> Lua ()
249249pushDoc = Lua. pushAnyWithMetatable pushDocMT
250250 where
251251 pushDocMT = Lua. ensureUserdataMetatable docTypeName $ do
252+ Lua. addfunction " __add" __add
252253 Lua. addfunction " __concat" __concat
253254 Lua. addfunction " __eq" __eq
254255 Lua. addfunction " __tostring" __tostring
255256
256257instance Pushable (Doc Text ) where
257258 push = pushDoc
258259
259- -- | Convert to string by rendering without reflowing .
260- __tostring :: Doc Text -> Lua Text
261- __tostring d = return $ Doc. render Nothing d
260+ -- | Concatenate two @'Doc'@s, putting breakable spaces between them .
261+ __add :: Doc Text -> Doc Text -> Lua ( Doc Text )
262+ __add a b = return (a <+> b)
262263
263264-- | Concatenate two @'Doc'@.
264265__concat :: Doc Text -> Doc Text -> Lua (Doc Text )
@@ -267,3 +268,7 @@ __concat a b = return (a <> b)
267268-- | Test @'Doc'@ equality.
268269__eq :: Doc Text -> Doc Text -> Lua Bool
269270__eq a b = return (a == b)
271+
272+ -- | Convert to string by rendering without reflowing.
273+ __tostring :: Doc Text -> Lua Text
274+ __tostring d = return $ Doc. render Nothing d
0 commit comments