简体   繁体   English

如何使用C库在JavaScript中创建GNOME应用程序

[英]How to use C libraries to create GNOME app in JavaScript

I am a beginner in GNOME desktop application development so I am trying to learn about it as much as possible. 我是GNOME桌面应用程序开发的初学者,所以我试图尽可能多地了解它。 I have read various tutorials present on developer.gnome.org written for JavaScript. 我已经阅读了针对JavaScript编写的developer.gnome.org上的各种教程。 I know that through GObject Introspection I can access C libraries in JavaScript. 我知道通过GObject Introspection我可以在JavaScript中访问C库。

As use of JavaScript for desktop applications is new so not many documentations are present. 由于JavaScript用于桌面应用程序是新的,因此不存在很多文档。 I was wondering if there is any way I can know which functions I can use with what parameters to access some libraries. 我想知道是否有任何方法我可以知道哪些函数可以使用哪些参数来访问某些库。

For example I can create a button using GTK in JavaScript by: 例如,我可以在JavaScript中使用GTK创建一个按钮:

this.mybutton = new GTK.Button({some code here});

How can I come to know about the name of the functions I can use? 我怎样才能知道我可以使用的功能的名称? Is there any way I can make out the name of the function for JavaScript seeing the documentation written for C? 有没有什么办法可以看出JavaScript的函数名称,看看为C编写的文档?

For some of the libraries I have seen this documentation written for JavaScript. 对于一些库我见过这个为JavaScript编写的文档 Any help will be appreciated to understand more about GNOME application development. 感谢任何帮助以了解有关GNOME应用程序开发的更多信息。

I agree with you: the documentation is pretty low on the subject. 我同意你的观点:关于这个问题,文档很少。
Most of the time I try to find already written code from other developers and change it to have what I want. 大多数时候,我尝试从其他开发人员那里找到已编写的代码并将其更改为具有我想要的内容。
The C documentation is pretty complete on http://developer.gnome.org and most of the time you can use nearly the same methods. C文档在http://developer.gnome.org上非常完整,大多数时候你可以使用几乎相同的方法。
I suggest you to take a look at this web site: http://www.roojs.org/seed/gir-1.2-gtk-3.0/seed/ 我建议你看看这个网站: http//www.roojs.org/seed/gir-1.2-gtk-3.0/seed/
And also to this one: http://zetcode.com/gui/javascriptgtktutorial/ 还有这个:http: //zetcode.com/gui/javascriptgtktutorial/
Good luck with your javascript development !!! 祝你的javascript开发好运!

Yes, you can get Javascript function mapped to the that C library function by searching though GIR files. 是的,您可以通过搜索GIR文件将Javascript函数映射到该C库函数。 Each library should have an XML file containing introspection information. 每个库都应该有一个包含内省信息的XML文件。

Example from one question I asked before. 我之前问过的一个问题的例子。

grep -rn gdk_keymap_get_default /usr/share/gir-1.0/

/usr/share/gir-1.0/Gdk-2.0.gir:16781:                c:identifier="gdk_keymap_get_default"
/usr/share/gir-1.0/Gdk-3.0.gir:15776:      <function name="get_default" c:identifier="gdk_keymap_get_default">

vim /usr/share/gir-1.0/Gdk-3.0.gir +15776

    <class name="Keymap"
           c:symbol-prefix="keymap"
           c:type="GdkKeymap"
           parent="GObject.Object"
           glib:type-name="GdkKeymap"
           glib:get-type="gdk_keymap_get_type">
      <doc xml:space="preserve">A #GdkKeymap defines the translation from keyboard state
(including a hardware key, a modifier mask, and active keyboard group)
to a keyval. This translation has two phases. The first phase is
to determine the effective keyboard group and level for the keyboard
state; the second phase is to look up the keycode/group/level triplet
in the keymap and see what keyval it corresponds to.</doc>
      <function name="get_default" c:identifier="gdk_keymap_get_default">
        <doc xml:space="preserve">Returns the #GdkKeymap attached to the default display.</doc>
        <return-value transfer-ownership="none">
          <doc xml:space="preserve">the #GdkKeymap attached to the default display.</doc>
          <type name="Keymap" c:type="GdkKeymap*"/>
        </return-value>
      </function>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM