瓦拉VAPI文件文档 [英] Vala vapi files documentation

查看:175
本文介绍了瓦拉VAPI文件文档的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想破解使用瓦拉现有GLib的基于C语言的项目。

I'd like to hack on an existing GLib based C project using Vala.

我在做基本上是什么,我的构建过程的开始,利用华劣克从我.vala文件生成.c和.h文件,然后就编译生成的文件的方式我想任何.c和。 .h文件。

Basically what I'm doing is, at the beginning of my build process, using valac to generate .c and .h files from my .vala files and then just compiling the generated files the way I would any .c or .h file.

这可能不是最好的办法,但似乎大部分被好吗工作。

This is probably not the best way, but seems to be working alright for the most part.

我的问题是,我有一个很难从我的瓦拉code访问我现有的C code。有没有一种简单的方法来做到这一点?

My problem is that I'm having a hard time accessing my existing C code from my Vala code. Is there an easy way to do this?

我试着写我自己的.vapi文件(我没有与同VALA附带的工具,如果幸运的话),但我不能找到如何写这些的任何体面的文件。

I've tried writing my own .vapi files (I didn't have any luck with the tool that came with vala), but I can't find any decent documentation on how to write these.

是否有存在吗?我需要这些文件中的一个调用现有的C code?

Does any exist? Do I need one of these files to call existing C code?

推荐答案

是的,调用C函数,你需要为它编写的绑定。该方法是在<一个描述href=\"http://live.gnome.org/Vala/Tutorial#Binding_Libraries_with_VAPI_Files\">http://live.gnome.org/Vala/Tutorial#Binding_Libraries_with_VAPI_Files,然而,这并不直接适用于无图形对象编写的自定义功能或库。你可能需要从#vala IRC频道帮助,如果您有复杂的非图形对象库结合。

Yes, to call a C function, you need to write a binding for it. The process is described in http://live.gnome.org/Vala/Tutorial#Binding_Libraries_with_VAPI_Files, however, this doesn't apply directly to custom functions or libraries written without GObject. You'll probably need help from #vala IRC channel if you have complex binding for non-GObject libraries.

不过,大多数时候,我们用简单的VAPI文件绑定一些autoconf的定义或写在普通的C,为了效率的原因或破裂VALA,或任何其他原因,一些功能。这是大多数人做的方式:

However, most of the time, we use simple vapi files to bind some autoconf define or some functions written in plain C, for efficiency reason or broken vala, or whatever other reason. And this is the way that most people do:

myfunc.vapi

myfunc.vapi

[CCode (cheader_filename = "myfunc.h")]
namespace MyFunc {
    [CCode (cname = "my_func_foo")]
    public string foo (int bar, Object? o = null);
}

myfunc.h(以及相应的实施与项目挂钩一.C)

myfunc.h (and corresponding implementation in a .c linked with your project)

#include <glib-object.h>
char* my_func_foo(int bar, GObject* o)

example.vala可能是

example.vala could be

using MyFunc;

void main() {
    baz = foo(42);
}

在与华劣克编译,使用 - vapidir = 给myfunc.vapi的目录位置。根据您的构建系统,您可能需要通过额外的参数,以华劣克或GCC CFLAGS为了一切联系在一起。

When compiling with valac, use --vapidir= to give the directory location of the myfunc.vapi. Depending on your build system, you may need to pass extra argument to valac or gcc CFLAGS in order to link everything together.

这篇关于瓦拉VAPI文件文档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆