Skip to content

Commit

Permalink
autoload.lua: promote to a builtin script
Browse files Browse the repository at this point in the history
Of all the scripts located in the TOOLS directory, autoload is miles
away the most popular one. It gets the most contributions by far, and
the feature is clearly fairly popular among users. Instead of forcing
them to manually copy the script into their script folders, make it a
builtin instead. Unlike the other lua scripts, this is disabled by
default given that it's a big behavioral change that is not universally
desirable but users can enable it with a simple line in their configs.
  • Loading branch information
Dudemanguy committed Jul 14, 2024
1 parent 202ecc1 commit 5c6caa2
Show file tree
Hide file tree
Showing 8 changed files with 13 additions and 2 deletions.
5 changes: 5 additions & 0 deletions DOCS/man/options.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1027,6 +1027,11 @@ Program Behavior
Enable the builtin script that lets you select from lists of items (default:
yes). By default, its keybindings start with the ``g`` key.

``--load-autoload=<yes|no>``
Enable the builtin script that scans the directory a file is located in and
adds the found files to the playlist before and after the currently playing
file (default: no).

``--player-operation-mode=<cplayer|pseudo-gui>``
For enabling "pseudo GUI mode", which means that the defaults for some
options are changed. This option should not normally be used directly, but
Expand Down
1 change: 1 addition & 0 deletions options/options.c
Original file line number Diff line number Diff line change
Expand Up @@ -558,6 +558,7 @@ static const m_option_t mp_opts[] = {
OPT_CHOICE(lua_load_auto_profiles, {"no", 0}, {"yes", 1}, {"auto", -1}),
.flags = UPDATE_BUILTIN_SCRIPTS},
{"load-select", OPT_BOOL(lua_load_select), .flags = UPDATE_BUILTIN_SCRIPTS},
{"load-autoload", OPT_BOOL(lua_load_autoload), .flags = UPDATE_BUILTIN_SCRIPTS},
#endif

// ------------------------- stream options --------------------
Expand Down
1 change: 1 addition & 0 deletions options/options.h
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ typedef struct MPOpts {
bool lua_load_console;
int lua_load_auto_profiles;
bool lua_load_select;
bool lua_load_autoload;

bool auto_load_scripts;

Expand Down
2 changes: 1 addition & 1 deletion player/core.h
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ typedef struct MPContext {

struct mp_ipc_ctx *ipc_ctx;

int64_t builtin_script_ids[6];
int64_t builtin_script_ids[7];

mp_mutex abort_lock;

Expand Down
3 changes: 3 additions & 0 deletions player/lua.c
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ static const char * const builtin_lua_scripts[][2] = {
},
{"@select.lua",
# include "player/lua/select.lua.inc"
},
{"@autoload.lua",
# include "player/lua/autoload.lua.inc"
},
{0}
};
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion player/lua/meson.build
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
lua_files = ['defaults.lua', 'assdraw.lua', 'options.lua', 'osc.lua',
'ytdl_hook.lua', 'stats.lua', 'console.lua', 'auto_profiles.lua',
'input.lua', 'fzy.lua', 'select.lua']
'input.lua', 'fzy.lua', 'select.lua', 'autoload.lua']
foreach file: lua_files
lua_file = custom_target(file,
input: join_paths(source_root, 'player', 'lua', file),
Expand Down
1 change: 1 addition & 0 deletions player/scripting.c
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,7 @@ void mp_load_builtin_scripts(struct MPContext *mpctx)
load_builtin_script(mpctx, 4, mpctx->opts->lua_load_auto_profiles,
"@auto_profiles.lua");
load_builtin_script(mpctx, 5, mpctx->opts->lua_load_select, "@select.lua");
load_builtin_script(mpctx, 6, mpctx->opts->lua_load_autoload, "@autoload.lua");
}

bool mp_load_scripts(struct MPContext *mpctx)
Expand Down

0 comments on commit 5c6caa2

Please sign in to comment.