From da38caff9c0bec4745cef16b7904e26e51a4539b Mon Sep 17 00:00:00 2001 From: wm4 Date: Sat, 1 Feb 2020 18:09:40 +0100 Subject: 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. --- player/core.h | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'player/core.h') diff --git a/player/core.h b/player/core.h index acb57ddbe2..70fc33448e 100644 --- a/player/core.h +++ b/player/core.h @@ -619,10 +619,18 @@ void update_screensaver_state(struct MPContext *mpctx); void update_ab_loop_clip(struct MPContext *mpctx); // scripting.c +struct mp_script_args { + const struct mp_scripting *backend; + struct MPContext *mpctx; + struct mp_log *log; + struct mpv_handle *client; + const char *filename; + const char *path; +}; struct mp_scripting { const char *name; // e.g. "lua script" const char *file_ext; // e.g. "lua" - int (*load)(struct mpv_handle *client, const char *filename); + int (*load)(struct mp_script_args *args); }; bool mp_load_scripts(struct MPContext *mpctx); void mp_load_builtin_scripts(struct MPContext *mpctx); -- cgit v1.2.3