Re: [Vala] Handling strings



From: Sascha Manns <Sascha Manns mailbox org>
Sent: Wednesday, 19 April 2017, 15:10
Subject: Re: [Vala] Handling strings

I tried it out:
    private string _filename;
    private string _path;
    private string entity_file_suffix = ".ent";
    private string entity_file_local = {get {_filename =
publication_title + entity_file_suffix; return _filename;}}

But got the same compiler error:
core/create_publication_core.vala:52.42-52.42: error: syntax error,
expected `}'
        private string entity_file_local = {get {_filename =
publication_title + entity_file_suffix; return _filename;}}

                                                ^

This compiles for me:

void main () {
     var a = new Test ();
  print (@"Path: $(a.path)\n");
}

class Test {
     private string ext = ".ext";
  private string text = "text";
  private string _backing_store_for_filename;
  private string filename {get {_backing_store_for_filename =
  text + ext; return _backing_store_for_filename;}}
  private string _path;
  public string path {get {_path = "/full/path/" + filename; return _path;}}
}

I'm not sure what you are trying to achieve in your object design here.
If publication_title is only set at construction time you can set these
fields in the constructor, but if publication_title can be changed throughout
the running of the program then I don't see a problem with a property that
calculates the path. The other option is to have a method that returns the
path name from the given fields.

I have tried compiling what you have uploaded to https://github.com/saigkill/gnome-publisher
Unfortunately I get an error:

git.mk: Generating .gitignore
make  all-recursive
make[1]: Entering directory '/srv/random-builds/gnome-publisher'
Making all in data
make[2]: Entering directory '/srv/random-builds/gnome-publisher/data'
GEN      org.gnome.Publisher.desktop
/usr/bin/msgfmt: error while opening "data/org.gnome.Publisher.appdata.xml.in.po" for reading: No such file 
or directory
Makefile:627: recipe for target 'org.gnome.Publisher.desktop' failed

It was pointed out on IRC that the callback in 
https://github.com/saigkill/gnome-publisher/blob/master/src/ui/build_publication.vala
should be functions, not properties. So:

[GtkCallback]
private void on_btnBuild_clicked {
/* tbf */
}


should be:

[GtkCallback]
private void on_btnBuild_clicked (Button button) {
/* tbf */
}

For example see:
https://blogs.gnome.org/tvb/2013/05/29/composite-templates-lands-in-vala/


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