What is imported using the Gjs imports statement?
Asked Answered
T

2

14

If I'm looking at Gjs code and see this line near the beginning:

const Gio = imports.gi.Gio;

How can I know what methods, constants, events, etc. are on 'Gio' (without doing a Google search)? Is there a file somewhere on my installation that contains that information?

Obviously I'm asking for any 'imports' statement, not Gio specifically.

Tomi answered 22/9, 2013 at 18:39 Comment(0)
H
15

Some of imports statements import other javascript files:

  • imports.ui.* -> /usr/share/cinnamon/js/ui/*
  • imports.misc.* -> /usr/share/cinnamon/js/misc/*
  • imports.[cairo, dbus, format, gettext, jsUnit, lang, promise, signals] -> /usr/share/gjs-1.0/

For the imports.gi imports, Gnome Introspection is used to allow gjs to use C library.
So to get informations about those libraries I suggest you to look at the Gnome reference manuals:

But to conclude, there is a huge lack of documentation and examples. That makes difficult to develop with gjs.

UPDATE
Here other useful links:

Hirsh answered 23/9, 2013 at 11:6 Comment(5)
Thank you! And yes, I'm finding it incredibly difficult to develop with gjs. As for the links you provided, I found those but it's not always obvious what the "C" function names (and parameters) are vs what they are in gjs - which is why I'm now using the instructions in the blog I posted to get the actual gjs documentation.Tomi
You're right, the most difficult is to find the conversion from the C statement to the gjs one.Hirsh
For things under imports.gi, there is nowadays people.gnome.org/~gcampagna/docs that is quite ok for figuring out what is what. For general rules on how to map C documentation to equivalent Gjs there's wiki.gnome.org/Projects/Gjs/Mapping (useful for GObject Intrespection libraries not included in the gcampana docs).Incorrect
You can also add entries to the search path: imports.searchPath.push("/.../mymodule") Files (and folders) under /.../mymodule will be importable by imports.name_of_fileShock
Would you please give us the new link for this dead link : St => developer.gnome.org/st/stableCheslie
T
4

Since I got no answers I kept searching online and found this excellent blog post on how to generate HTML-formatted documentation from typelib files (such as Gio-2.0.typelib):

http://mathematicalcoffee.blogspot.com/2012/09/developing-gnome-shell-extensions_6.html

Tomi answered 23/9, 2013 at 0:53 Comment(1)
Not exactly an answer to this question, but linking to it anyway for the sheer quantity of hard-to-find information: GNOME shell: Javascript Source Documentation (extensions development) mathematicalcoffee.blogspot.com/2012/09/…Tomi

© 2022 - 2024 — McMap. All rights reserved.