[Vala] Problem with array of struct



Hi,
I try to create a code like this :

using GLib;

namespace OptMain
{

public class Main : Object
{
    private int _test = 250;
    public int test {get {return _test;}}

    private OptionContext _opt_context;

    private OptionEntry[] enteries =
    {
        OptionEntry(){
                long_name = "test",
                short_name = 't',
                flags = 0,
                arg = OptionArg.INT,
                arg_data =  &_test,
                description = "Test arg",
                arg_description = "T"}
    };
    public bool ParseCmdLine(string[] args)
    {


/*        enteries += OptionEntry(){
                long_name = null,
                short_name = '\0',
                flags = 0,
                arg = 0,
                arg_data =  null,
                description = null,
                arg_description = null
        };*/
        _opt_context = new OptionContext("-test option parser");
        _opt_context.add_main_entries(enteries,null);
        try
        {
            _opt_context.parse(ref args);
        }
        catch(OptionError e)
        {
            stderr.printf(e.message);
            return false;
        }
        return true;
    }

    static int main (string[] args)
    {
        var app = new Main();
        if (!app.ParseCmdLine ( args))
            return 1;
        stdout.printf ("%d",app.test);
        return 0;
    }
}
}


First of all, I want to create an array of OptionEntry with a NULL in
the end of array. How I can do this? (The commented code is not an
option :) )
Secound problem is if I compile the exact code here, I get this :

$ valac ./valaopt.vala

** (valac:19428): CRITICAL **:
vala_ccode_member_access_construct_pointer: assertion `container !=
NULL' failed

** (valac:19428): CRITICAL **:
vala_ccode_member_access_construct_pointer: assertion `container !=
NULL' failed

** (valac:19428): CRITICAL **: vala_ccode_unary_expression_construct:
assertion `expr != NULL' failed

** (valac:19428): CRITICAL **: vala_ccode_function_add_assignment:
assertion `right != NULL' failed

And by running the output application :
$./valaopt --test 66
[1]    19491 segmentation fault (core dumped)  ./valaopt --test 66

But if I define "enteries" inside "ParseCmdLine" function every thing is OK,

This is my first try in vala. so I don't know If I do any thing wrong
or its the valac ??

--Sorry for my bad english.



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]