Thanks about the solution.
I thought about this solution earlier as fail safe, but it just didn't seen 
right to
force the user to use my way all along main(and not natural).
However, I've ended up using another way to make this easy in Vala:
namespace Max {
    [CCode (has_target="false")]
    public delegate bool ArgsBoolFunc ([CCode (array_length_pos = 0.9)] ref 
unowned string[] args);
    private delegate bool ArgsBoolFuncC (int* argsc, char*** argsv);
    public bool pass_args_bool (ArgsBoolFunc func) {
        ArgsBoolFuncC func_c = (ArgsBoolFuncC)func;
        return func_c (argsc, argsv); 
    }
}

I've also copy the code for the void and int types.
This hide complexity from the user which I see as the best solution so far.

I've just hoped that there could be some pointer to "ref" conversion in Vala,
like:
void* pointer
func ((ref)pointer)

Thanks again,
Tal

> Subject: Re: [Vala] Seg fault when trying to pass args to gtk_init_check.
> From: [email protected]
> To: [email protected]
> CC: [email protected]
> Date: Wed, 18 Jul 2012 16:38:08 +0200
> 
> Hi Tal,
> 
> On Mon, 2012-07-16 at 20:27 +0300, Tal Hadad wrote:
> > Ok I've explained my self wrong.
> > The reason I use a pointer to string[] instead of just storing it, is that 
> > I want
> > the plugins init calls, Gtk.init_check for example, is that I want Gtk to
> > remove arguments which Gtk familiar with.
> > Then, when other init () invoked, they remove the familiar args.
> > In the end, the user returns to the main, and if unrecognized arguments
> > had left, the main shows error "Unrecognized argument".
> > 
> > Now this all thing can be done only if I use a pointer which points it to 
> > the
> > args variable in the main function:
> > main (string[] args)
> 
> I'd replace the function Max.get_args() with a variable:
> 
> namespace Max {
>       unowned string[] args;
> }
> 
> int main (string[] args) {
>       Max.args = args;
>       ... initialize plugins
>       ... use Max.args instead of args
> }
> 
> public void peas_register_types (ObjectModule module) {
>       if (!Gtk.init_check (ref Max.args)) {
>               stderr.printf ("Error: Failed to initialize Gtk.\n");
>               return;
>       }
>       stdout.printf ("Pass first\n");
> }
> 
> Regards,
> Jürg
> 
                                          
_______________________________________________
vala-list mailing list
[email protected]
https://mail.gnome.org/mailman/listinfo/vala-list

Reply via email to