Skip to content

Commit 4173cd9

Browse files
committed
feat: add flag to disable lens
1 parent 113a642 commit 4173cd9

6 files changed

Lines changed: 52 additions & 37 deletions

File tree

cabal.project

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
packages: *.cabal
22

3-
optimization: 2
3+
optimization: 0
44

55
package h-raylib
66
flags: +examples

h-raylib.cabal

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,11 @@ flag ghci
101101
default: False
102102
manual: True
103103

104+
flag disable-lens
105+
description: Exclude the lens dependency and Raylib.Util.Lenses
106+
default: False
107+
manual: True
108+
104109
common example-options
105110
default-language: Haskell2010
106111

@@ -229,24 +234,35 @@ library
229234
Raylib.Util.Colors
230235
Raylib.Util.GUI
231236
Raylib.Util.GUI.Styles
232-
Raylib.Util.Lenses
233237
Raylib.Util.Math
234238
Raylib.Util.RLGL
235239

240+
if !flag(disable-lens)
241+
exposed-modules:
242+
Raylib.Util.Lenses
243+
236244
other-modules:
237245
Raylib.Internal.TH
238246
Raylib.Internal.Web.Native
239247
Raylib.Internal.Web.Processable
240248

249+
if !flag(disable-lens)
250+
other-modules:
251+
Raylib.Util.Lenses.TH
252+
241253
build-depends:
242254
, base >=4.0 && <4.22
243255
, bytestring >=0.11.0 && <0.13
244-
, containers >=0.6.0 && <0.7
256+
, containers >=0.6.0 && <0.9
245257
, exceptions >=0.10.4 && <0.11
246-
, lens >=4.0 && <5.4
247258
, linear >=1.22 && <1.24
248-
, template-haskell >=2.16.0.0 && <2.23.0.0
259+
, template-haskell >=2.16.0.0 && <2.24
249260
, text >=2.0 && <2.2
261+
262+
263+
if !flag(disable-lens)
264+
build-depends:
265+
, lens >=4.0 && <5.4
250266

251267
hs-source-dirs: src
252268
default-language: Haskell2010

src/Raylib/Internal/TH.hs

Lines changed: 4 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -3,59 +3,33 @@
33
{-# LANGUAGE TupleSections #-}
44

55
-- | Template Haskell functions used internally
6-
module Raylib.Internal.TH (genLenses, genNative) where
7-
8-
import Control.Lens (makeLensesFor)
9-
import Control.Monad (zipWithM)
6+
module Raylib.Internal.TH (genNative) where
107

118
#ifdef WEB_FFI
129

1310
import Language.Haskell.TH
1411
( Body (NormalB),
1512
Clause (Clause),
16-
Con (RecC),
17-
Dec (DataD, FunD, SigD),
13+
Dec (FunD, SigD),
1814
DecsQ,
1915
Exp (AppE, LitE, VarE),
20-
Info (TyConI),
2116
Lit (StringL),
22-
Name,
2317
TypeQ,
2418
mkName,
25-
nameBase,
26-
reify,
2719
)
2820
import Raylib.Internal.Web.Native (callRaylibFunction)
2921

3022
#else
3123

3224
import Language.Haskell.TH
33-
( Con (RecC),
34-
Dec (DataD, ForeignD),
25+
( Dec (ForeignD),
3526
DecsQ,
36-
Info (TyConI),
37-
Name,
3827
TypeQ,
39-
mkName,
40-
nameBase,
41-
reify, Foreign (ImportF), Callconv (CCall), Safety (Safe),
28+
mkName, Foreign (ImportF), Callconv (CCall), Safety (Safe),
4229
)
4330

4431
#endif
4532

46-
-- | Creates lenses with an underscore before field names; e.g. @vector2'x@
47-
-- becomes the lens @_vector2'x@
48-
genLenses :: [Name] -> DecsQ
49-
genLenses names = do
50-
infos <- mapM reify names
51-
concat <$> zipWithM genLensesForType names infos
52-
where
53-
genLensesForType name (TyConI (DataD _ _ _ _ [RecC _ ctors] _)) =
54-
makeLensesFor mapping name
55-
where
56-
mapping = map (\(a, _, _) -> let fName = nameBase a in (fName, '_' : fName)) ctors
57-
genLensesForType _ _ = error "(genLenses) Received a name that does not refer to a valid type!"
58-
5933
-- | Generates native code for the given functions. On non-web platforms, this
6034
-- means @foreign import@ statements. On web platforms, this means
6135
-- `callRaylibFunction` calls.

src/Raylib/Util/Lenses.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
module Raylib.Util.Lenses where
66

77
import Control.Lens (Lens', lens)
8-
import Raylib.Internal.TH (genLenses)
8+
import Raylib.Util.Lenses.TH (genLenses)
99
import qualified Raylib.Types as RL
1010

1111
$( genLenses

src/Raylib/Util/Lenses/TH.hs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
module Raylib.Util.Lenses.TH (genLenses) where
2+
3+
import Language.Haskell.TH
4+
( Con (RecC),
5+
Dec (DataD),
6+
DecsQ,
7+
Name,
8+
Info (TyConI),
9+
nameBase,
10+
reify
11+
)
12+
import Control.Lens (makeLensesFor)
13+
import Control.Monad (zipWithM)
14+
15+
-- | Creates lenses with an underscore before field names; e.g. @vector2'x@
16+
-- becomes the lens @_vector2'x@
17+
genLenses :: [Name] -> DecsQ
18+
genLenses names = do
19+
infos <- mapM reify names
20+
concat <$> zipWithM genLensesForType names infos
21+
where
22+
genLensesForType name (TyConI (DataD _ _ _ _ [RecC _ ctors] _)) =
23+
makeLensesFor mapping name
24+
where
25+
mapping = map (\(a, _, _) -> let fName = nameBase a in (fName, '_' : fName)) ctors
26+
genLensesForType _ _ = error "(genLenses) Received a name that does not refer to a valid type!"

src/Raylib/Util/Math.hs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,6 @@ module Raylib.Util.Math
9696
)
9797
where
9898

99-
import Data.Foldable (foldl')
10099
import Raylib.Types (Matrix (..), Quaternion, Vector2, pattern Vector2, Vector3, pattern Vector3, Vector4, pattern Vector4)
101100
epsilon :: Float
102101
epsilon = 0.000001

0 commit comments

Comments
 (0)