swog icon indicating copy to clipboard operation
swog copied to clipboard

CObj: extern functions can't return abstract classes.

Open lolgab opened this issue 8 years ago • 3 comments

When an extern function have as return type an abstract type, the macro tries to instantiate it, resulting in a compile error. Example with GtkBuilder:

@CObj
class GtkBuilder {
  def getObject(name: CString): GObject = extern
}
[error] [E1] src/main/scala/GtkBuilder.scala
[error]      class GObject is abstract; cannot be instantiated
[error]      L6:@CObj

lolgab avatar Mar 09 '18 14:03 lolgab

@lolgab do you use GObject from scalanative-gtk, or your own implementation? If so, did you extend CObj.CObjWrapper? We don't have support to determine the actual implementation of an interface or abstract class, so this issue is left to the user. For an example, please refer to the documentation for GObject.getObject

jokade avatar Mar 13 '18 18:03 jokade

Reading the documentation cleared me the ideas. Thank you. I was writing a gui library built on libui but libui is not complete and mature enough to cover all the needed use cases (for example managing keyboard layout characters) I think it is a better idea to make another layer on your scalanative-gtk to let the users get rid of all the Scala Native and Gtk specific stuff like I did for libui. Much compliments for your idea of the c object macro. It is a wonderful idea and implementation! I am dreaming on a future when one can build mobile guis in a abstracted scala dsl and let the compiler generate scala native code based on your scala native cocoa and scala jvm code for android.

lolgab avatar Mar 14 '18 08:03 lolgab

@lolgab glad to help. Unfortunately, there's currently not a lot of documentation on how to use the CObj macro and the scalanative-gtk libs. And since I'm currently heavily involved in other projects, I don't have much time left to extend it right now (or the Gtk bindings lib itself). However, I'm committed to make both libs "production ready" at some point.

I saw your great libui binding for SN, and of course I would be excited to have a real cross-platform Scala UI (DSL) for JVM and Native - so if the CObj macro or the gtk-bindings lib can help you with that endeavor, feel free to ask questions & place feature requests. With my time being limited, it's more efficient to implement features actually required by another project.

jokade avatar Mar 14 '18 20:03 jokade