Skip to content

joelberkeley/c-ffi

Repository files navigation

c-ffi

Generic C FFI utilities for Idris.

This library is intended to remove the need to build and package some of the more common C FFI utilities with Idris projects.

Install

Install pack, then run

pack install c-ffi

Example

We can create a C array double*

doubles : IO (Ptr Double)
doubles = do
  xs <- malloc (3 * cast prim__sizeOfDouble)
  let xs = prim__castPtr xs

  primIO $ prim__setArrayDouble xs 0 3.14
  primIO $ prim__setArrayDouble xs 1 (-1.23)
  primIO $ prim__setArrayDouble xs 2 2.71

  pure xs

and then read and print the array

showDoubles : IO ()
showDoubles = do
  ds <- doubles
  let ds' = map (prim__getArrayDouble ds) [0, 1, 2]
  free (prim__forgetPtr ds)
  printLn ds'

About

Generic C FFI utilities for Idris

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published