inline-c-objc (empty) → 0.1.0.0
raw patch · 4 files changed
+111/−0 lines, 4 filesdep +basedep +containersdep +hspec
Dependencies added: base, containers, hspec, inline-c, inline-c-objc, template-haskell
Files
- LICENSE +20/−0
- inline-c-objc.cabal +40/−0
- src/Language/C/Inline/ObjC.hs +26/−0
- test/tests.hs +25/−0
+ LICENSE view
@@ -0,0 +1,20 @@+Copyright (c) 2015 FP Complete Corporation.++Permission is hereby granted, free of charge, to any person obtaining+a copy of this software and associated documentation files (the+"Software"), to deal in the Software without restriction, including+without limitation the rights to use, copy, modify, merge, publish,+distribute, sublicense, and/or sell copies of the Software, and to+permit persons to whom the Software is furnished to do so, subject to+the following conditions:++The above copyright notice and this permission notice shall be+included in all copies or substantial portions of the Software.++THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ inline-c-objc.cabal view
@@ -0,0 +1,40 @@+cabal-version: 2.2+name: inline-c-objc+version: 0.1.0.0+synopsis: Lets you embed Objective-C code into Haskell.+description: Utilities to inline Objective-C code into Haskell using inline-c. See+ tests for example on how to build.+license: MIT+license-file: LICENSE+author: Francesco Mazzoli+maintainer: f@mazzo.li+copyright: (c) 2015-2016 FP Complete Corporation, (c) 2017-2023 Francesco Mazzoli+category: FFI+tested-with: GHC == 9.2.7+build-type: Simple++source-repository head+ type: git+ location: https://github.com/fpco/inline-c++library+ exposed-modules: Language.C.Inline.ObjC+ build-depends: base >=4.7 && <5+ , inline-c >= 0.9.1.5+ , template-haskell+ , containers+ hs-source-dirs: src+ default-language: Haskell2010+ ghc-options: -Wall++test-suite tests+ type: exitcode-stdio-1.0+ hs-source-dirs: test+ main-is: tests.hs+ build-depends: base >=4 && <5+ , inline-c+ , inline-c-objc+ , hspec+ default-language: Haskell2010+ if os(darwin)+ frameworks: Foundation
+ src/Language/C/Inline/ObjC.hs view
@@ -0,0 +1,26 @@+{-# LANGUAGE TemplateHaskell #-}+{-# LANGUAGE OverloadedStrings #-}++module Language.C.Inline.ObjC+ ( module Language.C.Inline+ , objcCtx+ , CId, Id(..)+ ) where++import qualified Language.Haskell.TH.Syntax as TH+import qualified Language.C.Types as CT+import Foreign++import Language.C.Inline+import Language.C.Inline.Context++import qualified Data.Map as Map++objcCtx :: Context+objcCtx = baseCtx <> mempty+ { ctxForeignSrcLang = Just TH.LangObjc+ , ctxTypesTable = Map.singleton (CT.TypeName "id") [t|Id|]+ }++data CId+newtype Id = Id (Ptr CId)
+ test/tests.hs view
@@ -0,0 +1,25 @@+{-# LANGUAGE QuasiQuotes #-}+{-# LANGUAGE TemplateHaskell #-}++import qualified Language.C.Inline.ObjC as C+import qualified Test.Hspec as Hspec++C.context C.objcCtx++C.include "<Foundation/Foundation.h>"++main :: IO ()+main = Hspec.hspec $ do+ Hspec.describe "Basic Objective-C" $ do+ Hspec.it "Hello World" $ do+ let x = 3+ [C.block| void {+ NSLog(@"%@ %d", @"Hello, world!", $(int x));+ } |]+ Hspec.it "Expressions" $ do+ z <- [C.exp| int { [[@"A few words" componentsSeparatedByString: @" "] count] } |]+ z `Hspec.shouldBe` 3+ Hspec.it "Objects" $ do+ a <- [C.exp| id { [@"A few more words" componentsSeparatedByString: @" "] } |]+ s <- [C.exp| int { [$(id a) count] } |]+ s `Hspec.shouldBe` 4