packages feed

hs-bindgen-runtime-1.0.0.0: src/HsBindgen/Runtime/Block.hs

-- | Bare-bones support for blocks
--
-- TODO <https://github.com/well-typed/hs-bindgen/issues/2132>
--
-- Ideally we would at least support @Block_copy@ and @Block_release@. This
-- would be easy to do, but would mean that @hs-bindgen-runtime@ would then
-- depend on the runtime (@libblocksruntime@).
--
-- This module is intended to be imported qualified.
--
-- > import HsBindgen.Runtime.Prelude
-- > import HsBindgen.Runtime.Block qualified as Block
module HsBindgen.Runtime.Block (
    Block(..)
  ) where

import Foreign (Ptr)

import HsBindgen.Runtime.HasFFIType (HasFFIType)

{-------------------------------------------------------------------------------
  Definition

  We expose the definition of 'Block' so that it can appear in foreign imports.
-------------------------------------------------------------------------------}

-- | Block
--
-- See <https://clang.llvm.org/docs/BlockLanguageSpec.html>
--
-- The type index is the type of the bloc, for example:
--
-- > typedef int(^VarCounter)(int increment);
--
-- corresponds to
--
-- > newtype VarCounter = VarCounter (Block (CInt -> IO CInt))
newtype Block t = Block (Ptr ())

deriving newtype instance HasFFIType (Block t)