5

I am a beginner in GNOME desktop application development so I am trying to learn about it as much as possible. I have read various tutorials present on developer.gnome.org written for JavaScript. I know that through GObject Introspection I can access C libraries in JavaScript.

As use of JavaScript for desktop applications is new so not many documentations are present. 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:

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?

For some of the libraries I have seen this documentation written for JavaScript. Any help will be appreciated to understand more about GNOME application development.

BuZZ-dEE
  • 6,075
  • 12
  • 66
  • 96
prolific
  • 765
  • 1
  • 6
  • 23
  • My first instinct is to say, if you know javascript, you almost know C, so just use C. For the next person who tries to help, here's a link to a hello world in JS just to show that javascript for gnome apps is possible: https://developer.gnome.org/gnome-devel-demos/3.7/helloWorld.js.html.en – Tom Cerul Mar 19 '14 at 15:27
  • 1
    @TomCerul yes i know C but i want to learn to create apps in javascript and wanted to know how can i use C libraries in javascript. How can i know about the function names and parameters which i can use? – prolific Mar 19 '14 at 15:39

2 Answers2

5

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.
I suggest you to take a look at this web site: http://www.roojs.org/seed/gir-1.2-gtk-3.0/seed/
And also to this one: http://zetcode.com/gui/javascriptgtktutorial/
Good luck with your javascript development !!!

Nicolas
  • 6,289
  • 4
  • 36
  • 51
0

There is new host for Gnome GJS documentation:

You still can get Javascript function mapped to the that C library function by searching though GIR files. Each library should have an XML file containing introspection information.

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>
user.dz
  • 962
  • 2
  • 19
  • 39