Tutorial Pages‎ > ‎

    Returning lists from within module source code

    The Gtk and Gdk library functions often return lists but how can those lists be passed over to the Tcl interpreter? The following code snippet shows how its done. This example is taken from the keyfile.c module.


        gint len;
        gchar **grouplist;
        gchar **group;
        Tcl_Obj *resList;

        grouplist =  g_key_file_get_groups ( keyFile, &len );
        group = grouplist;

        resList = Tcl_NewListObj ( 0, NULL );

        while ( *group != NULL )
        {
            Tcl_ListObjAppendElement ( interp, resList, Tcl_NewStringObj ( *group, -1 ) );
            group++;
        }

        g_strfreev ( grouplist );

        Tcl_SetObjResult ( interp, resList );




    Comments

    Sections