1. Help with Phix structures

This C structure in GTK:

struct GtkTreeIter { 
  gint stamp; 
  gpointer user_data; 
  gpointer user_data2; 
  gpointer user_data3; 
}; 
The fields of which are filled in by a call to library function:
gboolean 
gtk_tree_model_get_iter_from_string (GtkTreeModel *tree_model, 
                                     GtkTreeIter *iter, 
                                     const gchar *path_string); 

I have no problem calling the library function, but how should I code the struct for Phix, and how to pass the structure to the library function?

Phix is really working well for interfacing to GTK. A few of the stickier problems will need a better understanding of structures.

Thanks!

new topic     » topic index » view message » categorize

2. Re: Help with Phix structures

I would try this first:

include cffi.e 
constant idGtkTreeIter = define_struct(""" 

typedef struct GtkTreeIter {  
  int stamp;  
  ptr user_data;  
  ptr user_data2;  
  ptr user_data3;  
};  
""") 

atom pGtkTreeIter = allocate_struct(idGtkTreeIter) 

(I suppose we could update cffi.e to recognise gint and gpointer once we're sure what they are on 32/64 bit win/lnx)

Oh, silly me, this should also work:

struct GtkTreeIter 
""" 

typedef struct GtkTreeIter {  
  int stamp;  
  ptr user_data;  
  ptr user_data2;  
  ptr user_data3;  
};  
""" 

end struct 
GtkTreeIter gti = new() 

PS the blank lines are courtesy of euforum, not me
PPS sorry, I omitted typedef, now fixed

new topic     » goto parent     » topic index » view message » categorize

3. Re: Help with Phix structures

-deleted-

Reply sent before I saw your update.

May work now.

new topic     » goto parent     » topic index » view message » categorize

4. Re: Help with Phix structures

struct GtkTreeIter  
"""  

typedef struct GtkTreeIter {   
  int stamp;   
  ptr user_data;   
  ptr user_data2;   
  ptr user_data3;   
};   
"""  

end struct  
 
procedure set_data(object data)  
GtkTreeIter gti = new() ? gti  --=> {"struct","GtkTreeIter",12,1101190672.0} 
end procedure 

Now, if I knew how to get the handle or pointer to the structure, I could pass that to the GTK function. (I assume that the gti structure has been allocated the necessary memory?)

new topic     » goto parent     » topic index » view message » categorize

5. Re: Help with Phix structures

irv said...

Now, if I knew how to get the handle or pointer to the structure, I could pass that to the GTK function. (I assume that the gti structure has been allocated the necessary memory?)

Oh yeah, it is fairly well hidden in the docs, you'll need a struct_mem(gti) for passing to c_func etc.
(Now you know what it's called, the doc index will take you to builtins\structs.e, but c-struct (Corelang/declarations/structs&classes/struct/c-struct) is better reading, as little as it is.)

new topic     » goto parent     » topic index » view message » categorize

6. Re: Help with Phix structures

Thanks. Will work on it tomorrow.

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu