summaryrefslogtreecommitdiffstats
path: root/DOCS/man
diff options
context:
space:
mode:
authorAvi Halachmi (:avih) <avihpit@yahoo.com>2019-12-14 19:34:58 +0200
committerAvi Halachmi (:avih) <avihpit@yahoo.com>2019-12-19 16:23:19 +0200
commit4fc5cd32d022fbc898052bbc5beda2e618137aa4 (patch)
tree4366bb127f796d158dfd66e9939f0c33fc219d16 /DOCS/man
parent3d2e30d764cdf5f89ce743b6f2f8c2f3f659b2ff (diff)
downloadmpv-4fc5cd32d022fbc898052bbc5beda2e618137aa4.tar.bz2
mpv-4fc5cd32d022fbc898052bbc5beda2e618137aa4.tar.xz
js: require: allow custom module search paths via mp.module_paths
Diffstat (limited to 'DOCS/man')
-rw-r--r--DOCS/man/javascript.rst8
1 files changed, 8 insertions, 0 deletions
diff --git a/DOCS/man/javascript.rst b/DOCS/man/javascript.rst
index 0c29affcdf..c0c4dbad8c 100644
--- a/DOCS/man/javascript.rst
+++ b/DOCS/man/javascript.rst
@@ -240,6 +240,9 @@ Note: ``read_file`` and ``write_file`` throw on errors, allow text content only.
anything from the filesystem), and returns it as a function. Very similar
to a ``Function`` constructor, but shows at stack traces as ``fname``.
+``mp.module_paths``
+ Global modules search paths array for the ``require`` function (see below).
+
Timers (global)
---------------
@@ -301,6 +304,11 @@ or ``~/x``. Otherwise, it's considered a global module id and searched at
``require("x")`` is searched as file ``x.js`` at those dirs, and id ``foo/x`` is
searched as file ``x.js`` inside dir ``foo`` at those dirs.
+Search paths for global module id's are at the array ``mp.module_paths``, which
+is searched in order. Initially it contains one item: ``~~/scripts/modules.js``
+such that it behaves as described above. Modifying it will affect future
+``require`` calls with global module id's which are not already loaded/cached.
+
No ``global`` variable, but a module's ``this`` at its top lexical scope is the
global object - also in strict mode. If you have a module which needs ``global``
as the global object, you could do ``this.global = this;`` before ``require``.