Skip to content

Commit b5d17f5

Browse files
committed
Require hslua-2.1
1 parent eeef5dc commit b5d17f5

2 files changed

Lines changed: 18 additions & 41 deletions

File tree

hslua-module-doclayout.cabal

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ source-repository head
3030
library
3131
build-depends: base >= 4.9 && < 5
3232
, doclayout >= 0.2 && < 0.4
33-
, hslua >= 2.0 && < 2.1
33+
, hslua >= 2.1 && < 2.2
3434
, text >= 1.0 && < 1.3
3535
default-language: Haskell2010
3636
hs-source-dirs: src

src/HsLua/Module/DocLayout.hs

Lines changed: 17 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ where
7272
import Prelude hiding (concat)
7373
import Data.List (intersperse)
7474
import Data.Text (Text)
75-
import HsLua as Lua hiding (concat, render)
75+
import HsLua as Lua hiding (concat)
7676
import Text.DocLayout (Doc, (<+>), ($$), ($+$))
7777

7878
import qualified Data.Text as T
@@ -198,7 +198,7 @@ typeDoc = deftype "Doc"
198198
### liftPure2 (==)
199199
<#> docParam "a"
200200
<#> docParam "b"
201-
=#> booleanResult "whether the two Docs are equal"
201+
=#> boolResult "whether the two Docs are equal"
202202
, operation Idiv $ binaryOp ($+$) "Puts a above b"
203203
, operation Tostring $ lambda
204204
### liftPure (Doc.render Nothing)
@@ -220,7 +220,7 @@ render :: LuaError e => DocumentedFunction e
220220
render = defun "render"
221221
### liftPure2 (flip Doc.render)
222222
<#> docParam "doc"
223-
<#> optionalParameter (peekIntegral @Int) "integer" "colwidth" ""
223+
<#> opt (integralParam "colwidth" "")
224224
=#> functionResult pushText "Doc" "rendered doc"
225225
#? ("Render a @'Doc'@. The text is reflowed on breakable spaces" <>
226226
"to match the given line length. Text is not reflowed if the" <>
@@ -235,15 +235,15 @@ is_empty :: LuaError e => DocumentedFunction e
235235
is_empty = defun "is_empty"
236236
### liftPure Doc.isEmpty
237237
<#> docParam "doc"
238-
=#> booleanResult "`true` iff `doc` is the empty document, `false` otherwise."
238+
=#> boolResult "`true` iff `doc` is the empty document, `false` otherwise."
239239
#? "Checks whether a doc is empty."
240240

241241
-- | Returns the width of a @'Doc'@.
242242
offset :: LuaError e => DocumentedFunction e
243243
offset = defun "offset"
244244
### liftPure Doc.offset
245245
<#> docParam "doc"
246-
=#> intResult "doc width"
246+
=#> integralResult "doc width"
247247
#? "Returns the width of a `Doc` as number of characters."
248248

249249
-- | Returns the minimal width of a @'Doc'@ when reflowed at
@@ -252,7 +252,7 @@ min_offset :: LuaError e => DocumentedFunction e
252252
min_offset = defun "min_offset"
253253
### liftPure Doc.minOffset
254254
<#> docParam "doc"
255-
=#> intResult "minimal possible width"
255+
=#> integralResult "minimal possible width"
256256
#? ("Returns the minimal width of a `Doc` when reflowed at " <>
257257
"breakable spaces.")
258258

@@ -262,8 +262,8 @@ update_column :: LuaError e => DocumentedFunction e
262262
update_column = defun "update_column"
263263
### liftPure2 Doc.updateColumn
264264
<#> docParam "doc"
265-
<#> intParam "i"
266-
=#> intResult "column number"
265+
<#> integralParam "i" ""
266+
=#> integralResult "column number"
267267
#? ("Returns the column that would be occupied by the last " <>
268268
"laid out character.")
269269

@@ -272,7 +272,7 @@ height :: LuaError e => DocumentedFunction e
272272
height = defun "height"
273273
### liftPure Doc.height
274274
<#> docParam "doc"
275-
=#> intResult "doc height"
275+
=#> integralResult "doc height"
276276
#? "Returns the height of a block or other Doc."
277277

278278

@@ -282,8 +282,8 @@ height = defun "height"
282282
real_length :: DocumentedFunction e
283283
real_length = defun "real_length"
284284
### liftPure Doc.realLength
285-
<#> textParam "str"
286-
=#> intResult "text length"
285+
<#> textParam "str" ""
286+
=#> integralResult "text length"
287287
#? ("Returns the real length of a string in a monospace font: " <>
288288
"0 for a combining chaeracter, 1 for a regular character, " <>
289289
"2 for an East Asian wide character.")
@@ -297,7 +297,7 @@ real_length = defun "real_length"
297297
after_break :: LuaError e => DocumentedFunction e
298298
after_break = defun "after_break"
299299
### liftPure Doc.afterBreak
300-
<#> textParam "text"
300+
<#> textParam "text" ""
301301
=#> docResult "new doc"
302302
#? ("Creates a `Doc` which is conditionally included only if it" <>
303303
"comes at the beginning of a line.")
@@ -316,7 +316,7 @@ before_non_blank = defun "before_non_blank"
316316
blanklines :: LuaError e => DocumentedFunction e
317317
blanklines = defun "blanklines"
318318
### liftPure Doc.blanklines
319-
<#> intParam "n"
319+
<#> integralParam "n" ""
320320
=#> docResult "conditional blank lines"
321321
#? "Inserts blank lines unless they exist already."
322322

@@ -361,7 +361,7 @@ concat = defun "concat"
361361
### liftPure2 (\docs optSep -> mconcat $
362362
maybe docs (`intersperse` docs) optSep)
363363
<#> parameter (peekList peekDoc) "`{Doc,...}`" "docs" "list of Docs"
364-
<#> optionalParameter peekDoc "Doc" "sep" "separator"
364+
<#> opt (parameter peekDoc "Doc" "sep" "separator")
365365
=#> docResult "concatenated doc"
366366
#? "Concatenates a list of `Doc`s."
367367

@@ -417,7 +417,7 @@ lblock = defun "lblock"
417417
literal :: LuaError e => DocumentedFunction e
418418
literal = defun "literal"
419419
### liftPure Doc.literal
420-
<#> textParam "string"
420+
<#> textParam "string" ""
421421
=#> docResult "doc contatining just the literal string"
422422
#? "Creates a `Doc` from a string."
423423

@@ -493,7 +493,7 @@ rblock = defun "rblock"
493493
vfill :: LuaError e => DocumentedFunction e
494494
vfill = defun "vfill"
495495
### liftPure Doc.vfill
496-
<#> textParam "border"
496+
<#> textParam "border" ""
497497
=#> docResult "automatically expanding border Doc"
498498
#? ("An expandable border that, when placed next to a box, " <>
499499
"expands to the height of the box. Strings cycle through the " <>
@@ -519,7 +519,7 @@ pushDoc :: LuaError e => Pusher e (Doc Text)
519519
pushDoc = pushUD typeDoc
520520

521521
instance Peekable (Doc Text) where
522-
peek = forcePeek . peekDoc
522+
safepeek = peekDoc
523523

524524
instance Pushable (Doc Text) where
525525
push = pushDoc
@@ -532,35 +532,12 @@ instance Pushable (Doc Text) where
532532
docParam :: LuaError e => Text -> Parameter e (Doc Text)
533533
docParam name = parameter peekDoc "Doc" name ""
534534

535-
-- | @Int@ typed function parameter.
536-
intParam :: Text -> Parameter e Int
537-
intParam name = parameter (peekIntegral @Int) "integer "name ""
538-
539-
-- | @Text@ typed function parameter.
540-
textParam :: Text -> Parameter e Text
541-
textParam name = parameter peekText "string" name ""
542-
543535
--
544536
-- Results
545537
--
546538

547-
-- | Boolean function result.
548-
booleanResult :: Text -- ^ Description
549-
-> FunctionResults e Bool
550-
booleanResult = functionResult pushBool "boolean"
551-
552539
-- | Function result of type @'Doc'@.
553540
docResult :: LuaError e
554541
=> Text -- ^ Description
555542
-> FunctionResults e (Doc Text)
556543
docResult = functionResult pushDoc "Doc"
557-
558-
-- | Function result of type @'Int'@.
559-
intResult :: Text -- ^ Description
560-
-> FunctionResults e Int
561-
intResult = functionResult (pushIntegral @Int) "integer"
562-
563-
-- | Function result of type @'Text'@.
564-
textResult :: Text -- ^ Description
565-
-> FunctionResults e Text
566-
textResult = functionResult pushText "text"

0 commit comments

Comments
 (0)