Re: Unified libraries to allow porting code to other oses

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

Let me try to explain what I mean:

if you begin with an action - set_text, for example, then the set_text function must examine the type of object to be set, and then call the correct function to do the setting. This could be done with a switch. Each action - set_text, get_text, set_color, etc. would have a (fairly long) list of switches.

Now, with any major set of GUI controls, there are going to be a huge number of possible actions - thousands - therefore, lots of code, and not all that easy to maintain. Whenever you need to add a new one - set_background, for example, you're going to have to write another long list of switches : case window then ... case button then ... etc. A case for each type of control that can change its background. Look at win32lib, for example. You will see a lot of "if ctrl_Type[ ID ] = ..." lines in each call. Lots of code, lots of opportunity for bugs.

On the other hand, there will be a smaller number of controls, and your call to set(control,"text",...) will already 'know' to look only at actions that are defined for that particular control. And you wouldn't need to use any switch statements to find the correct function, either. You can 'lookup' in that control's list of actions the one named "set_text" using fast built-in Eu functions like vlookup.

In most cases "set_text" would not be the name of the actual function call. It could be anything you choose that makes sense. For example, in EuGTK, "set_text" maps to "gtk_label_set_text" in libgtk3.so - for labels. It is also found as "gtk_entry_set_text" for GtkEntry widgets, and as "gtk_clipboard_set_text" for clipboards, where it needs an extra parameter. That causes no problem, since the looked-up info specifies the number and types of parameters the control is expecting. It could just as easily map to "SetWindowTextA" in user32.dll (or whatever) when using Windows, with a bit more work.

By doing things this way, each "set_text" takes exactly one line of code, for each control that actually can 'set text'. the line can be pretty simple, too:

widget[GtkLabel] = {"gtk_label",  
{GtkMisc,GtkWidget,GtkBuildable,GObject}, -- common properties inherited from lower-level controls 
    {"new",{S},P}, 
    {"set_text",{P,S}}, -- < this is all you'd need to add 
    {"get_text",{P},S}, 

For Windows, where the .dll routine names aren't so logically named, you'd probably have to make that line something like:

   {"set_text",{P,S},user32,"SetWindowTextA"} -- or something similar 
new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu