// 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”
valac --vapi=Point.vapi --library=point -X -shared Point.vala
// Point.vapi
namespace Test {
}空的..。
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; }
}
}它看起来很完美,而且适合我。
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:对于创建共享库,我应该使用--内部-vapi吗?
发布于 2016-10-28 11:03:10
您的类没有指定其可见性,因此默认情况下它具有“内部”可见性。
这意味着它只对您命名空间中的其他类可见。
如果将类指定为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是干什么用的。
至于您的第二个问题,您通常应该使用公共类来进行共享库。内部可见性与公共可见性的全部要点是,公共类型用于公众(命名空间之外),而内部类型仅用于内部实现详细信息。
https://stackoverflow.com/questions/40303245
复制相似问题