packages feed

h-raylib 4.5.0.10 → 4.5.0.11

raw patch · 4 files changed

+35/−17 lines, 4 filesPVP: major bump suggested

API removals or changes: PVP suggests a major version bump

API changes (from Hackage documentation)

- Raylib: getMonitorHeight :: Int -> IO CInt
+ Raylib: getMonitorHeight :: Int -> IO Int
- Raylib: getMonitorPhysicalWidth :: Int -> IO CInt
+ Raylib: getMonitorPhysicalWidth :: Int -> IO Int
- Raylib: loadShader :: String -> String -> IO Shader
+ Raylib: loadShader :: Maybe String -> Maybe String -> IO Shader
- Raylib: loadShaderFromMemory :: String -> String -> IO Shader
+ Raylib: loadShaderFromMemory :: Maybe String -> Maybe String -> IO Shader

Files

CHANGELOG.md view
@@ -1,24 +1,24 @@ # h-raylib changelog
 
 ## Version 4.5.0.4
-_13 November 2022_
+_13 November, 2022_
 - Replaced `CInt` with `CBool` for functions that return booleans
 - Removed `Xext` dependency (it is no longer required for Nix builds)
 
 ## Version 4.5.0.5
-_19 November 2022_
+_19 November, 2022_
 - Replaced `CInt` with `CBool` in `RayCollision`
 - Updated raylib to the master branch
 
 ## Version 4.5.0.6
-_24 November 2022_
+_24 November, 2022_
 
 \[[#6](https://github.com/Anut-py/h-raylib/issues/6)\]
 
 - Fixed `Font` marshalling
 
 ## Version 4.5.0.7
-_26 November 2022_
+_26 November, 2022_
 
 \[[#7](https://github.com/Anut-py/h-raylib/pull/7)\]
 
@@ -27,19 +27,25 @@ - Removed `Raylib.Constants`
 
 ## Version 4.5.0.8
-_18 December 2022_
+_18 December, 2022_
 
 \[[#9](https://github.com/Anut-py/h-raylib/issues/9)\]
 
 - Fixed an issue on Mac where `clang` failed to detect that `rglfw.c` was using objective-c
 
 ## Version 4.5.0.9
-_23 December 2022_
+_23 December, 2022_
 
 - Changed `setConfigFlags` and `setGesturesEnabled` to use an array of flags
 
 ## Version 4.5.0.10
-_5 January 2023_
+_5 January, 2023_
 
 - Restructured to make the examples easier to run
 - Updated raylib to the master branch
+
+## Version 4.5.0.11
+_14 January, 2023_
+
+- Fixed some function types
+- Allowed omitting fragment/vertex shaders in `loadShader` functions
h-raylib.cabal view
@@ -1,6 +1,6 @@ cabal-version:      2.4
 name:               h-raylib
-version:            4.5.0.10
+version:            4.5.0.11
 synopsis:           Raylib bindings for Haskell
 category:           graphics
 description:
src/Raylib.hs view
@@ -81,7 +81,7 @@     ShaderUniformDataType,
     PixelFormat
   )
-import Raylib.Util (pop, withArray2D, configsToBitflag)
+import Raylib.Util (pop, withArray2D, configsToBitflag, withMaybeCString)
 import Prelude hiding (length)
 
 -- Haskell doesn't support varargs in foreign calls, so these functions are impossible to call from FFI
@@ -477,7 +477,7 @@   c'getMonitorHeight ::
     CInt -> IO CInt
 
-getMonitorHeight :: Int -> IO CInt
+getMonitorHeight :: Int -> IO Int
 getMonitorHeight monitor = fromIntegral <$> c'getMonitorHeight (fromIntegral monitor)
 
 foreign import ccall safe "raylib.h &GetMonitorHeight"
@@ -488,7 +488,7 @@   c'getMonitorPhysicalWidth ::
     CInt -> IO CInt
 
-getMonitorPhysicalWidth :: Int -> IO CInt
+getMonitorPhysicalWidth :: Int -> IO Int
 getMonitorPhysicalWidth monitor = fromIntegral <$> c'getMonitorPhysicalWidth (fromIntegral monitor)
 
 foreign import ccall safe "raylib.h &GetMonitorPhysicalWidth"
@@ -833,8 +833,9 @@ 
 foreign import ccall safe "bindings.h LoadShader_" c'loadShader :: CString -> CString -> IO (Ptr Raylib.Types.Shader)
 
-loadShader :: String -> String -> IO Raylib.Types.Shader
-loadShader vsFileName fsFileName = withCString vsFileName (withCString fsFileName . c'loadShader) >>= pop
+loadShader :: Maybe String -> Maybe String -> IO Raylib.Types.Shader
+loadShader vsFileName fsFileName = 
+  withMaybeCString vsFileName (withMaybeCString fsFileName . c'loadShader) >>= pop
 
 foreign import ccall safe "raylib.h &LoadShader"
   p'loadShader ::
@@ -842,8 +843,8 @@ 
 foreign import ccall safe "bindings.h LoadShaderFromMemory_" c'loadShaderFromMemory :: CString -> CString -> IO (Ptr Raylib.Types.Shader)
 
-loadShaderFromMemory :: String -> String -> IO Raylib.Types.Shader
-loadShaderFromMemory vsCode fsCode = withCString vsCode (withCString fsCode . c'loadShaderFromMemory) >>= pop
+loadShaderFromMemory :: Maybe String -> Maybe String -> IO Raylib.Types.Shader
+loadShaderFromMemory vsCode fsCode = withMaybeCString vsCode (withMaybeCString fsCode . c'loadShaderFromMemory) >>= pop
 
 foreign import ccall safe "raylib.h &LoadShaderFromMemory"
   p'loadShaderFromMemory ::
src/Raylib/Util.hs view
@@ -1,9 +1,10 @@ {-# OPTIONS -Wall #-}
-module Raylib.Util (c'free, pop, popCArray, withArray2D, configsToBitflag) where
+module Raylib.Util (c'free, pop, popCArray, withArray2D, configsToBitflag, withMaybe, withMaybeCString) where
 
-import Foreign (Ptr, Storable (peek), castPtr, newArray, free, peekArray)
+import Foreign (Ptr, Storable (peek), castPtr, newArray, free, peekArray, with, nullPtr)
 import Control.Monad (forM_)
 import Data.Bits ((.|.))
+import Foreign.C (CString, withCString)
 -- Internal utility functions
 
 foreign import ccall "stdlib.h free" c'free :: Ptr () -> IO ()
@@ -32,3 +33,13 @@ configsToBitflag :: (Enum a) => [a] -> Integer
 configsToBitflag = fromIntegral . foldr folder (toEnum 0)
     where folder a b = fromEnum a .|. b
+
+withMaybe :: (Storable a) => Maybe a -> (Ptr a -> IO b) -> IO b
+withMaybe a f = case a of
+    (Just val) -> with val f
+    Nothing    -> f nullPtr
+
+withMaybeCString :: Maybe String -> (CString -> IO b) -> IO b
+withMaybeCString a f = case a of
+    (Just val) -> withCString val f
+    Nothing    -> f nullPtr