flipper-io / flipper

Flipper is a development platform that can be controlled from any programming language.
https://www.flipper.io/
Apache License 2.0
70 stars 15 forks source link

CSize -> Word32 #50

Closed TravisWhitaker closed 8 years ago

TravisWhitaker commented 8 years ago

Change CSize to Word32 to reflect the changes to how sizes are handled.

nicholastmosher commented 8 years ago

So as a non-Haskell person, what is the mechanical difference between the terms CSize and Word32 and how does that fit better with the size_t changes in C?

TravisWhitaker commented 8 years ago

The standard Haskell base library has a module called Foreign.C.Types (http://hackage.haskell.org/package/base-4.9.0.0/docs/Foreign-C-Types.html) that provides access to standard C types in Haskell land. CSize is just a type that represents an unsigned integer guaranteed to be the same width as size_t for the specific platform. #47 from @georgemorgan earlier replaces all uses of size_t with fmr_size_t which is defined as uint32_t for libflipper in include/flipper/core.h. Word32 is from the base module Data.Word and is just a 32-bit unsigned integer (i.e. same representation as uint32_t).

Wrapping C functions in Haskell is pretty simple. All you have to do is write something like:

foreign import ccall safe "something.h something" hsSomething :: t

Where ccall specifies the calling convention to translate to, something.h is a header file declaring the symbol something, safe indicates that the C function might block, and the type t is in terms Storable types (http://hackage.haskell.org/package/base-4.9.0.0/docs/Foreign-Storable.html) and optionally the IO monad. Then there's magically a Haskell function called hsSomething in scope.

georgemorgan commented 8 years ago

Merged.