0

GObjectIntrospection 允许在任何高级语言中使用 C 对象。https://live.gnome.org/GObjectIntrospection

IBus 是 linux 的输入法框架。code.google.com/p/ibus

我在使用 GObjectIntrospection / javascript 时遇到了一些麻烦。我试图创建一个 ibus 引擎。相同的代码适用于 vala,python。但在 javascript 段错误中。我正在使用opensuse 12.1 gnome3。“ibus-devel”包提供了 GObjectIntrospection 所需的 /usr/share/gir-1.0/IBus-1.0.gir。

我正在尝试运行以下代码。

#!/usr/bin/env gjs
const IBus = imports.gi.IBus;
//get the ibus bus
var bus = new IBus.Bus();
if(bus.is_connected()){
  var factory = new IBus.Factory({
  connection: bus.get_connection()
  });
   factory.add_engine({
   engine_name:"ibus-sarim",
   engine_type:typeof(this)
   });
}

它在“new IBus.Factory”的第 6 行崩溃。

终端输出,

(gjs:13353): GLib-GIO-CRITICAL **: g_dbus_connection_register_object:
assertion `object_path != NULL && g_variant_is_object_path
(object_path)' failed
Segmentation fault

我无法弄清楚问题出在哪里。我在https://github.com/ibus/ibus/blob/master/bindings/vala/test/enchant.vala尝试了 ibus 提供的 vala 测试代码, 它编译并运行良好。在 enchant.vala 第 148 行,

var factory = new Factory(bus.get_connection());

创建工厂的代码与我在 javascript 中尝试的代码相同。也在python中,

from gi.repository import IBus
from gi.repository import GLib
from gi.repository import GObject
IBus.init()
bus = IBus.Bus()
if bus.is_connected():
    factory = IBus.Factory.new(bus.get_connection())

这似乎也可以正常工作,没有段错误。但是在javascript中它每次都失败。任何想法 ?我敲了几天没有任何用处:(

4

1 回答 1

0

In IBusFactory:

"connection"               IBusConnection*       : Read / Write / Construct Only

The documentation says "Construct Only". That's subject to interpretation for now, but it means to me that it is probably a private or protected class member. That said, the constructor is defined as:

IBusFactory *       ibus_factory_new                    (IBusConnection *connection);

There's that connection variable, in the constructor. Notice when you provide it exactly that way, your app works fine.

const IBus = imports.gi.IBus;
//get the ibus bus
var bus = new IBus.Bus();
if(bus.is_connected()){
    var factory = new IBus.Factory(bus.get_connection());
}

Now as for factory.add_engine(), the definition is here:

void                ibus_factory_add_engine             (IBusFactory *factory,
                                                         const gchar *engine_name,
                                                         GType engine_type);

That means you will have to provide the engine_name and engine_type as function parameters. This works:

factory.add_engine('ibus-engine-name', some-engine-type);

See http://ibus.googlecode.com/svn/docs/ibus/ch03.html for engine ideas. This code doesn't segfault, but it doesn't work either. It indicates the correct syntax up until add_engine()'s second parameter.

#!/usr/bin/env gjs
const IBus = imports.gi.IBus;
//get the ibus bus
var bus = new IBus.Bus();
if(bus.is_connected()){
    var factory = new IBus.Factory(bus.get_connection());
    factory.add_engine("ibus-sarim", typeof(this));
}
于 2012-01-15T04:49:45.670 回答