History

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.

Avi Halachmi (:avih) committed 6 years ago

Commit 756960b1 parent 68a1b474 files · +16 −1Browse files

Showing the changes to player/javascript.c (1 of 4 files). Show all

Unified · Split

player/javascript.c+7−0
@@ -59,6 +59,7 @@ static const char *const builtin_files[][3] = { · 58 unmodified lines
5959 // Represents a loaded script. Each has its own js state.
6060 struct script_ctx {
6161 const char *filename;
62+ const char *path; // NULL if single file
6263 struct mpv_handle *client;
6364 struct MPContext *mpctx;
6465 struct mp_log *log;
@@ -477,6 +478,7 @@ static int s_load_javascript(struct mp_script_args *args) · 412 unmodified lines
477478 .log = args->log,
478479 .last_error_str = talloc_strdup(ctx, "Cannot initialize JavaScript"),
479480 .filename = args->filename,
481+ .path = args->path,
480482 };
481483
482484 int r = -1;
@@ -1281,6 +1283,11 @@ static void add_functions(js_State *J, struct script_ctx *ctx) · 798 unmodified lines
12811283 js_pushstring(J, ctx->filename);
12821284 js_setproperty(J, -2, "script_file");
12831285
1286+ if (ctx->path) {
1287+ js_pushstring(J, ctx->path);
1288+ js_setproperty(J, -2, "script_path");
1289+ }
1290+
12841291 js_pop(J, 2); // leave the stack as we got it
12851292 }
12861293

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t