On Tue, Jan 05, 2010 at 11:53:50AM +0330, golnaz nilieh wrote:

> Hello everybody!
> I'm a newbie to vala language, I faced to a strange problem recently and
> couldn't find any help in vala documentations.
> In my app, I have declared a class named "Global" in a file "global.vala":
> 
> using GLib;
> public class MyApp.Global : GLib.Object {
>     public static string dataDir = "/usr/local/share/";
> }
> 
> And I have a "main.vala" file, whith this code inside:
> 
> using GLib;
> using Gtk;
> public class MyApp.MainWindow : Window {
>    static int main (string[] args) {
>       stdout.printf ("all data is in: " + Global.dataDir);
>       return 0;
>    }
> }

Hi,

I'm really sorry, I can't help you.

But since I'm doing something similar in a software I'm writing, I'll take
the occasion and ask a little piece of advice on the list.

You are hard-coding dataDir into your application; assuming you're using
the GNU autotools, the data directory can be configured using the --prefix
option of configure. If that value is changed, the hard-coded dataDir will
not point to the right directory.

What I've done to work around the issue is to create a small utility class,
where I replace the value of prefix at build time:

        public class AutotoolsSupport : GLib.Object {
                public static const string DATA_DIR = "@prefix@/share/";
        }

The above snippet goes in autotoolssupport.vala.in, so that a suitable
autotoolssupport.vala is generated when AC_SUBS(prefix) is called in
configure.ac.

I would like to have a cleaner way to refer to @datadir@ from inside a Vala
source file. Any suggestion?

-- 
Andrea Bolognani <[email protected]>
Resistance is futile, you will be garbage collected.

Attachment: signature.asc
Description: Digital signature

_______________________________________________
Vala-list mailing list
[email protected]
http://mail.gnome.org/mailman/listinfo/vala-list

Reply via email to