Re: php source q's >> closer ..
| From: | Simon | Date: | Tue, 26 Jul 2005 15:37:53 +0000 |
| Subject: | Re: php source q's >> closer .. | ||
| References: | 1 2 3 | Groups: | php.gtk.dev |
| Request: | Send a blank email to php-gtk-dev+get-1471@lists.php.net to get a copy of this message | ||
OK , cheers !! , I can now get the passed array data into the gchar and it displays as expected...
but I can't for some reason get the array count .. I thought that zend_hash_num_elements would do it but no go
unsigned int y;
y = zend_hash_num_elements(Z_ARRVAL_P(php_list));
//OR y = zend_hash_num_elements(Z_ARRVAL_P(php_list));
list = g_new( gchar *, y ) ; //segfaults
with a hard coded int it works fine ( but limits the array to $x )
this is probably a simple 'c' problem but I just ain't getting it ;)
I also seem to have to append a NULL to the gchar but I don't see that in the python bindings?
hard coded (list = g_new( gchar *, 4 ); ) actually works with any amount of array arguments but then g_free() complains
/******************************************************************/
static PHP_METHOD(GtkAboutDialog, set_documenters)
{
int i=0;
zval *php_list, **item;
gchar **list;
NOT_STATIC_METHOD();
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a/", &php_list) == FAILURE ) {
return;
}
list = g_new( gchar *, 4 ) ; //WORKS WITH HARD CODED INT//
zend_hash_internal_pointer_reset(Z_ARRVAL_P(php_list));
while (zend_hash_get_current_data(Z_ARRVAL_P(php_list), (void **)&item) == SUCCESS) {
convert_to_string_ex( item ) ;
list[i] = Z_STRVAL_PP( item ) ;
i++;
zend_hash_move_forward(Z_ARRVAL_P(php_list)) ;
}
list[i]=NULL;
gtk_about_dialog_set_documenters( GTK_ABOUT_DIALOG(PHPG_GOBJECT(this_ptr)), list ) ;
g_free(list);
}
Andrei Zmievski wrote:
You have to accept a parameter of type "a" in php_gtk_parse_args() and then iterate through it and add elements to gchar** array. Something like: override gtk_combo_set_popdown_strings PHP_FUNCTION(gtk_combo_set_popdown_strings) {zval *php_list, **item; GList *list = NULL;#ifdef PHP_WIN32gchar *utf8_text = NULL;#endifNOT_STATIC_METHOD();if (!php_gtk_parse_args(ZEND_NUM_ARGS(), "a/", &php_list)) return;zend_hash_internal_pointer_reset(Z_ARRVAL_P(php_list)); while (zend_hash_get_current_data(Z_ARRVAL_P(php_list), (void **)&item) == SUCCESS) { convert_to_string_ex(item);#ifdef PHP_WIN32utf8_text = g_convert(Z_STRVAL_PP(item), Z_STRLEN_PP(item), "UTF-8", GTK_G(codepage), NULL, NULL, NULL); list = g_list_append(list, utf8_text);#elselist = g_list_append(list, Z_STRVAL_PP(item));#endifzend_hash_move_forward(Z_ARRVAL_P(php_list)); }gtk_combo_set_popdown_strings(GTK_COMBO(PHP_GTK_GET(this_ptr)), list); g_list_free(list); RETURN_TRUE;} But this code is from PHP-GTK 1 so it might need to be adjusted. -Andrei On Jul 24, 2005, at 4:39 AM, Simon wrote:how to grab an array passed as an argument ,& convert it to the correct type ? Yes I did look at the php documentation but totally confused .. there are a few Dialog functions that could be cleaned up if only I had a clue what I was doing ;) ... e.g. I want to learn /*********************************************************/ static PHP_METHOD(GtkAboutDialog, set_documenters) {gchar *doccers[] = { "Andrei", "Steph", "Christian", "Scott...etc", NULL }; zend_bool free_doccers;gtk_about_dialog_set_documenters(GTK_ABOUT_DIALOG(PHPG_GOBJECT(this_ptr )), doccers);if (free_doccers) g_free(doccers);} /*****************************************************/ The above works in as much that the doccers array is successfully passed to the dialog (and the credits button appears) , I think I have ints worked out ~ but what is the process for grabbing an array argument & then converting to the expected type ?gchar**? Regards, Simon. -- PHP-GTK Development Mailing List (http://gtk.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php