mirror of https://github.com/mpv-player/mpv
lua: expose mp_getcwd through mp.utils
This commit is contained in:
parent
8956878448
commit
a910b5c6df
|
@ -486,6 +486,10 @@ This built-in module provides generic helper functions for Lua, and have
|
|||
strictly speaking nothing to do with mpv or video/audio playback. They are
|
||||
provided for convenience. Most compensate for Lua's scarce standard library.
|
||||
|
||||
``utils.getcwd()``
|
||||
Returns the directory that mpv was launched from. On error, ``nil, error``
|
||||
is returned.
|
||||
|
||||
``utils.readdir(path [, filter])``
|
||||
Enumerate all entries at the given path on the filesystem, and return them
|
||||
as array. Each entry is a directory entry (without the path).
|
||||
|
|
14
player/lua.c
14
player/lua.c
|
@ -1005,6 +1005,19 @@ static int script_get_wakeup_pipe(lua_State *L)
|
|||
return 1;
|
||||
}
|
||||
|
||||
static int script_getcwd(lua_State *L)
|
||||
{
|
||||
char *cwd = mp_getcwd(NULL);
|
||||
if (!cwd) {
|
||||
lua_pushnil(L);
|
||||
lua_pushstring(L, "error");
|
||||
return 2;
|
||||
}
|
||||
lua_pushstring(L, cwd);
|
||||
talloc_free(cwd);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int script_readdir(lua_State *L)
|
||||
{
|
||||
// 0 1 2 3
|
||||
|
@ -1104,6 +1117,7 @@ static const struct fn_entry main_fns[] = {
|
|||
};
|
||||
|
||||
static const struct fn_entry utils_fns[] = {
|
||||
FN_ENTRY(getcwd),
|
||||
FN_ENTRY(readdir),
|
||||
FN_ENTRY(split_path),
|
||||
FN_ENTRY(join_path),
|
||||
|
|
Loading…
Reference in New Issue