首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >valac,vapi,internal,vapi,fast

valac,vapi,internal,vapi,fast
EN

Stack Overflow用户
提问于 2016-10-28 10:33:00
回答 1查看 132关注 0票数 2
代码语言:javascript
复制
// 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

代码语言:javascript
复制
// 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

代码语言:javascript
复制
// 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. -快-vapi

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

代码语言:javascript
复制
// 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:对于创建共享库,我应该使用--内部-vapi吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-10-28 11:03:10

您的类没有指定其可见性,因此默认情况下它具有“内部”可见性。

这意味着它只对您命名空间中的其他类可见。

如果将类指定为public,则--vapi开关将按预期输出vapi文件:

代码语言:javascript
复制
// 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; }
    }
}

调用:

代码语言:javascript
复制
valac --vapi=Point.vapi --library=point -X -shared Point.vala

结果:

代码语言:javascript
复制
/* 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是干什么用的。

至于您的第二个问题,您通常应该使用公共类来进行共享库。内部可见性与公共可见性的全部要点是,公共类型用于公众(命名空间之外),而内部类型仅用于内部实现详细信息。

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/40303245

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档