scripting: add wrapper to load scripts with user paths

Fixes regression since b2f756c80e, which broke load-script command
when used with user paths (ex: ~~/script.lua)
This commit is contained in:
Ricardo Constantino 2017-06-30 14:53:33 +01:00
parent ba8160cf59
commit c1f46dbbe9
No known key found for this signature in database
GPG Key ID: EFD16019AE4FF531
3 changed files with 12 additions and 6 deletions

View File

@ -5643,7 +5643,7 @@ int run_command(struct MPContext *mpctx, struct mp_cmd *cmd, struct mpv_node *re
case MP_CMD_LOAD_SCRIPT: {
char *script = cmd->args[0].v.s;
if (mp_load_script(mpctx, script) < 0)
if (mp_load_user_script(mpctx, script) < 0)
return -1;
break;
}

View File

@ -594,6 +594,7 @@ struct mp_scripting {
void mp_load_scripts(struct MPContext *mpctx);
void mp_load_builtin_scripts(struct MPContext *mpctx);
int mp_load_script(struct MPContext *mpctx, const char *fname);
int mp_load_user_script(struct MPContext *mpctx, const char *fname);
// sub.c
void reset_subtitle_state(struct MPContext *mpctx);

View File

@ -155,6 +155,14 @@ int mp_load_script(struct MPContext *mpctx, const char *fname)
return 0;
}
int mp_load_user_script(struct MPContext *mpctx, const char *fname)
{
char *path = mp_get_user_path(NULL, mpctx->global, fname);
int ret = mp_load_script(mpctx, path);
talloc_free(path);
return ret;
}
static int compare_filename(const void *pa, const void *pb)
{
char *a = (char *)pa;
@ -219,11 +227,8 @@ void mp_load_scripts(struct MPContext *mpctx)
// Load scripts from options
char **files = mpctx->opts->script_files;
for (int n = 0; files && files[n]; n++) {
if (files[n][0]) {
char *path = mp_get_user_path(NULL, mpctx->global, files[n]);
mp_load_script(mpctx, path);
talloc_free(path);
}
if (files[n][0])
mp_load_user_script(mpctx, files[n]);
}
if (!mpctx->opts->auto_load_scripts)
return;