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
59// Represents a loaded script. Each has its own js state.59// Represents a loaded script. Each has its own js state.
60struct script_ctx {60struct script_ctx {
61 const char *filename;61 const char *filename;
62 const char *path; // NULL if single file
62 struct mpv_handle *client;63 struct mpv_handle *client;
63 struct MPContext *mpctx;64 struct MPContext *mpctx;
64 struct mp_log *log;65 struct mp_log *log;
@@ -477,6 +478,7 @@ static int s_load_javascript(struct mp_script_args *args) · 412 unmodified lines
477 .log = args->log,478 .log = args->log,
478 .last_error_str = talloc_strdup(ctx, "Cannot initialize JavaScript"),479 .last_error_str = talloc_strdup(ctx, "Cannot initialize JavaScript"),
479 .filename = args->filename,480 .filename = args->filename,
481 .path = args->path,
480 };482 };
481 483
482 int r = -1;484 int r = -1;
@@ -1281,6 +1283,11 @@ static void add_functions(js_State *J, struct script_ctx *ctx) · 798 unmodified lines
1281 js_pushstring(J, ctx->filename);1283 js_pushstring(J, ctx->filename);
1282 js_setproperty(J, -2, "script_file");1284 js_setproperty(J, -2, "script_file");
1283 1285
1286 if (ctx->path) {
1287 js_pushstring(J, ctx->path);
1288 js_setproperty(J, -2, "script_path");
1289 }
1290
1284 js_pop(J, 2); // leave the stack as we got it1291 js_pop(J, 2); // leave the stack as we got it
1285}1292}
1286 1293

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