So I'm working on a GTK3 module (finally). This will be a little different and use gobject introspection to call methods by name, dynamically, so I won't have to write code to interface with every single function. The module will use gobject introspection to look up the method by the object and the name, and if it exists, call it with the arguments. Anyway, I was thinking of using GTK2 module.pmod as an interface to the [] method, although that might not be the proper way to do this. So, basically I'll be creating a sort of blank program with only a couple methods, with a lot of behind the scenes infrastructure type code, and want to write so that when you call GTK3.Window("title"), it will call GTK3.method_missing (say), which will call my infrastructure code that will look up the class and method, create the program (if it doesn't exist already), add the method (if it doesn't exist already, if this is possible), and then call it with the arguments. Of course, if all that exists already, it would call it directly. Which brings up a question: is it possible to add a method to a class that has already started and ended (using start_new_program() and end_program()). And how could I write the frontend pike code to intercept GTK3.Window and have it call GTK3.method_missing. I was looking at the GTK2 module's module.pmod as a base, but not sure if that is the right way to do it... Thanks...
Yeah, that's what the gtk2 module does, I'm wondering if I can add functions to a class (in the c code) that has already been created and ended using end_program().
Sent from Yahoo Mail on Android
On Sat, May 26, 2018 at 11:14 AM, Stephen R. van den Bergsrb@cuci.nl wrote: Lance Dillon wrote:
Which brings up a question:?? is it possible to add a method to a class that has already started and ended (using start_new_program() and end_program()).
Overloading the `-> operator should work.
When I wrote an Objective-C bridge, I used introspection at class creation time: I overloaded ObjectiveC->`[]() so that when, for example, ObjectiveC.NSObject was accessed, a c-method performed introspection of the NSObject class and created a program dynamically using the C level module API: start_new_program() and friends. Methods were trampolines generated using libffi This provided relatively good runtime speed of method calls (as they were c methods that used libffi combined with the objective-c API) without the overhead of performing `[] and introspection on each method call. I also built a system of overlays that could provide custom mixing methods for situations where the generic binding wouldn’t suffice. Perhaps something like this could be used to provide optimal performance?
Bill
On May 26, 2018, at 11:34 AM, Lance Dillon riffraff169@yahoo.com wrote:
Yeah, that's what the gtk2 module does, I'm wondering if I can add functions to a class (in the c code) that has already been created and ended using end_program().
Sent from Yahoo Mail on Android https://go.onelink.me/107872968?pid=InProduct&c=Global_Internal_YGrowth_AndroidEmailSig__AndroidUsers&af_wl=ym&af_sub1=Internal&af_sub2=Global_YGrowth&af_sub3=EmailSignature On Sat, May 26, 2018 at 11:14 AM, Stephen R. van den Berg srb@cuci.nl wrote: Lance Dillon wrote:
Which brings up a question:?? is it possible to add a method to a class that has already started and ended (using start_new_program() and end_program()).
Overloading the `-> operator should work.
Stephen.
<Untitled.txt>
You know, I was looking at the PyGobject code, which basically does the same thing. It looks at the methods and properties and such and creates the object at that time. I'll look at that, that would probably be best. I'm hoping to get some demonstration code soon... The documentation for gobject introspection doesn't seem very good, more about making your own glib types and classes be able to be introspected, rather than how to use introspection in your own code for calling methods from existing classes. I did see something on how ruby created bindings for gtk, and how you can use it in your language, so I'll try to find that again, in addition to looking at the python source.... It will be a while before this gets to the point of pygobect, that code does a lot of stuff, including creating new gobject types dynamically based on python code. On Saturday, May 26, 2018, 2:19:22 PM EDT, H. William Welliver III william@welliver.org wrote:
When I wrote an Objective-C bridge, I used introspection at class creation time: I overloaded ObjectiveC->`[]() so that when, for example, ObjectiveC.NSObject was accessed, a c-method performed introspection of the NSObject class and created a program dynamically using the C level module API: start_new_program() and friends. Methods were trampolines generated using libffi This provided relatively good runtime speed of method calls (as they were c methods that used libffi combined with the objective-c API) without the overhead of performing `[] and introspection on each method call. I also built a system of overlays that could provide custom mixing methods for situations where the generic binding wouldn’t suffice. Perhaps something like this could be used to provide optimal performance? Bill
On May 26, 2018, at 11:34 AM, Lance Dillon riffraff169@yahoo.com wrote: Yeah, that's what the gtk2 module does, I'm wondering if I can add functions to a class (in the c code) that has already been created and ended using end_program().
Sent from Yahoo Mail on Android
On Sat, May 26, 2018 at 11:14 AM, Stephen R. van den Bergsrb@cuci.nl wrote: Lance Dillon wrote:
Which brings up a question:?? is it possible to add a method to a class that has already started and ended (using start_new_program() and end_program()).
Overloading the `-> operator should work.
Which brings up a question: is it possible to add a method to a class that has already started and ended (using start_new_program() and end_program()). And how could I write the frontend pike code to intercept GTK3.Window and have it call GTK3.method_missing. I was looking at the GTK2 module's module.pmod as a base, but not sure if that is the right way to do it... Thanks...
Adding symbols to a program after end_program() is not supported. If you know symbols att compile-time (but not their values), you can use getters that evaluate the the symbol at first access (and eg store the resulting value in a mapping).
program.c:f_dispatch_variant() may give some clues about how to implement such a function (ie how to look up the name of the current function).
If you don't know the symbols at compile-time, you'll have to resort to using the lfuns `[]() and `->().
You migth want to take a look at my marcus/gobject-introspection branch, which gives access to any package supplying GI, including GTK3. It doesn't include any Cairo integration though, since Cairo does not have GI...
Ah yes, I will check that out.... I was going to implement that myself, but since you have... What's the status of that branch? Would it be best ti implement the stuff you have in the GTK3 code, or use that branch, hoping it would be merged someday? Although it looks like it has been 4 years, so I'm not sure about that...
On Sunday, May 27, 2018, 3:54:13 PM EDT, Marcus Comstedt (ACROSS) (Hail Ilpalazzo!) @ Pike (-) developers forum 10353@lyskom.lysator.liu.se wrote:
You migth want to take a look at my marcus/gobject-introspection branch, which gives access to any package supplying GI, including GTK3. It doesn't include any Cairo integration though, since Cairo does not have GI...
The status is that the refcounting parts probably still need some work, but most things work, including, IIRC, inheriting a GI class from a Pike class and overriding the methods in it.
I've demoed it with instantiating a web browser widget in a GTK3 window, but due to the lack of Cairo no custom widgets are possible.
The branch is off early 8.0, but if there is new interrest in it I can probably bring it up to date for 8.1.
pike-devel@lists.lysator.liu.se