diff options
author | Avi Halachmi (:avih) <avihpit@yahoo.com> | 2020-02-07 17:35:48 +0200 |
---|---|---|
committer | Avi Halachmi (:avih) <avihpit@yahoo.com> | 2020-02-07 18:22:12 +0200 |
commit | 756960bf3cd6110c85b97f3edbd3bf0e2a2b91d4 (patch) | |
tree | 004dd368108cf52d8d73964f91a8ae7d86100437 /player/javascript.c | |
parent | 68a1b47d4d4a7d59d4f43850902d4194eb7c0552 (diff) | |
download | mpv-756960bf3cd6110c85b97f3edbd3bf0e2a2b91d4.tar.bz2 mpv-756960bf3cd6110c85b97f3edbd3bf0e2a2b91d4.tar.xz |
js: require: directory-scripts: first look at <dir>/modules/
Also, add the function mp.get_script_directory() to let scripts know if
they're loaded as a directory and where.
Diffstat (limited to 'player/javascript.c')
-rw-r--r-- | player/javascript.c | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/player/javascript.c b/player/javascript.c index 6047add255..f3d810e29c 100644 --- a/player/javascript.c +++ b/player/javascript.c @@ -59,6 +59,7 @@ static const char *const builtin_files[][3] = { // Represents a loaded script. Each has its own js state. struct script_ctx { const char *filename; + const char *path; // NULL if single file struct mpv_handle *client; struct MPContext *mpctx; struct mp_log *log; @@ -477,6 +478,7 @@ static int s_load_javascript(struct mp_script_args *args) .log = args->log, .last_error_str = talloc_strdup(ctx, "Cannot initialize JavaScript"), .filename = args->filename, + .path = args->path, }; int r = -1; @@ -1281,6 +1283,11 @@ static void add_functions(js_State *J, struct script_ctx *ctx) js_pushstring(J, ctx->filename); js_setproperty(J, -2, "script_file"); + if (ctx->path) { + js_pushstring(J, ctx->path); + js_setproperty(J, -2, "script_path"); + } + js_pop(J, 2); // leave the stack as we got it } |