Nathan Hüsken | 17 Jan 18:48 2013
Picon

Feedback on FFI bindings for C++ library

Hey,

I would like to write FII bindings in haskell for cocos2d-x
(http://www.cocos2d-x.org/), which is a C++ library.

Since I have little experience with this, I would like some feedback
before I discover that concept is bad half way.

In cocos2d there is a base class with much functionality: CCNode
Many classes derive from it (i.E. CCLayer) and use the virtual functions
of CCNode (i.E. setPosition).

How do I map this to haskell?

The general Idea:

I have a typeclass, in which everything that is derived from CCNode is
an instance:

    class NodeDerived a where
      toNode :: a -> Node

      setPosition :: a -> (Double,Double) -> IO ()
      setPosition a pos = setNodePosition (toNode a) pos

    instane NodeDerived Layer where
      toNode = layerToNode

and layerToNode :: Layer -> Node would be implemented in C++ as:

(Continue reading)

kudah | 18 Jan 01:05 2013
Picon

Re: Feedback on FFI bindings for C++ library

I'd suggest to first look at how other C++-bindings for haskell are
implemented. e.g. wxHaskell is the most mature Haskell C++ binding out
there. hogre tries to generate bindings from headers. And a number of
(rather minimal) bindings to some libs were made as part of Nikki and
the Robots.

On Thu, 17 Jan 2013 18:48:02 +0100 Nathan Hüsken
<nathan.huesken <at> posteo.de> wrote:

> Hey,
> 
> I would like to write FII bindings in haskell for cocos2d-x
> (http://www.cocos2d-x.org/), which is a C++ library.
> 
> Since I have little experience with this, I would like some feedback
> before I discover that concept is bad half way.
> 
> In cocos2d there is a base class with much functionality: CCNode
> Many classes derive from it (i.E. CCLayer) and use the virtual
> functions of CCNode (i.E. setPosition).
> 
> How do I map this to haskell?
> 
> The general Idea:
> 
> I have a typeclass, in which everything that is derived from CCNode is
> an instance:
> 
>     class NodeDerived a where
>       toNode :: a -> Node
(Continue reading)

Alp Mestanogullari | 18 Jan 08:36 2013
Picon

Re: Feedback on FFI bindings for C++ library

The simplest way generally is to make make a C binding and then bind Haskell from there. You may indeed want to take a look at wxWidgets' binding or SFML's (https://github.com/jeannekamikaze/SFML).


On Fri, Jan 18, 2013 at 1:05 AM, kudah <kudahkukarek <at> gmail.com> wrote:
I'd suggest to first look at how other C++-bindings for haskell are
implemented. e.g. wxHaskell is the most mature Haskell C++ binding out
there. hogre tries to generate bindings from headers. And a number of
(rather minimal) bindings to some libs were made as part of Nikki and
the Robots.

On Thu, 17 Jan 2013 18:48:02 +0100 Nathan Hüsken
<nathan.huesken <at> posteo.de> wrote:

> Hey,
>
> I would like to write FII bindings in haskell for cocos2d-x
> (http://www.cocos2d-x.org/), which is a C++ library.
>
> Since I have little experience with this, I would like some feedback
> before I discover that concept is bad half way.
>
> In cocos2d there is a base class with much functionality: CCNode
> Many classes derive from it (i.E. CCLayer) and use the virtual
> functions of CCNode (i.E. setPosition).
>
> How do I map this to haskell?
>
> The general Idea:
>
> I have a typeclass, in which everything that is derived from CCNode is
> an instance:
>
>     class NodeDerived a where
>       toNode :: a -> Node
>
>       setPosition :: a -> (Double,Double) -> IO ()
>       setPosition a pos = setNodePosition (toNode a) pos
>
>     instane NodeDerived Layer where
>       toNode = layerToNode
>
> and layerToNode :: Layer -> Node would be implemented in C++ as:
>
>     CCNode* layerToNode(CCLayer* l) { return
> dynamic_cast<CCNode*>(l); }
>
> This way I would have only to implement toNode for every class derived
> from CCNode and get all the functions CCNode defines.
>
> What do you think if this Idea?
> How would you do it?
>
> Thanks!
> Nathan
>
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe <at> haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe

_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe <at> haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe



--
Alp Mestanogullari
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe <at> haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe
kudah | 18 Jan 03:03 2013
Picon

Re: Feedback on FFI bindings for C++ library

I'd suggest to first look at how other C++-bindings for haskell are
implemented. e.g. wxHaskell is the most mature Haskell C++ binding out
there. hogre tries to generate bindings from headers. And a number of
(rather minimal) bindings to some libs were made as part of Nikki and
the Robots.

On Thu, 17 Jan 2013 18:48:02 +0100 Nathan Hüsken
<nathan.huesken <at> posteo.de> wrote:

> Hey,
> 
> I would like to write FII bindings in haskell for cocos2d-x
> (http://www.cocos2d-x.org/), which is a C++ library.
> 
> Since I have little experience with this, I would like some feedback
> before I discover that concept is bad half way.
> 
> In cocos2d there is a base class with much functionality: CCNode
> Many classes derive from it (i.E. CCLayer) and use the virtual
> functions of CCNode (i.E. setPosition).
> 
> How do I map this to haskell?
> 
> The general Idea:
> 
> I have a typeclass, in which everything that is derived from CCNode is
> an instance:
> 
>     class NodeDerived a where
>       toNode :: a -> Node
> 
>       setPosition :: a -> (Double,Double) -> IO ()
>       setPosition a pos = setNodePosition (toNode a) pos
> 
>     instane NodeDerived Layer where
>       toNode = layerToNode
> 
> and layerToNode :: Layer -> Node would be implemented in C++ as:
> 
>     CCNode* layerToNode(CCLayer* l) { return
> dynamic_cast<CCNode*>(l); }
> 
> This way I would have only to implement toNode for every class derived
> from CCNode and get all the functions CCNode defines.
> 
> What do you think if this Idea?
> How would you do it?
> 
> Thanks!
> Nathan
> 
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe <at> haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe

_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe <at> haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Gmane