On Wed, 2017-08-23 at 10:06 -0500, Federico Mena Quintero wrote:
On Wed, 2017-08-23 at 09:44 +0300, Sebastian Dröge wrote:This is good timing BTW, I was going to write a full example of GObject subclasses with interfaces implementations, signals, action signals, properties, virtual methods, gobject-introspection support next week. Using the glib-rs infrastructure but otherwise manual. Goal would be to have a baseline / template to what gnome-class should be able to generate, to have it all written out and functional so that also someone not knowing the implementation details of GObject can start working on that.See, I love it when this happens: Federico: "hi, please help me make fire by rubbing sticks" Sebastian: "here, have this high-tech oven instead" Having this example of all the GObjects bells and whistles used from Rust would be *VERY* helpful for the code generator!
You can find the oven here: https://github.com/sdroege/gobject-example-rs I'm not very happy with the code organization yet, any suggestions let me know :) It's all feeling mashed together, the actual safe implementations of the stuff are mixed with the boilerplate. This thing includes so far: - All compiled to a shared library that exports C API - 2 GObjects. Bar inherits from Foo. src/{foo,bar} contains the code of each. mod.rs is the gtk-rs style Rust wrapper, imp.rs is the actual implementation, ffi.rs see below - Constructors with a construct-only GObject property "name" - Normal methods on all of them (get_name(), get_counter(), increment(), etc.) - Virtual method "increment" on Foo, overridden by Bar, plus calling function - Signal "incremented" on Foo - Normal "number" GObject property on Bar - Makefile that builds all this, plus GObject-Introspection stuff - Python and Javascript example that uses it (can be run from the Makefile so that the G-I things are found directly), and a Rust "unit" test that uses it all from Rust - C header for the public API - A "bindings" feature that would only compile the Rust bindings but not the actual implementation, and would have to be linked to the shared library (no idea how to properly do that with cargo, need to switch the crate type with the feature) - Lots of FIXME comments for things that are ugly, missing API in the glib/gobject bindings, etc :) Things to come: - Some GObject interface - Action signal - Refcounted and copying boxed type Let me know if that is all useful for you, if you have any suggestions/comments, etc. Once it's all done, I was also going to blog about it. I think once the macro can generate all the boilerplate for these things, using GObject from Rust would be a good way of generating/exporting an expressive C API (that can do more things than plain C: inheritance, signals, properties, etc.) and automatically get bindings for arbitrary languages.
Attachment:
signature.asc
Description: This is a digitally signed message part