Re: Unified libraries to allow porting code to other oses

new topic     » goto parent     » topic index » view thread      » older message » newer message
jmduro said...

I think I understand. Something like set(object id, sequence property, object value). I don't understand how your "pretty simple" line works.

With my classes library, I would have to define a lot of classes, one per widget, defines all its methods and properties and create functions that instantiate that object like I did in my Database Visual Control Library. That is to say one source file per widget.

Regards

Jean-Marc

That's where computers come in handy - let it do the dirty work :)

The line is a 'prototype'. It defines the property and the parameters and parameter types needed to make the call.

When the first instance of an object (say a label) is created, that line is processed as follows:
1. the name "set_text" is converted to "gtk_label_set_text" - easy, since you already know you are dealing with gtk and a label.
2. "gtk_label_set_text" is looked up in the .dll or .so using define_c_proc() and the routine_id returned is appended to the line:
Now it looks like this:

{ 
  "set_text", 
  {50331649,150994948}, -- these are the P and S (just unique numbers, don't be concerned about them here) 
  0,   -- zero means no return value is expected 
  531, -- this is the routine to call, I refer to it as a 'vector' since it can be a call into a dll, or a call to a eu function. 
  0 -- this is used for other purposes, not important here. 
} 
 

To be exact, all the calls relating to a label are initialized in this way. Once, no matter how many labels you create, and only if your program is using labels. Otherwise, the entire GtkLabel structure remains untouched.

The P parameter just indicates that this particular call wants a pointer as the first parameter, and the S means it's expecting a string for the second. These are used in define_c_func(). They are also used later when you call set(somelabel,"text","FooBar") to assure that somelabel is a pointer to a label class, and that "FooBar" is a string. Since you can't pass strings directly to c functions, it also tells the set() call to convert that string into a pointer (via allocate_string).

A call which returns a result has a slightly different format:

   {"get_text",{P},S} -- wants a pointer to the label, and returns a pointer to a c string 

Since this has a return type indicated, the call was looked up using define_c_func(). Again, all these calls are 'initialized' the first time a label is declared. The S format of the return value tells get() to convert the string pointer from c back into a Eu string.

This may sound complex, but there are real benefits. One, you only need to lookup and 'register' functions for classes that are actually used in the current program. That saves a lot of startup time. Second, the prototype is dead simple to understand and convert from the documentation of the c call.

void 
gtk_label_set_markup (GtkLabel *label, 
                      const gchar *str); 

And it's never more than one line. Anybody can add features without knowing much at all about the underlying code. Say labels add a 'markup' property - like 'text', but using html. All that's needed is to add the line:

   {"set_markup",{P,S}} 

And you're done!

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu