[Vala] GLib command line parser and remaining args.



Hi,

I was playing with the Glib command line parser and something strange
occurred.

I'm joining the sample code.
-------
using GLib;

class Test : Object {
        [NoArrayLength ()]
        static string[] sources;
        static uint i = 0;

        const OptionEntry[] options = {
                { "", 0, 0, OptionArg.FILENAME_ARRAY, ref sources,
null, "FILE..." }, { null }
        };

        static int main (string[] args) {
                var opt_context = new OptionContext ("- Test");
                opt_context.set_help_enabled (true);
                opt_context.add_main_entries (options, null);
                opt_context.parse (ref args);

                stdout.printf("sources.length %u\n", sources.length);
                foreach (string source in sources)
                        stdout.printf("(1)- %s\n", source);

                while (sources[i] != null) {
                        stdout.printf("(2)- %s\n", sources[i]);
                        i++;
                }

                return 0;
        }
}
-------
When I run it with "./test blabla bla bla" nothing is displayed in the
foreach loop and sources.length value is always 0. In the second loop,
every words in the command line are displayed. 

The table length is 0 but it is not empty, confusing.

Is where something wrong in my code ? I've checked the internet
and vala sources for similar stuff and as far as I can see
everything seems ok. Or is it something wrong with vala ?

Thanks.



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