2
// Point.vala
namespace Test {
    class Point {
        public const int MY_CONST = 123;
        public float x { get; set; }
        public float y { get; set; }
    }
}

vala ソース ファイル 'Point.vala' があります。

  1. --vapi

valac --vapi=Point.vapi --library=point -X -shared Point.vala:

// Point.vapi
namespace Test {
}

空の...

  1. --内部-vapi

valac --internal-vapi=Point.vapi --header=Point.h --internal-header=Point_internal.h --library=point -X -shared Point.vala:

// Point.vapi
namespace Test {
    [CCode (cheader_filename = "Point_internal.h")]
    internal class Point {
        public const int MY_CONST;
        public Point ();
        public float x { get; set; }
        public float y { get; set; }
    }
}

それは完璧に思え、私にとってはうまくいきます

  1. --fast-vapi

valac --fast-vapi=Point.vapi --library=point -X -shared Point.vala:

// Point.vapi
using GLib;
namespace Test {
    internal class Point {
        public const int MY_CONST = 123; // error
        public Point ();
        public float x { get; set; }
        public float y { get; set; }
    }
}

error: External constants cannot use valuesこのvapi を使用すると、エラーが発生します。

Q1 : 厳密な違いは何ですか? そして、なぜオプションがあるのですか。

Q2 : 共有ライブラリを作成するには --internal-vapi を使用する必要がありますか?

4

1 に答える 1

3

クラスはその可視性を指定していないため、デフォルトで「内部」可視性があります。

つまり、名前空間内の他のクラスにのみ表示されます。

クラスを public として指定すると、--vapiスイッチは期待どおりに vapi ファイルを出力します。

// Point.vala
namespace Test {
    // Make it public!
    public class Point {
        public const int MY_CONST = 123;
        public float x { get; set; }
        public float y { get; set; }
    }
}

呼び出し:

valac --vapi=Point.vapi --library=point -X -shared Point.vala

結果:

/* Point.vapi generated by valac.exe 0.34.0-dirty, do not modify. */

namespace Test {
        [CCode (cheader_filename = "Point.h")]
        public class Point {
                public const int MY_CONST;
                public Point ();
                public float x { get; set; }
                public float y { get; set; }
        }
}

その--vapiため、パブリック タイプのみが出力--internal-vapiされ、さらに内部タイプも出力されます。

何のためにあるのかわからない--fast-vapi

2 番目の質問については、通常、共有ライブラリにはパブリック クラスを使用する必要があります。内部とパブリックの可視性の全体的なポイントは、パブリック型はパブリック (名前空間の外部) による消費を目的としているのに対し、内部型は内部実装の詳細のみを目的としているということです。

于 2016-10-28T11:03:10.647 に答える