开发者

How Do I Make a PHP Module with the Vala Programming Language?

开发者 https://www.devze.com 2022-12-30 03:53 出处:网络
This new language called Vala, which is said to be C#-like and supposedly easier than C++ or C, compiles down into C on Linux with the GCC compiler.

This new language called Vala, which is said to be C#-like and supposedly easier than C++ or C, compiles down into C on Linux with the GCC compiler.

Sounds great. Now I want to use it to make a PHP extension module so that slow PHP code can be made in Vala and imported into PHP 开发者_运维技巧as a function.

How do I accomplish this in Vala? Is it even possible?


You need to use or write (if it doesn't exist) a VAPI file for the C library you need to use. It's quite easy, you just need to watch at the existing examples: http://live.gnome.org/Vala/Bindings or simply: http://git.gnome.org/browse/vala/tree/vapi


I don't know Vala, but if you can call native code, declare C structures and pass them as pointers to said native code, and define functions that use C calling conventions, it should be possible. But it will certainly be easier to do it in C/C++.

Edit: its homepage says

valac produces C source and header files from Vala source files as if you've written your library or application directly in C. Using a Vala library from a C application won't look different than using any other GObject-based library. There won't be a vala runtime library and applications can distribute the generated C code with their tarballs, so there are no additional run- or build-time dependencies for users.

So, although this is not definitive, I'd say you probably can.


I've created simple example of how to use Vala library from other languages:

https://github.com/antono/vala-object

Bindings for vala library generated automagically via GOobject Introspection.

https://live.gnome.org/GObjectIntrospection

Use gobject-for-php and get bindings for free!

https://github.com/indeyets/gobject-for-php

0

精彩评论

暂无评论...
验证码 换一张
取 消