[gjs: 1/2] Add more documents for "imports" and "imports.gi"
- From: Philip Chimento <pchimento src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gjs: 1/2] Add more documents for "imports" and "imports.gi"
- Date: Wed, 18 Nov 2020 20:38:57 +0000 (UTC)
commit 1c5c7fd9e720813eeb257db6eb92fff1c72f36f3
Author: wsgalaxy <wsgalaxy qq com>
Date: Wed Nov 18 15:17:19 2020 +0800
Add more documents for "imports" and "imports.gi"
doc/Modules.md | 42 +++++++++++++++++++++++++++++++++++++++++-
1 file changed, 41 insertions(+), 1 deletion(-)
---
diff --git a/doc/Modules.md b/doc/Modules.md
index 6c906070..e346566a 100644
--- a/doc/Modules.md
+++ b/doc/Modules.md
@@ -280,4 +280,44 @@ The System module offers a number of useful functions and properties for debuggi
Built-in version of the well-known [Tweener][tweener-www] animation/property transition library.
-[tweener-www]: http://hosted.zeh.com.br/tweener/docs/
\ No newline at end of file
+[tweener-www]: http://hosted.zeh.com.br/tweener/docs/
+
+## GObject Introspection
+
+**Import with `const gi = imports.gi;`**
+
+A wrapper of **libgirepository** to import native gobject-introspection libraries. This
+object has a property `versions` which is an object on which you can set string-valued
+properties indicating the version of that gobject-introspection library you want to load,
+and loading multiple versions in the same process is forbidden. So if you want to
+use gtk-3.0, set `imports.gi.versions.Gtk = '3.0';`.
+
+Any other properties of `imports.gi` will attempt to import a gobject-introspection library
+with the property name, picking the latest version if there is no entry for it in `imports.gi.versions`.
+
+## More about **imports**
+
+**imports** is a global object that you can use to import any js file or GObject
+Introspection lib as moudule, there are 4 special properties of **imports**:
+
+ * `searchPath`
+
+ An array of path that used to look for files, if you want to prepend a path
+ you can do something like `imports.searchPath.unshift(myPath)`.
+
+ * `__modulePath__`
+ * `__moduleName__`
+ * `__parentModule__`
+
+ These 3 properties is intended to be used internally, you should not use them.
+
+Any other properties of **imports** is treated as a module, if you access these
+properties, an import is attempted. Gjs try to look up a js file or directory by property name
+from each location in `imports.searchPath`. For `imports.foo`, if a file named
+`foo.js` is found, this file is executed and then imported as a module object; else if
+a directory `foo` is found, a new importer object is returned and its `searchPath` property
+is replaced by the path of `foo`.
+
+Note that any variable, function and class declared at the top level,
+except those declared by `let` or `const`, are exported as properties of the module object,
+and one js file is executed only once at most even if it is imported multiple times.
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]