History

scripting: load scripts from directories

The intention is to provide a slightly nicer way to distribute scripts. For example, you could put multiple source files into the directory, and then import them from the actual script file (this is still unimplemented). At first I wanted to require a config file (because you need to know at least which scripting backend it should use). This wouldn't have been too hard (could have reused/abused the mpv config file parsing mechanism, and I already had working code that was just 2 function calls). But probably better to do this without new config files, because it might become a pain in the distant future. So this just probes for "main.lua", "main.js", etc., until an existing file is found. Another important change is that this skips all directory entries whose name starts with ".". This automatically excludes the "." and ".." special directories, and is probably useful to exclude random crap that might be lying around in the directory (such as editor temporary files, or OSX, in its usual hrmful, annoying, and idiotic modus operandi, sharting all over any directories opened by "Finder"). Although the changelog mentions the docs, they're added only in a later commit.

wm4 committed 6 years ago

Commit da38caf1 parent 66a979b7 files · +83 −52Browse files

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

Unified · Split

player/javascript.c+5−5
@@ -468,15 +468,15 @@ static int s_init_js(js_State *J, struct script_ctx *ctx) · 467 unmodified lines
468468 //
469469 // Note: init functions don't need autofree. They can use ctx as a talloc
470470 // context and free normally. If they throw - ctx is freed right afterwards.
471−static int s_load_javascript(struct mpv_handle *client, const char *fname)
471+static int s_load_javascript(struct mp_script_args *args)
472472 {
473473 struct script_ctx *ctx = talloc_ptrtype(NULL, ctx);
474474 *ctx = (struct script_ctx) {
475− .client = client,
476− .mpctx = mp_client_get_core(client),
477− .log = mp_client_get_log(client),
475+ .client = args->client,
476+ .mpctx = args->mpctx,
477+ .log = args->log,
478478 .last_error_str = talloc_strdup(ctx, "Cannot initialize JavaScript"),
479− .filename = fname,
479+ .filename = args->filename,
480480 };
481481
482482 int r = -1;

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