Unified libraries to allow porting code to other oses

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

Porting source code to other OSes can be very painfull. With one library, a unique call to a function with multiple parameters does the job, and on another you have to call multiple atomic functions to get the same result.

GUIs like wxWidgets have several function names to change a value according to classes where win32lib uses the same function name. Porting can be a hunter game where you need to spend weeks reading the documentation for each GUI you are testing.

I think OpenEuphoria can leverage some differences, not all of course, so I began writing a set of unified libraries that share common specifications: same function names, same parameters if possible or close parameters if not, limited set of functions. Thank's to Irv for giving me the key to be able to do this.

The aim is to ease the step of porting Euphoria code from windows to multiplatform to linux and reverse. It is based on the following principle:

           \ OS        Windows        Multiplatform       Linux  
Skill level \       
             \  
  
Beginner               winSimple  <-->  wxSimple    <-->  linSimple  
                          ^                ^                 ^  
                          |                |                 |  
                          v                v                 v  
Advanced user          win32lib        wxEuphoria          euGtk  
                        arwen                              euQt  
                        tinEwg  
                        ...  

winSimple would be as simple as:

ifdef WIN32LIB then  
  include winlibSimple.e  
elsifdef ARWEN then  
  include arwenSimple.e  
elsifdef TIN_EWG then  
  include tinEwgSimple.e  
end ifdef  

So everyone who wants to port his code to another OS can do it at his skill level. As an example, if I know only win32lib, I will be able to port my program to use winlibSimple instead of win32lib. Then, porting most of the code to use wxSimple should be obvious because most of the job is done only by changing one line "include winSimple.e" by "include wxSimple.e" and defining a variable named WX_WIDGETS instead of WIN32LIB.

There should be few lines than could not be ported from win32lib to winlibSimple, so not ported to wxSimple, because they are Windows specific. For those, you will get help on the forum. With only a very basic knowledge of Linux you could run your first Linux program. Then at your speed, you could learn wxEuphoria to do more while being compatible with Windows or swap to pure Linux by using linSimple, and later EuGTK or EUQT if you want.

The first library I build is wxSimple. Here is the first version to show it's not just a dream:

include std/search.e 
public include wxeud.e 
 
public enum  --     wxGridSelectionModes 
  wxGridSelectCells, 
  wxGridSelectRows, 
  wxGridSelectColumns, 
  wxGridSelectRowsOrColumns, 
$ 
 
export object registry = {} 
 
public function wxCreate( integer class, object params ) 
  atom id = create( class, params ) 
  registry = append(registry, {id, class}) 
  return id 
end function 
 
public function getClass(integer id) 
  return vlookup(id, registry, 1, 2, -1) 
end function 
 
public procedure setText(object id, sequence text) 
  integer wxId, param 
  if sequence(id) then 
    wxId = id[1] 
    param = id[2] 
  else 
    wxId = id 
  end if 
  atom wxClass = getClass(wxId) 
  if find(wxClass, {wxListCtrl, wxListBox, wxChoice}) then 
    set_string( wxId, param-1, text ) 
  elsif find(wxClass, {wxFrame, wxButton, wxStaticText, wxComboBox, wxRadioBox}) then 
    set_label ( wxId,  text ) 
  elsif (wxClass = wxStatusBar) then 
    if sequence(id) then 
      set_status_text( wxId, text, param-1) 
    else 
      set_status_text( wxId, text, 0 ) 
    end if 
  elsif (wxClass = wxTextCtrl) then 
    set_text( wxId, text ) 
  end if 
end procedure 

Create your widgets with wxCreate instead of create, and you will be able to use the same function to set widgets text instead of many. These lines:

  set_label(frame, "Clicked") 
  set_label(button, "Clicked") 
  set_label(lbl, "Clicked") 
  set_label(radiobox, "Clicked") 
  set_label(combo, "Clicked") 
 
  set_status_text(sb, "Clicked", 0) 
 
  set_text(sle, "Clicked") 
 
  set_string(list, 0, "Clicked") 
 
  set_string(choice, 0, "Clicked") 
  set_choice(choice, "Clicked") 
 
  set_cell_value(grid, "Clicked", 0, 1) 

can be replaced by those lines:

  setText(frame, "Clicked") 
  setText(button, "Clicked") 
  setText(lbl, "Clicked") 
  setText(radiobox, "Clicked") 
  setText(combo, "Clicked") 
 
  setText({sb,1}, "Clicked") 
 
  setText(sle, "Clicked") 
 
  setText({list,1}, "Clicked") 
  setText({choice,1}, "Clicked") 
  set_choice(choice, "Clicked") 
 
  set_cell_value(grid, "Clicked", 0, 1) 

You still have access to wxEuphoria standard functions. Simple functions are designed for people who migrate from one OS to another, from one GUI to another, with few knowledge of the intended target. Advanced users can use standard functions.

Regards

Jean-Marc

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

Search



Quick Links

User menu

Not signed in.

Misc Menu