Convert Ptr () to SourceCompletionProvider

I partially solved the prev issue.

Now I can register a GObject subtype via bindings-gobject (see hpase ). I can implement SourceCompletionProvider using the c'g_type_add_interface_static function (but have not tried it yet).

The only problem is converting the Ptr () returned by c'g_object_newv to the gtk2hs data type SourceCompletionProvider . How can I do it? Any clues?

SourceCompletionProvider defined as follows:

 newtype SourceCompletionProvider = SourceCompletionProvider (ForeignPtr (SourceCompletionProvider)) 

What does this definition mean? Why is it recursive? The provider, the ForeignPtr provider, looks strange to me.

Thanks.

Decision:

 makeNewGObject mkGObject $ castPtr <$> c'g_object_newv myObType 0 nullPtr 
+1
source share
1 answer

An external SourceCompletionProvider is required because it is a new type, and an internal SourceCompletionProvider is just a marker to distinguish this external pointer from pointers to other types. If you look at the definition of Ptr a , then data Ptr a = Ptr Addr# - a is a phantom type that does not appear on the right side, so the definition is not actually recursive.

You can convert Ptr () to ForeignPtr () using newForeignPtr_ and then translate it to ForeignPtr SourceCompletionProvider using castForeignPtr .

edit:. After looking at this a little more, I think that to do this, you first need to convert Ptr to GObject using the method described above, and then use unsafeCastGObject . Not verified.

+1
source

Source: https://habr.com/ru/post/1435348/


All Articles