SourceCompletionProvider

SourceCompletionProvider

本文介绍了将Ptr()转换为SourceCompletionProvider的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我已经部分解决了上一个问题。 现在我可以通过 bindings-gobject 注册 GObject 子类型(参见)我可以实现 SourceCompletionProvider 使用 a href =http://hackage.haskell.org/packages/archive/bindings-gobject/0.3/doc/html/Bindings-GObject-TypeInformation.html#v:c-39-g_type_add_interface_static =nofollow noreferrer > c'g_type_add_interface_static 函数(但尚未尝试过)。 唯一的问题是将 Ptr() code> c'g_object_newv ,返回到 gtk2hs 数据类型 SourceCompletionProvider 。我该怎么做?任何提示? SourceCompletionProvider 定义如下: newtype SourceCompletionProvider = SourceCompletionProvider(ForeignPtr(SourceCompletionProvider)) 什么这个定义是否意味着?为什么它是递归的? Provider是 ForeignPtr 提供者 - 看起来很奇怪。 谢谢。 解决方案: makeNewGObject mkGObject $ castPtr< $> c'g_object_newv myObType 0 nullPtr 解决方案 SourceCompletionProvider 是必需的,因为这是一个新类型,并且内部 SourceCompletionProvider 只是一个标记,用于区分这个外部指针和其他类型的指针。如果您查看定义 ptr a ,它是 data Ptr a = Ptr Addr# - a 是一个幻像类型,不会出现在右侧,因此定义实际上不是递归的。 可以将 Ptr()到 ForeignPtr()使用 newForeignPtr _ ,然后将它转换为 ForeignPtr SourceCompletionProvider 与 castForeignPtr 。 edit:在看了这些之后,我认为要做到这一点,您需要先将 Ptr 转换为 GObject w ith上述方法,然后使用 unsafeCastGObject 。不过未经测试。 I've solved the prev question partially.Right now I'm able to register GObject subtype via bindings-gobject (see hpase)I can implement SourceCompletionProvider using c'g_type_add_interface_static function (but didn't tried yet).The only issue is to convert Ptr (), returned by c'g_object_newv, to gtk2hs data type SourceCompletionProvider. How can I do it? Any hints?SourceCompletionProvider is defined like:newtype SourceCompletionProvider = SourceCompletionProvider (ForeignPtr (SourceCompletionProvider))What does this definition means? Why it is recursive? Provider is a ForeignPtr to provider -- looks strange for me.Thanks.Solution:makeNewGObject mkGObject $ castPtr <$> c'g_object_newv myObType 0 nullPtr 解决方案 The outer SourceCompletionProvider is required since this is a newtype, and the inner SourceCompletionProvider is just a marker to distinguish this foreign pointer from pointers to other types. If you look at the definition of Ptr a, it's data Ptr a = Ptr Addr# - a is a phantom type that doesn't appear on the right-hand side, so the definition is not actually recursive.You can convert a Ptr () to ForeignPtr () using newForeignPtr_ and then cast it to ForeignPtr SourceCompletionProvider with castForeignPtr.edit: After looking at this a bit more, I think that to make this work you'll need to first convert your Ptr to GObject with the method outlined above and then use unsafeCastGObject. Not tested, though. 这篇关于将Ptr()转换为SourceCompletionProvider的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
09-26 12:15